]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.9-201302171808.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.9-201302171808.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 5634228..b54a897 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398 - signing_key.x509.signer
399 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403 @@ -1053,6 +1113,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1213,6 +1274,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1349,17 +1412,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1369,11 +1436,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..47bed62 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590 - unsigned long limit)
591 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592 + unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595 -
596 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601 - if (!vma || addr + len <= vma->vm_start)
602 + if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610 +#ifdef CONFIG_PAX_RANDMMAP
611 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612 +#endif
613 +
614 if (addr) {
615 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623 - len, limit);
624 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625 +
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636 index 0c4132d..88f0d53 100644
637 --- a/arch/alpha/mm/fault.c
638 +++ b/arch/alpha/mm/fault.c
639 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643 +#ifdef CONFIG_PAX_PAGEEXEC
644 +/*
645 + * PaX: decide what to do with offenders (regs->pc = fault address)
646 + *
647 + * returns 1 when task should be killed
648 + * 2 when patched PLT trampoline was detected
649 + * 3 when unpatched PLT trampoline was detected
650 + */
651 +static int pax_handle_fetch_fault(struct pt_regs *regs)
652 +{
653 +
654 +#ifdef CONFIG_PAX_EMUPLT
655 + int err;
656 +
657 + do { /* PaX: patched PLT emulation #1 */
658 + unsigned int ldah, ldq, jmp;
659 +
660 + err = get_user(ldah, (unsigned int *)regs->pc);
661 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663 +
664 + if (err)
665 + break;
666 +
667 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669 + jmp == 0x6BFB0000U)
670 + {
671 + unsigned long r27, addr;
672 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674 +
675 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676 + err = get_user(r27, (unsigned long *)addr);
677 + if (err)
678 + break;
679 +
680 + regs->r27 = r27;
681 + regs->pc = r27;
682 + return 2;
683 + }
684 + } while (0);
685 +
686 + do { /* PaX: patched PLT emulation #2 */
687 + unsigned int ldah, lda, br;
688 +
689 + err = get_user(ldah, (unsigned int *)regs->pc);
690 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
691 + err |= get_user(br, (unsigned int *)(regs->pc+8));
692 +
693 + if (err)
694 + break;
695 +
696 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
698 + (br & 0xFFE00000U) == 0xC3E00000U)
699 + {
700 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703 +
704 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706 + return 2;
707 + }
708 + } while (0);
709 +
710 + do { /* PaX: unpatched PLT emulation */
711 + unsigned int br;
712 +
713 + err = get_user(br, (unsigned int *)regs->pc);
714 +
715 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716 + unsigned int br2, ldq, nop, jmp;
717 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718 +
719 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720 + err = get_user(br2, (unsigned int *)addr);
721 + err |= get_user(ldq, (unsigned int *)(addr+4));
722 + err |= get_user(nop, (unsigned int *)(addr+8));
723 + err |= get_user(jmp, (unsigned int *)(addr+12));
724 + err |= get_user(resolver, (unsigned long *)(addr+16));
725 +
726 + if (err)
727 + break;
728 +
729 + if (br2 == 0xC3600000U &&
730 + ldq == 0xA77B000CU &&
731 + nop == 0x47FF041FU &&
732 + jmp == 0x6B7B0000U)
733 + {
734 + regs->r28 = regs->pc+4;
735 + regs->r27 = addr+16;
736 + regs->pc = resolver;
737 + return 3;
738 + }
739 + }
740 + } while (0);
741 +#endif
742 +
743 + return 1;
744 +}
745 +
746 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747 +{
748 + unsigned long i;
749 +
750 + printk(KERN_ERR "PAX: bytes at PC: ");
751 + for (i = 0; i < 5; i++) {
752 + unsigned int c;
753 + if (get_user(c, (unsigned int *)pc+i))
754 + printk(KERN_CONT "???????? ");
755 + else
756 + printk(KERN_CONT "%08x ", c);
757 + }
758 + printk("\n");
759 +}
760 +#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764 @@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768 - if (!(vma->vm_flags & VM_EXEC))
769 + if (!(vma->vm_flags & VM_EXEC)) {
770 +
771 +#ifdef CONFIG_PAX_PAGEEXEC
772 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773 + goto bad_area;
774 +
775 + up_read(&mm->mmap_sem);
776 + switch (pax_handle_fetch_fault(regs)) {
777 +
778 +#ifdef CONFIG_PAX_EMUPLT
779 + case 2:
780 + case 3:
781 + return;
782 +#endif
783 +
784 + }
785 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786 + do_group_exit(SIGKILL);
787 +#else
788 goto bad_area;
789 +#endif
790 +
791 + }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796 index c79f61f..9ac0642 100644
797 --- a/arch/arm/include/asm/atomic.h
798 +++ b/arch/arm/include/asm/atomic.h
799 @@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803 +#ifdef CONFIG_GENERIC_ATOMIC64
804 +#include <asm-generic/atomic64.h>
805 +#endif
806 +
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811 +#define _ASM_EXTABLE(from, to) \
812 +" .pushsection __ex_table,\"a\"\n"\
813 +" .align 3\n" \
814 +" .long " #from ", " #to"\n" \
815 +" .popsection"
816 +
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824 +{
825 + return v->counter;
826 +}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829 +{
830 + v->counter = i;
831 +}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839 +"1: ldrex %1, [%3]\n"
840 +" adds %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +"2: bkpt 0xf103\n"
845 +"3:\n"
846 +#endif
847 +
848 +" strex %1, %0, [%3]\n"
849 +" teq %1, #0\n"
850 +" bne 1b"
851 +
852 +#ifdef CONFIG_PAX_REFCOUNT
853 +"\n4:\n"
854 + _ASM_EXTABLE(2b, 4b)
855 +#endif
856 +
857 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858 + : "r" (&v->counter), "Ir" (i)
859 + : "cc");
860 +}
861 +
862 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863 +{
864 + unsigned long tmp;
865 + int result;
866 +
867 + __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875 +"1: ldrex %1, [%3]\n"
876 +" adds %0, %1, %4\n"
877 +
878 +#ifdef CONFIG_PAX_REFCOUNT
879 +" bvc 3f\n"
880 +" mov %0, %1\n"
881 +"2: bkpt 0xf103\n"
882 +"3:\n"
883 +#endif
884 +
885 +" strex %1, %0, [%3]\n"
886 +" teq %1, #0\n"
887 +" bne 1b"
888 +
889 +#ifdef CONFIG_PAX_REFCOUNT
890 +"\n4:\n"
891 + _ASM_EXTABLE(2b, 4b)
892 +#endif
893 +
894 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895 + : "r" (&v->counter), "Ir" (i)
896 + : "cc");
897 +
898 + smp_mb();
899 +
900 + return result;
901 +}
902 +
903 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904 +{
905 + unsigned long tmp;
906 + int result;
907 +
908 + smp_mb();
909 +
910 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918 +"1: ldrex %1, [%3]\n"
919 +" subs %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954 -"1: ldrex %0, [%3]\n"
955 -" sub %0, %0, %4\n"
956 +"1: ldrex %1, [%3]\n"
957 +" subs %0, %1, %4\n"
958 +
959 +#ifdef CONFIG_PAX_REFCOUNT
960 +" bvc 3f\n"
961 +" mov %0, %1\n"
962 +"2: bkpt 0xf103\n"
963 +"3:\n"
964 +#endif
965 +
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969 +
970 +#ifdef CONFIG_PAX_REFCOUNT
971 +"\n4:\n"
972 + _ASM_EXTABLE(2b, 4b)
973 +#endif
974 +
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983 +{
984 + unsigned long oldval, res;
985 +
986 + smp_mb();
987 +
988 + do {
989 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990 + "ldrex %1, [%3]\n"
991 + "mov %0, #0\n"
992 + "teq %1, %4\n"
993 + "strexeq %0, %5, [%3]\n"
994 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
996 + : "cc");
997 + } while (res);
998 +
999 + smp_mb();
1000 +
1001 + return oldval;
1002 +}
1003 +
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011 +
1012 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013 +{
1014 + return atomic_add_return(i, v);
1015 +}
1016 +
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019 +{
1020 + (void) atomic_add_return(i, v);
1021 +}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030 +{
1031 + (void) atomic_sub_return(i, v);
1032 +}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041 +{
1042 + return atomic_cmpxchg(v, old, new);
1043 +}
1044 +
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053 +{
1054 + return xchg(&v->counter, new);
1055 +}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064 +{
1065 + atomic_add_unchecked(1, v);
1066 +}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_sub_unchecked(1, v);
1071 +}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075 +{
1076 + return atomic_add_return_unchecked(1, v) == 0;
1077 +}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081 +{
1082 + return atomic_add_return_unchecked(1, v);
1083 +}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087 @@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091 +#ifdef CONFIG_PAX_REFCOUNT
1092 +typedef struct {
1093 + u64 __aligned(8) counter;
1094 +} atomic64_unchecked_t;
1095 +#else
1096 +typedef atomic64_t atomic64_unchecked_t;
1097 +#endif
1098 +
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107 +{
1108 + u64 result;
1109 +
1110 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111 +" ldrexd %0, %H0, [%1]"
1112 + : "=&r" (result)
1113 + : "r" (&v->counter), "Qo" (v->counter)
1114 + );
1115 +
1116 + return result;
1117 +}
1118 +
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127 +{
1128 + u64 tmp;
1129 +
1130 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131 +"1: ldrexd %0, %H0, [%2]\n"
1132 +" strexd %0, %3, %H3, [%2]\n"
1133 +" teq %0, #0\n"
1134 +" bne 1b"
1135 + : "=&r" (tmp), "=Qo" (v->counter)
1136 + : "r" (&v->counter), "r" (i)
1137 + : "cc");
1138 +}
1139 +
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147 +" adcs %H0, %H0, %H4\n"
1148 +
1149 +#ifdef CONFIG_PAX_REFCOUNT
1150 +" bvc 3f\n"
1151 +"2: bkpt 0xf103\n"
1152 +"3:\n"
1153 +#endif
1154 +
1155 +" strexd %1, %0, %H0, [%3]\n"
1156 +" teq %1, #0\n"
1157 +" bne 1b"
1158 +
1159 +#ifdef CONFIG_PAX_REFCOUNT
1160 +"\n4:\n"
1161 + _ASM_EXTABLE(2b, 4b)
1162 +#endif
1163 +
1164 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165 + : "r" (&v->counter), "r" (i)
1166 + : "cc");
1167 +}
1168 +
1169 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170 +{
1171 + u64 result;
1172 + unsigned long tmp;
1173 +
1174 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175 +"1: ldrexd %0, %H0, [%3]\n"
1176 +" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184 - u64 result;
1185 - unsigned long tmp;
1186 + u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191 +"1: ldrexd %1, %H1, [%3]\n"
1192 +" adds %0, %1, %4\n"
1193 +" adcs %H0, %H1, %H4\n"
1194 +
1195 +#ifdef CONFIG_PAX_REFCOUNT
1196 +" bvc 3f\n"
1197 +" mov %0, %1\n"
1198 +" mov %H0, %H1\n"
1199 +"2: bkpt 0xf103\n"
1200 +"3:\n"
1201 +#endif
1202 +
1203 +" strexd %1, %0, %H0, [%3]\n"
1204 +" teq %1, #0\n"
1205 +" bne 1b"
1206 +
1207 +#ifdef CONFIG_PAX_REFCOUNT
1208 +"\n4:\n"
1209 + _ASM_EXTABLE(2b, 4b)
1210 +#endif
1211 +
1212 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213 + : "r" (&v->counter), "r" (i)
1214 + : "cc");
1215 +
1216 + smp_mb();
1217 +
1218 + return result;
1219 +}
1220 +
1221 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222 +{
1223 + u64 result;
1224 + unsigned long tmp;
1225 +
1226 + smp_mb();
1227 +
1228 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236 +" sbcs %H0, %H0, %H4\n"
1237 +
1238 +#ifdef CONFIG_PAX_REFCOUNT
1239 +" bvc 3f\n"
1240 +"2: bkpt 0xf103\n"
1241 +"3:\n"
1242 +#endif
1243 +
1244 +" strexd %1, %0, %H0, [%3]\n"
1245 +" teq %1, #0\n"
1246 +" bne 1b"
1247 +
1248 +#ifdef CONFIG_PAX_REFCOUNT
1249 +"\n4:\n"
1250 + _ASM_EXTABLE(2b, 4b)
1251 +#endif
1252 +
1253 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254 + : "r" (&v->counter), "r" (i)
1255 + : "cc");
1256 +}
1257 +
1258 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259 +{
1260 + u64 result;
1261 + unsigned long tmp;
1262 +
1263 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264 +"1: ldrexd %0, %H0, [%3]\n"
1265 +" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273 - u64 result;
1274 - unsigned long tmp;
1275 + u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280 -"1: ldrexd %0, %H0, [%3]\n"
1281 -" subs %0, %0, %4\n"
1282 -" sbc %H0, %H0, %H4\n"
1283 +"1: ldrexd %1, %H1, [%3]\n"
1284 +" subs %0, %1, %4\n"
1285 +" sbcs %H0, %H1, %H4\n"
1286 +
1287 +#ifdef CONFIG_PAX_REFCOUNT
1288 +" bvc 3f\n"
1289 +" mov %0, %1\n"
1290 +" mov %H0, %H1\n"
1291 +"2: bkpt 0xf103\n"
1292 +"3:\n"
1293 +#endif
1294 +
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +"\n4:\n"
1301 + _ASM_EXTABLE(2b, 4b)
1302 +#endif
1303 +
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312 +{
1313 + u64 oldval;
1314 + unsigned long res;
1315 +
1316 + smp_mb();
1317 +
1318 + do {
1319 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320 + "ldrexd %1, %H1, [%3]\n"
1321 + "mov %0, #0\n"
1322 + "teq %1, %4\n"
1323 + "teqeq %H1, %H4\n"
1324 + "strexdeq %0, %5, %H5, [%3]"
1325 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326 + : "r" (&ptr->counter), "r" (old), "r" (new)
1327 + : "cc");
1328 + } while (res);
1329 +
1330 + smp_mb();
1331 +
1332 + return oldval;
1333 +}
1334 +
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342 - u64 result;
1343 - unsigned long tmp;
1344 + u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349 -"1: ldrexd %0, %H0, [%3]\n"
1350 -" subs %0, %0, #1\n"
1351 -" sbc %H0, %H0, #0\n"
1352 +"1: ldrexd %1, %H1, [%3]\n"
1353 +" subs %0, %1, #1\n"
1354 +" sbcs %H0, %H1, #0\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 +" bvc 3f\n"
1358 +" mov %0, %1\n"
1359 +" mov %H0, %H1\n"
1360 +"2: bkpt 0xf103\n"
1361 +"3:\n"
1362 +#endif
1363 +
1364 " teq %H0, #0\n"
1365 -" bmi 2f\n"
1366 +" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370 -"2:"
1371 +"4:\n"
1372 +
1373 +#ifdef CONFIG_PAX_REFCOUNT
1374 + _ASM_EXTABLE(2b, 4b)
1375 +#endif
1376 +
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384 -" beq 2f\n"
1385 +" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387 -" adc %H0, %H0, %H6\n"
1388 +" adcs %H0, %H0, %H6\n"
1389 +
1390 +#ifdef CONFIG_PAX_REFCOUNT
1391 +" bvc 3f\n"
1392 +"2: bkpt 0xf103\n"
1393 +"3:\n"
1394 +#endif
1395 +
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399 -"2:"
1400 +"4:\n"
1401 +
1402 +#ifdef CONFIG_PAX_REFCOUNT
1403 + _ASM_EXTABLE(2b, 4b)
1404 +#endif
1405 +
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424 index 75fe66b..ba3dee4 100644
1425 --- a/arch/arm/include/asm/cache.h
1426 +++ b/arch/arm/include/asm/cache.h
1427 @@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431 +#include <linux/const.h>
1432 +
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439 @@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447 index e1489c5..d418304 100644
1448 --- a/arch/arm/include/asm/cacheflush.h
1449 +++ b/arch/arm/include/asm/cacheflush.h
1450 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454 -};
1455 +} __no_const;
1456
1457 /*
1458 * Select the calling method
1459 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460 index 7eb18c1..e38b6d2 100644
1461 --- a/arch/arm/include/asm/cmpxchg.h
1462 +++ b/arch/arm/include/asm/cmpxchg.h
1463 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467 +#define xchg_unchecked(ptr,x) \
1468 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473 index ab98fdd..6b19938 100644
1474 --- a/arch/arm/include/asm/delay.h
1475 +++ b/arch/arm/include/asm/delay.h
1476 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480 -} arm_delay_ops;
1481 +} *arm_delay_ops;
1482
1483 -#define __delay(n) arm_delay_ops.delay(n)
1484 +#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492 -#define __udelay(n) arm_delay_ops.udelay(n)
1493 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494 +#define __udelay(n) arm_delay_ops->udelay(n)
1495 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500 index 38050b1..9d90e8b 100644
1501 --- a/arch/arm/include/asm/elf.h
1502 +++ b/arch/arm/include/asm/elf.h
1503 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509 +
1510 +#ifdef CONFIG_PAX_ASLR
1511 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512 +
1513 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515 +#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523 -struct mm_struct;
1524 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525 -#define arch_randomize_brk arch_randomize_brk
1526 -
1527 #endif
1528 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529 index 83eb2f7..ed77159 100644
1530 --- a/arch/arm/include/asm/kmap_types.h
1531 +++ b/arch/arm/include/asm/kmap_types.h
1532 @@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536 -#define KM_TYPE_NR 16
1537 +#define KM_TYPE_NR 17
1538
1539 #endif
1540 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541 index 9e614a1..3302cca 100644
1542 --- a/arch/arm/include/asm/mach/dma.h
1543 +++ b/arch/arm/include/asm/mach/dma.h
1544 @@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548 -};
1549 +} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554 index 195ac2f..2272f0d 100644
1555 --- a/arch/arm/include/asm/mach/map.h
1556 +++ b/arch/arm/include/asm/mach/map.h
1557 @@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561 +#define MT_MEMORY_R 16
1562 +#define MT_MEMORY_RW 17
1563 +#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568 index 53426c6..c7baff3 100644
1569 --- a/arch/arm/include/asm/outercache.h
1570 +++ b/arch/arm/include/asm/outercache.h
1571 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575 -};
1576 +} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581 index 812a494..71fc0b6 100644
1582 --- a/arch/arm/include/asm/page.h
1583 +++ b/arch/arm/include/asm/page.h
1584 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588 -};
1589 +} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594 index 943504f..84d0f84 100644
1595 --- a/arch/arm/include/asm/pgalloc.h
1596 +++ b/arch/arm/include/asm/pgalloc.h
1597 @@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601 +#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610 +{
1611 + pud_populate(mm, pud, pmd);
1612 +}
1613 +
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625 @@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630 +{
1631 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632 + pmdp[0] = __pmd(pmdval);
1633 +#ifndef CONFIG_ARM_LPAE
1634 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635 +#endif
1636 + flush_pmd_entry(pmdp);
1637 +}
1638 +
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642 @@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652 index 5cfba15..d437dc2 100644
1653 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655 @@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663 +
1664 /*
1665 * - section
1666 */
1667 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671 @@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680 index 2317a71..1897391 100644
1681 --- a/arch/arm/include/asm/pgtable-2level.h
1682 +++ b/arch/arm/include/asm/pgtable-2level.h
1683 @@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687 +#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692 index d795282..d82ff13 100644
1693 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695 @@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703 @@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715 @@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724 index b249035..4ab204b 100644
1725 --- a/arch/arm/include/asm/pgtable-3level.h
1726 +++ b/arch/arm/include/asm/pgtable-3level.h
1727 @@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735 @@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744 index 08c1231..1031bb4 100644
1745 --- a/arch/arm/include/asm/pgtable.h
1746 +++ b/arch/arm/include/asm/pgtable.h
1747 @@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751 +#define ktla_ktva(addr) (addr)
1752 +#define ktva_ktla(addr) (addr)
1753 +
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757 @@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761 +extern pteval_t __supported_pte_mask;
1762 +extern pmdval_t __supported_pmd_mask;
1763 +
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767 @@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773 +
1774 +#ifdef CONFIG_PAX_KERNEXEC
1775 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777 +#else
1778 +static inline unsigned long pax_open_kernel(void) { return 0; }
1779 +static inline unsigned long pax_close_kernel(void) { return 0; }
1780 +#endif
1781 +
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785 @@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789 - * as well as any architecture dependent bits like global/ASID and SMP
1790 - * shared mapping bits.
1791 + * as well as any architecture dependent bits like global/ASID, PXN,
1792 + * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796 @@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806 index f3628fb..a0672dd 100644
1807 --- a/arch/arm/include/asm/proc-fns.h
1808 +++ b/arch/arm/include/asm/proc-fns.h
1809 @@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813 -} processor;
1814 +} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819 index 2e3be16..4dc90fc 100644
1820 --- a/arch/arm/include/asm/smp.h
1821 +++ b/arch/arm/include/asm/smp.h
1822 @@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826 -};
1827 +} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832 index 8477b4c..801a6a9 100644
1833 --- a/arch/arm/include/asm/thread_info.h
1834 +++ b/arch/arm/include/asm/thread_info.h
1835 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839 +
1840 +/* within 8 bits of TIF_SYSCALL_TRACE
1841 + to meet flexible second operand requirements
1842 +*/
1843 +#define TIF_GRSEC_SETXID 11
1844 +
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857 + _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862 index 7e1f760..f2c37b1 100644
1863 --- a/arch/arm/include/asm/uaccess.h
1864 +++ b/arch/arm/include/asm/uaccess.h
1865 @@ -418,8 +418,23 @@ do { \
1866
1867
1868 #ifdef CONFIG_MMU
1869 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1870 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1871 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1872 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1873 +
1874 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1875 +{
1876 + check_object_size(to, n, false);
1877 +
1878 + return ___copy_from_user(to, from, n);
1879 +}
1880 +
1881 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1882 +{
1883 + check_object_size(from, n, true);
1884 +
1885 + return ___copy_to_user(to, from, n);
1886 +}
1887 +
1888 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1889 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1890 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1891 @@ -431,6 +446,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1892
1893 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1894 {
1895 + if ((long)n < 0)
1896 + return n;
1897 +
1898 if (access_ok(VERIFY_READ, from, n))
1899 n = __copy_from_user(to, from, n);
1900 else /* security hole - plug it */
1901 @@ -440,6 +458,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1902
1903 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1904 {
1905 + if ((long)n < 0)
1906 + return n;
1907 +
1908 if (access_ok(VERIFY_WRITE, to, n))
1909 n = __copy_to_user(to, from, n);
1910 return n;
1911 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1912 index 96ee092..37f1844 100644
1913 --- a/arch/arm/include/uapi/asm/ptrace.h
1914 +++ b/arch/arm/include/uapi/asm/ptrace.h
1915 @@ -73,7 +73,7 @@
1916 * ARMv7 groups of PSR bits
1917 */
1918 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1919 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1920 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1921 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1922 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1923
1924 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1925 index 60d3b73..9168db0 100644
1926 --- a/arch/arm/kernel/armksyms.c
1927 +++ b/arch/arm/kernel/armksyms.c
1928 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1929 #ifdef CONFIG_MMU
1930 EXPORT_SYMBOL(copy_page);
1931
1932 -EXPORT_SYMBOL(__copy_from_user);
1933 -EXPORT_SYMBOL(__copy_to_user);
1934 +EXPORT_SYMBOL(___copy_from_user);
1935 +EXPORT_SYMBOL(___copy_to_user);
1936 EXPORT_SYMBOL(__clear_user);
1937
1938 EXPORT_SYMBOL(__get_user_1);
1939 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1940 index 486a15a..d95523a 100644
1941 --- a/arch/arm/kernel/head.S
1942 +++ b/arch/arm/kernel/head.S
1943 @@ -52,7 +52,9 @@
1944 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1945
1946 .macro pgtbl, rd, phys
1947 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1948 + mov \rd, #TEXT_OFFSET
1949 + sub \rd, #PG_DIR_SIZE
1950 + add \rd, \rd, \phys
1951 .endm
1952
1953 /*
1954 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1955 index 1e9be5d..03edbc2 100644
1956 --- a/arch/arm/kernel/module.c
1957 +++ b/arch/arm/kernel/module.c
1958 @@ -37,12 +37,37 @@
1959 #endif
1960
1961 #ifdef CONFIG_MMU
1962 -void *module_alloc(unsigned long size)
1963 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1964 {
1965 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
1966 + return NULL;
1967 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1968 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1969 + GFP_KERNEL, prot, -1,
1970 __builtin_return_address(0));
1971 }
1972 +
1973 +void *module_alloc(unsigned long size)
1974 +{
1975 +
1976 +#ifdef CONFIG_PAX_KERNEXEC
1977 + return __module_alloc(size, PAGE_KERNEL);
1978 +#else
1979 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1980 +#endif
1981 +
1982 +}
1983 +
1984 +#ifdef CONFIG_PAX_KERNEXEC
1985 +void module_free_exec(struct module *mod, void *module_region)
1986 +{
1987 + module_free(mod, module_region);
1988 +}
1989 +
1990 +void *module_alloc_exec(unsigned long size)
1991 +{
1992 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1993 +}
1994 +#endif
1995 #endif
1996
1997 int
1998 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1999 index 90084a6..a8b26bc 100644
2000 --- a/arch/arm/kernel/process.c
2001 +++ b/arch/arm/kernel/process.c
2002 @@ -28,7 +28,6 @@
2003 #include <linux/tick.h>
2004 #include <linux/utsname.h>
2005 #include <linux/uaccess.h>
2006 -#include <linux/random.h>
2007 #include <linux/hw_breakpoint.h>
2008 #include <linux/cpuidle.h>
2009 #include <linux/leds.h>
2010 @@ -256,9 +255,10 @@ void machine_power_off(void)
2011 machine_shutdown();
2012 if (pm_power_off)
2013 pm_power_off();
2014 + BUG();
2015 }
2016
2017 -void machine_restart(char *cmd)
2018 +__noreturn void machine_restart(char *cmd)
2019 {
2020 machine_shutdown();
2021
2022 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2023 init_utsname()->release,
2024 (int)strcspn(init_utsname()->version, " "),
2025 init_utsname()->version);
2026 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2027 - print_symbol("LR is at %s\n", regs->ARM_lr);
2028 + printk("PC is at %pA\n", instruction_pointer(regs));
2029 + printk("LR is at %pA\n", regs->ARM_lr);
2030 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2031 "sp : %08lx ip : %08lx fp : %08lx\n",
2032 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2033 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2034 return 0;
2035 }
2036
2037 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2038 -{
2039 - unsigned long range_end = mm->brk + 0x02000000;
2040 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2041 -}
2042 -
2043 #ifdef CONFIG_MMU
2044 /*
2045 * The vectors page is always readable from user space for the
2046 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2047 index 739db3a..7f4a272 100644
2048 --- a/arch/arm/kernel/ptrace.c
2049 +++ b/arch/arm/kernel/ptrace.c
2050 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2051 PTRACE_SYSCALL_EXIT,
2052 };
2053
2054 +#ifdef CONFIG_GRKERNSEC_SETXID
2055 +extern void gr_delayed_cred_worker(void);
2056 +#endif
2057 +
2058 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2059 enum ptrace_syscall_dir dir)
2060 {
2061 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2062
2063 current_thread_info()->syscall = scno;
2064
2065 +#ifdef CONFIG_GRKERNSEC_SETXID
2066 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2067 + gr_delayed_cred_worker();
2068 +#endif
2069 +
2070 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2071 return scno;
2072
2073 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2074 index da1d1aa..ef9bc58 100644
2075 --- a/arch/arm/kernel/setup.c
2076 +++ b/arch/arm/kernel/setup.c
2077 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2078 unsigned int elf_hwcap __read_mostly;
2079 EXPORT_SYMBOL(elf_hwcap);
2080
2081 +pteval_t __supported_pte_mask __read_only;
2082 +pmdval_t __supported_pmd_mask __read_only;
2083
2084 #ifdef MULTI_CPU
2085 -struct processor processor __read_mostly;
2086 +struct processor processor;
2087 #endif
2088 #ifdef MULTI_TLB
2089 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2090 +struct cpu_tlb_fns cpu_tlb __read_only;
2091 #endif
2092 #ifdef MULTI_USER
2093 -struct cpu_user_fns cpu_user __read_mostly;
2094 +struct cpu_user_fns cpu_user __read_only;
2095 #endif
2096 #ifdef MULTI_CACHE
2097 -struct cpu_cache_fns cpu_cache __read_mostly;
2098 +struct cpu_cache_fns cpu_cache __read_only;
2099 #endif
2100 #ifdef CONFIG_OUTER_CACHE
2101 -struct outer_cache_fns outer_cache __read_mostly;
2102 +struct outer_cache_fns outer_cache __read_only;
2103 EXPORT_SYMBOL(outer_cache);
2104 #endif
2105
2106 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2107 asm("mrc p15, 0, %0, c0, c1, 4"
2108 : "=r" (mmfr0));
2109 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2110 - (mmfr0 & 0x000000f0) >= 0x00000030)
2111 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2112 cpu_arch = CPU_ARCH_ARMv7;
2113 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2114 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2115 + __supported_pte_mask |= L_PTE_PXN;
2116 + __supported_pmd_mask |= PMD_PXNTABLE;
2117 + }
2118 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2119 (mmfr0 & 0x000000f0) == 0x00000020)
2120 cpu_arch = CPU_ARCH_ARMv6;
2121 else
2122 @@ -455,7 +461,7 @@ static void __init setup_processor(void)
2123 __cpu_architecture = __get_cpu_architecture();
2124
2125 #ifdef MULTI_CPU
2126 - processor = *list->proc;
2127 + memcpy((void *)&processor, list->proc, sizeof processor);
2128 #endif
2129 #ifdef MULTI_TLB
2130 cpu_tlb = *list->tlb;
2131 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2132 index fbc8b26..000ded0 100644
2133 --- a/arch/arm/kernel/smp.c
2134 +++ b/arch/arm/kernel/smp.c
2135 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2136
2137 static DECLARE_COMPLETION(cpu_running);
2138
2139 -static struct smp_operations smp_ops;
2140 +static struct smp_operations smp_ops __read_only;
2141
2142 void __init smp_set_ops(struct smp_operations *ops)
2143 {
2144 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2145 index b0179b8..7713948 100644
2146 --- a/arch/arm/kernel/traps.c
2147 +++ b/arch/arm/kernel/traps.c
2148 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2149 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2150 {
2151 #ifdef CONFIG_KALLSYMS
2152 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2153 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2154 #else
2155 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2156 #endif
2157 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2158 static int die_owner = -1;
2159 static unsigned int die_nest_count;
2160
2161 +extern void gr_handle_kernel_exploit(void);
2162 +
2163 static unsigned long oops_begin(void)
2164 {
2165 int cpu;
2166 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2167 panic("Fatal exception in interrupt");
2168 if (panic_on_oops)
2169 panic("Fatal exception");
2170 +
2171 + gr_handle_kernel_exploit();
2172 +
2173 if (signr)
2174 do_exit(signr);
2175 }
2176 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2177 index 36ff15b..75d9e9d 100644
2178 --- a/arch/arm/kernel/vmlinux.lds.S
2179 +++ b/arch/arm/kernel/vmlinux.lds.S
2180 @@ -8,7 +8,11 @@
2181 #include <asm/thread_info.h>
2182 #include <asm/memory.h>
2183 #include <asm/page.h>
2184 -
2185 +
2186 +#ifdef CONFIG_PAX_KERNEXEC
2187 +#include <asm/pgtable.h>
2188 +#endif
2189 +
2190 #define PROC_INFO \
2191 . = ALIGN(4); \
2192 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2193 @@ -90,6 +94,11 @@ SECTIONS
2194 _text = .;
2195 HEAD_TEXT
2196 }
2197 +
2198 +#ifdef CONFIG_PAX_KERNEXEC
2199 + . = ALIGN(1<<SECTION_SHIFT);
2200 +#endif
2201 +
2202 .text : { /* Real text segment */
2203 _stext = .; /* Text and read-only data */
2204 __exception_text_start = .;
2205 @@ -133,6 +142,10 @@ SECTIONS
2206
2207 _etext = .; /* End of text and rodata section */
2208
2209 +#ifdef CONFIG_PAX_KERNEXEC
2210 + . = ALIGN(1<<SECTION_SHIFT);
2211 +#endif
2212 +
2213 #ifndef CONFIG_XIP_KERNEL
2214 . = ALIGN(PAGE_SIZE);
2215 __init_begin = .;
2216 @@ -192,6 +205,11 @@ SECTIONS
2217 . = PAGE_OFFSET + TEXT_OFFSET;
2218 #else
2219 __init_end = .;
2220 +
2221 +#ifdef CONFIG_PAX_KERNEXEC
2222 + . = ALIGN(1<<SECTION_SHIFT);
2223 +#endif
2224 +
2225 . = ALIGN(THREAD_SIZE);
2226 __data_loc = .;
2227 #endif
2228 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2229 index 66a477a..bee61d3 100644
2230 --- a/arch/arm/lib/copy_from_user.S
2231 +++ b/arch/arm/lib/copy_from_user.S
2232 @@ -16,7 +16,7 @@
2233 /*
2234 * Prototype:
2235 *
2236 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2237 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2238 *
2239 * Purpose:
2240 *
2241 @@ -84,11 +84,11 @@
2242
2243 .text
2244
2245 -ENTRY(__copy_from_user)
2246 +ENTRY(___copy_from_user)
2247
2248 #include "copy_template.S"
2249
2250 -ENDPROC(__copy_from_user)
2251 +ENDPROC(___copy_from_user)
2252
2253 .pushsection .fixup,"ax"
2254 .align 0
2255 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2256 index 6ee2f67..d1cce76 100644
2257 --- a/arch/arm/lib/copy_page.S
2258 +++ b/arch/arm/lib/copy_page.S
2259 @@ -10,6 +10,7 @@
2260 * ASM optimised string functions
2261 */
2262 #include <linux/linkage.h>
2263 +#include <linux/const.h>
2264 #include <asm/assembler.h>
2265 #include <asm/asm-offsets.h>
2266 #include <asm/cache.h>
2267 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2268 index d066df6..df28194 100644
2269 --- a/arch/arm/lib/copy_to_user.S
2270 +++ b/arch/arm/lib/copy_to_user.S
2271 @@ -16,7 +16,7 @@
2272 /*
2273 * Prototype:
2274 *
2275 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2276 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2277 *
2278 * Purpose:
2279 *
2280 @@ -88,11 +88,11 @@
2281 .text
2282
2283 ENTRY(__copy_to_user_std)
2284 -WEAK(__copy_to_user)
2285 +WEAK(___copy_to_user)
2286
2287 #include "copy_template.S"
2288
2289 -ENDPROC(__copy_to_user)
2290 +ENDPROC(___copy_to_user)
2291 ENDPROC(__copy_to_user_std)
2292
2293 .pushsection .fixup,"ax"
2294 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2295 index 0dc5385..45833ef 100644
2296 --- a/arch/arm/lib/delay.c
2297 +++ b/arch/arm/lib/delay.c
2298 @@ -28,12 +28,14 @@
2299 /*
2300 * Default to the loop-based delay implementation.
2301 */
2302 -struct arm_delay_ops arm_delay_ops = {
2303 +static struct arm_delay_ops arm_loop_delay_ops = {
2304 .delay = __loop_delay,
2305 .const_udelay = __loop_const_udelay,
2306 .udelay = __loop_udelay,
2307 };
2308
2309 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2310 +
2311 static const struct delay_timer *delay_timer;
2312 static bool delay_calibrated;
2313
2314 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2315 __timer_const_udelay(usecs * UDELAY_MULT);
2316 }
2317
2318 +static struct arm_delay_ops arm_timer_delay_ops = {
2319 + .delay = __timer_delay,
2320 + .const_udelay = __timer_const_udelay,
2321 + .udelay = __timer_udelay,
2322 +};
2323 +
2324 void __init register_current_timer_delay(const struct delay_timer *timer)
2325 {
2326 if (!delay_calibrated) {
2327 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2328 delay_timer = timer;
2329 lpj_fine = timer->freq / HZ;
2330 loops_per_jiffy = lpj_fine;
2331 - arm_delay_ops.delay = __timer_delay;
2332 - arm_delay_ops.const_udelay = __timer_const_udelay;
2333 - arm_delay_ops.udelay = __timer_udelay;
2334 + arm_delay_ops = &arm_timer_delay_ops;
2335 delay_calibrated = true;
2336 } else {
2337 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2338 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2339 index 025f742..8432b08 100644
2340 --- a/arch/arm/lib/uaccess_with_memcpy.c
2341 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2342 @@ -104,7 +104,7 @@ out:
2343 }
2344
2345 unsigned long
2346 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2347 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2348 {
2349 /*
2350 * This test is stubbed out of the main function above to keep
2351 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2352 index 2c6c218..2b87c2d 100644
2353 --- a/arch/arm/mach-kirkwood/common.c
2354 +++ b/arch/arm/mach-kirkwood/common.c
2355 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2356 clk_gate_ops.disable(hw);
2357 }
2358
2359 -static struct clk_ops clk_gate_fn_ops;
2360 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2361 +{
2362 + return clk_gate_ops.is_enabled(hw);
2363 +}
2364 +
2365 +static struct clk_ops clk_gate_fn_ops = {
2366 + .enable = clk_gate_fn_enable,
2367 + .disable = clk_gate_fn_disable,
2368 + .is_enabled = clk_gate_fn_is_enabled,
2369 +};
2370
2371 static struct clk __init *clk_register_gate_fn(struct device *dev,
2372 const char *name,
2373 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2374 gate_fn->fn_en = fn_en;
2375 gate_fn->fn_dis = fn_dis;
2376
2377 - /* ops is the gate ops, but with our enable/disable functions */
2378 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2379 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2380 - clk_gate_fn_ops = clk_gate_ops;
2381 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2382 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2383 - }
2384 -
2385 clk = clk_register(dev, &gate_fn->gate.hw);
2386
2387 if (IS_ERR(clk))
2388 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2389 index d95f727..12f10dd 100644
2390 --- a/arch/arm/mach-omap2/board-n8x0.c
2391 +++ b/arch/arm/mach-omap2/board-n8x0.c
2392 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2393 }
2394 #endif
2395
2396 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2397 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2398 .late_init = n8x0_menelaus_late_init,
2399 };
2400
2401 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2402 index 87cc6d0..fd4f248 100644
2403 --- a/arch/arm/mach-omap2/omap_hwmod.c
2404 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2405 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2406 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2407 struct omap_hwmod_rst_info *ohri);
2408 int (*init_clkdm)(struct omap_hwmod *oh);
2409 -};
2410 +} __no_const;
2411
2412 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2413 -static struct omap_hwmod_soc_ops soc_ops;
2414 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2415
2416 /* omap_hwmod_list contains all registered struct omap_hwmods */
2417 static LIST_HEAD(omap_hwmod_list);
2418 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2419 index 5dbf13f..9be36fd 100644
2420 --- a/arch/arm/mm/fault.c
2421 +++ b/arch/arm/mm/fault.c
2422 @@ -25,6 +25,7 @@
2423 #include <asm/system_misc.h>
2424 #include <asm/system_info.h>
2425 #include <asm/tlbflush.h>
2426 +#include <asm/sections.h>
2427
2428 #include "fault.h"
2429
2430 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2431 if (fixup_exception(regs))
2432 return;
2433
2434 +#ifdef CONFIG_PAX_KERNEXEC
2435 + if (fsr & FSR_WRITE) {
2436 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2437 + if (current->signal->curr_ip)
2438 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2439 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2440 + else
2441 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2442 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2443 + }
2444 + }
2445 +#endif
2446 +
2447 /*
2448 * No handler, we'll have to terminate things with extreme prejudice.
2449 */
2450 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2451 }
2452 #endif
2453
2454 +#ifdef CONFIG_PAX_PAGEEXEC
2455 + if (fsr & FSR_LNX_PF) {
2456 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2457 + do_group_exit(SIGKILL);
2458 + }
2459 +#endif
2460 +
2461 tsk->thread.address = addr;
2462 tsk->thread.error_code = fsr;
2463 tsk->thread.trap_no = 14;
2464 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2465 }
2466 #endif /* CONFIG_MMU */
2467
2468 +#ifdef CONFIG_PAX_PAGEEXEC
2469 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2470 +{
2471 + long i;
2472 +
2473 + printk(KERN_ERR "PAX: bytes at PC: ");
2474 + for (i = 0; i < 20; i++) {
2475 + unsigned char c;
2476 + if (get_user(c, (__force unsigned char __user *)pc+i))
2477 + printk(KERN_CONT "?? ");
2478 + else
2479 + printk(KERN_CONT "%02x ", c);
2480 + }
2481 + printk("\n");
2482 +
2483 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2484 + for (i = -1; i < 20; i++) {
2485 + unsigned long c;
2486 + if (get_user(c, (__force unsigned long __user *)sp+i))
2487 + printk(KERN_CONT "???????? ");
2488 + else
2489 + printk(KERN_CONT "%08lx ", c);
2490 + }
2491 + printk("\n");
2492 +}
2493 +#endif
2494 +
2495 /*
2496 * First Level Translation Fault Handler
2497 *
2498 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2499 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2500 struct siginfo info;
2501
2502 +#ifdef CONFIG_PAX_KERNEXEC
2503 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2504 + if (current->signal->curr_ip)
2505 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2506 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2507 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2508 + else
2509 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2510 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2511 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2512 + goto die;
2513 + }
2514 +#endif
2515 +
2516 +#ifdef CONFIG_PAX_REFCOUNT
2517 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2518 + unsigned int bkpt;
2519 +
2520 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2521 + current->thread.error_code = ifsr;
2522 + current->thread.trap_no = 0;
2523 + pax_report_refcount_overflow(regs);
2524 + fixup_exception(regs);
2525 + return;
2526 + }
2527 + }
2528 +#endif
2529 +
2530 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2531 return;
2532
2533 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2534 inf->name, ifsr, addr);
2535
2536 +die:
2537 info.si_signo = inf->sig;
2538 info.si_errno = 0;
2539 info.si_code = inf->code;
2540 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2541 index cf08bdf..f1a0383 100644
2542 --- a/arch/arm/mm/fault.h
2543 +++ b/arch/arm/mm/fault.h
2544 @@ -3,6 +3,7 @@
2545
2546 /*
2547 * Fault status register encodings. We steal bit 31 for our own purposes.
2548 + * Set when the FSR value is from an instruction fault.
2549 */
2550 #define FSR_LNX_PF (1 << 31)
2551 #define FSR_WRITE (1 << 11)
2552 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2553 }
2554 #endif
2555
2556 +/* valid for LPAE and !LPAE */
2557 +static inline int is_xn_fault(unsigned int fsr)
2558 +{
2559 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2560 +}
2561 +
2562 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2563 unsigned long search_exception_table(unsigned long addr);
2564
2565 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2566 index ad722f1..46b670e 100644
2567 --- a/arch/arm/mm/init.c
2568 +++ b/arch/arm/mm/init.c
2569 @@ -734,9 +734,43 @@ void __init mem_init(void)
2570
2571 void free_initmem(void)
2572 {
2573 +
2574 +#ifdef CONFIG_PAX_KERNEXEC
2575 + unsigned long addr;
2576 + pgd_t *pgd;
2577 + pud_t *pud;
2578 + pmd_t *pmd;
2579 +#endif
2580 +
2581 #ifdef CONFIG_HAVE_TCM
2582 extern char __tcm_start, __tcm_end;
2583 +#endif
2584
2585 +#ifdef CONFIG_PAX_KERNEXEC
2586 + /* make pages tables, etc before .text NX */
2587 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2588 + pgd = pgd_offset_k(addr);
2589 + pud = pud_offset(pgd, addr);
2590 + pmd = pmd_offset(pud, addr);
2591 + __pmd_update(pmd, PMD_SECT_XN);
2592 + }
2593 + /* make init NX */
2594 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2595 + pgd = pgd_offset_k(addr);
2596 + pud = pud_offset(pgd, addr);
2597 + pmd = pmd_offset(pud, addr);
2598 + __pmd_update(pmd, PMD_SECT_XN);
2599 + }
2600 + /* make kernel code/rodata read-only */
2601 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2602 + pgd = pgd_offset_k(addr);
2603 + pud = pud_offset(pgd, addr);
2604 + pmd = pmd_offset(pud, addr);
2605 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2606 + }
2607 +#endif
2608 +
2609 +#ifdef CONFIG_HAVE_TCM
2610 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2611 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2612 __phys_to_pfn(__pa(&__tcm_end)),
2613 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2614 index ce8cb19..061aa14 100644
2615 --- a/arch/arm/mm/mmap.c
2616 +++ b/arch/arm/mm/mmap.c
2617 @@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2618 unsigned long start_addr;
2619 int do_align = 0;
2620 int aliasing = cache_is_vipt_aliasing();
2621 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2622
2623 /*
2624 * We only need to do colour alignment if either the I or D
2625 @@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2626 if (len > TASK_SIZE)
2627 return -ENOMEM;
2628
2629 +#ifdef CONFIG_PAX_RANDMMAP
2630 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2631 +#endif
2632 +
2633 if (addr) {
2634 if (do_align)
2635 addr = COLOUR_ALIGN(addr, pgoff);
2636 @@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2637 addr = PAGE_ALIGN(addr);
2638
2639 vma = find_vma(mm, addr);
2640 - if (TASK_SIZE - len >= addr &&
2641 - (!vma || addr + len <= vma->vm_start))
2642 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2643 return addr;
2644 }
2645 if (len > mm->cached_hole_size) {
2646 - start_addr = addr = mm->free_area_cache;
2647 + start_addr = addr = mm->free_area_cache;
2648 } else {
2649 - start_addr = addr = mm->mmap_base;
2650 - mm->cached_hole_size = 0;
2651 + start_addr = addr = mm->mmap_base;
2652 + mm->cached_hole_size = 0;
2653 }
2654
2655 full_search:
2656 @@ -124,14 +128,14 @@ full_search:
2657 * Start a new search - just in case we missed
2658 * some holes.
2659 */
2660 - if (start_addr != TASK_UNMAPPED_BASE) {
2661 - start_addr = addr = TASK_UNMAPPED_BASE;
2662 + if (start_addr != mm->mmap_base) {
2663 + start_addr = addr = mm->mmap_base;
2664 mm->cached_hole_size = 0;
2665 goto full_search;
2666 }
2667 return -ENOMEM;
2668 }
2669 - if (!vma || addr + len <= vma->vm_start) {
2670 + if (check_heap_stack_gap(vma, addr, len, offset)) {
2671 /*
2672 * Remember the place where we stopped the search:
2673 */
2674 @@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2675 unsigned long addr = addr0;
2676 int do_align = 0;
2677 int aliasing = cache_is_vipt_aliasing();
2678 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2679
2680 /*
2681 * We only need to do colour alignment if either the I or D
2682 @@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2683 return addr;
2684 }
2685
2686 +#ifdef CONFIG_PAX_RANDMMAP
2687 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2688 +#endif
2689 +
2690 /* requesting a specific address */
2691 if (addr) {
2692 if (do_align)
2693 @@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2694 else
2695 addr = PAGE_ALIGN(addr);
2696 vma = find_vma(mm, addr);
2697 - if (TASK_SIZE - len >= addr &&
2698 - (!vma || addr + len <= vma->vm_start))
2699 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2700 return addr;
2701 }
2702
2703 @@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2704 /* make sure it can fit in the remaining address space */
2705 if (addr > len) {
2706 vma = find_vma(mm, addr-len);
2707 - if (!vma || addr <= vma->vm_start)
2708 + if (check_heap_stack_gap(vma, addr - len, len, offset))
2709 /* remember the address as a hint for next time */
2710 return (mm->free_area_cache = addr-len);
2711 }
2712 @@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2713 goto bottomup;
2714
2715 addr = mm->mmap_base - len;
2716 - if (do_align)
2717 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2718
2719 do {
2720 + if (do_align)
2721 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2722 /*
2723 * Lookup failure means no vma is above this address,
2724 * else if new region fits below vma->vm_start,
2725 * return with success:
2726 */
2727 vma = find_vma(mm, addr);
2728 - if (!vma || addr+len <= vma->vm_start)
2729 + if (check_heap_stack_gap(vma, addr, len, offset))
2730 /* remember the address as a hint for next time */
2731 return (mm->free_area_cache = addr);
2732
2733 @@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2734 mm->cached_hole_size = vma->vm_start - addr;
2735
2736 /* try just below the current vma->vm_start */
2737 - addr = vma->vm_start - len;
2738 - if (do_align)
2739 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2740 - } while (len < vma->vm_start);
2741 + addr = skip_heap_stack_gap(vma, len, offset);
2742 + } while (!IS_ERR_VALUE(addr));
2743
2744 bottomup:
2745 /*
2746 @@ -259,6 +265,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2747 {
2748 unsigned long random_factor = 0UL;
2749
2750 +#ifdef CONFIG_PAX_RANDMMAP
2751 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2752 +#endif
2753 +
2754 /* 8 bits of randomness in 20 address space bits */
2755 if ((current->flags & PF_RANDOMIZE) &&
2756 !(current->personality & ADDR_NO_RANDOMIZE))
2757 @@ -266,10 +276,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2758
2759 if (mmap_is_legacy()) {
2760 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2761 +
2762 +#ifdef CONFIG_PAX_RANDMMAP
2763 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2764 + mm->mmap_base += mm->delta_mmap;
2765 +#endif
2766 +
2767 mm->get_unmapped_area = arch_get_unmapped_area;
2768 mm->unmap_area = arch_unmap_area;
2769 } else {
2770 mm->mmap_base = mmap_base(random_factor);
2771 +
2772 +#ifdef CONFIG_PAX_RANDMMAP
2773 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2774 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2775 +#endif
2776 +
2777 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2778 mm->unmap_area = arch_unmap_area_topdown;
2779 }
2780 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2781 index 99b47b9..579b667 100644
2782 --- a/arch/arm/mm/mmu.c
2783 +++ b/arch/arm/mm/mmu.c
2784 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2785 [MT_UNCACHED] = {
2786 .prot_pte = PROT_PTE_DEVICE,
2787 .prot_l1 = PMD_TYPE_TABLE,
2788 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2789 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2790 .domain = DOMAIN_IO,
2791 },
2792 [MT_CACHECLEAN] = {
2793 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2794 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2795 .domain = DOMAIN_KERNEL,
2796 },
2797 #ifndef CONFIG_ARM_LPAE
2798 [MT_MINICLEAN] = {
2799 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2800 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2801 .domain = DOMAIN_KERNEL,
2802 },
2803 #endif
2804 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2806 .domain = DOMAIN_KERNEL,
2807 },
2808 + [MT_MEMORY_R] = {
2809 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2810 + .prot_l1 = PMD_TYPE_TABLE,
2811 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2812 + .domain = DOMAIN_KERNEL,
2813 + },
2814 + [MT_MEMORY_RW] = {
2815 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2816 + .prot_l1 = PMD_TYPE_TABLE,
2817 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2818 + .domain = DOMAIN_KERNEL,
2819 + },
2820 + [MT_MEMORY_RX] = {
2821 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2822 + .prot_l1 = PMD_TYPE_TABLE,
2823 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2824 + .domain = DOMAIN_KERNEL,
2825 + },
2826 [MT_ROM] = {
2827 - .prot_sect = PMD_TYPE_SECT,
2828 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2829 .domain = DOMAIN_KERNEL,
2830 },
2831 [MT_MEMORY_NONCACHED] = {
2832 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2834 L_PTE_XN,
2835 .prot_l1 = PMD_TYPE_TABLE,
2836 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2837 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2838 .domain = DOMAIN_KERNEL,
2839 },
2840 [MT_MEMORY_ITCM] = {
2841 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2842 * from SVC mode and no access from userspace.
2843 */
2844 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2845 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2846 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2847 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2848 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2849 #endif
2850 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2851 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2852 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2853 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2854 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2855 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2856 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2857 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2858 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2859 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2860 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2861 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2862 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2863 @@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2864 vecs_pgprot |= PTE_EXT_AF;
2865 #endif
2866
2867 + user_pgprot |= __supported_pte_mask;
2868 +
2869 for (i = 0; i < 16; i++) {
2870 pteval_t v = pgprot_val(protection_map[i]);
2871 protection_map[i] = __pgprot(v | user_pgprot);
2872 @@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2873 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2874 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2875 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2876 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2877 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2878 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2879 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2880 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2881 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2882 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2883 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2884 mem_types[MT_ROM].prot_sect |= cp->pmd;
2885 @@ -1198,7 +1232,41 @@ static void __init map_lowmem(void)
2886 map.pfn = __phys_to_pfn(start);
2887 map.virtual = __phys_to_virt(start);
2888 map.length = end - start;
2889 +
2890 +#ifdef CONFIG_PAX_KERNEXEC
2891 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2892 + struct map_desc kernel;
2893 + struct map_desc initmap;
2894 +
2895 + /* when freeing initmem we will make this RW */
2896 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2897 + initmap.virtual = (unsigned long)__init_begin;
2898 + initmap.length = _sdata - __init_begin;
2899 + initmap.type = MT_MEMORY;
2900 + create_mapping(&initmap);
2901 +
2902 + /* when freeing initmem we will make this RX */
2903 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2904 + kernel.virtual = (unsigned long)_stext;
2905 + kernel.length = __init_begin - _stext;
2906 + kernel.type = MT_MEMORY;
2907 + create_mapping(&kernel);
2908 +
2909 + if (map.virtual < (unsigned long)_stext) {
2910 + map.length = (unsigned long)_stext - map.virtual;
2911 + map.type = MT_MEMORY;
2912 + create_mapping(&map);
2913 + }
2914 +
2915 + map.pfn = __phys_to_pfn(__pa(_sdata));
2916 + map.virtual = (unsigned long)_sdata;
2917 + map.length = end - __pa(_sdata);
2918 + }
2919 +
2920 + map.type = MT_MEMORY_RW;
2921 +#else
2922 map.type = MT_MEMORY;
2923 +#endif
2924
2925 create_mapping(&map);
2926 }
2927 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2928 index ec63e4a..62aa5f1d 100644
2929 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2930 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2931 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2932 value in bridge_virt_base */
2933 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2934 const int win);
2935 -};
2936 +} __no_const;
2937
2938 /*
2939 * Information needed to setup one address mapping.
2940 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2941 index f5144cd..71f6d1f 100644
2942 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2943 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2944 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2945 int (*started)(unsigned ch);
2946 int (*flush)(unsigned ch);
2947 int (*stop)(unsigned ch);
2948 -};
2949 +} __no_const;
2950
2951 extern void *samsung_dmadev_get_ops(void);
2952 extern void *s3c_dma_get_ops(void);
2953 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2954 index c3a58a1..78fbf54 100644
2955 --- a/arch/avr32/include/asm/cache.h
2956 +++ b/arch/avr32/include/asm/cache.h
2957 @@ -1,8 +1,10 @@
2958 #ifndef __ASM_AVR32_CACHE_H
2959 #define __ASM_AVR32_CACHE_H
2960
2961 +#include <linux/const.h>
2962 +
2963 #define L1_CACHE_SHIFT 5
2964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2966
2967 /*
2968 * Memory returned by kmalloc() may be used for DMA, so we must make
2969 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2970 index e2c3287..6c4f98c 100644
2971 --- a/arch/avr32/include/asm/elf.h
2972 +++ b/arch/avr32/include/asm/elf.h
2973 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2974 the loader. We need to make sure that it is out of the way of the program
2975 that it will "exec", and that there is sufficient room for the brk. */
2976
2977 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2978 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2979
2980 +#ifdef CONFIG_PAX_ASLR
2981 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2982 +
2983 +#define PAX_DELTA_MMAP_LEN 15
2984 +#define PAX_DELTA_STACK_LEN 15
2985 +#endif
2986
2987 /* This yields a mask that user programs can use to figure out what
2988 instruction set this CPU supports. This could be done in user space,
2989 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2990 index 479330b..53717a8 100644
2991 --- a/arch/avr32/include/asm/kmap_types.h
2992 +++ b/arch/avr32/include/asm/kmap_types.h
2993 @@ -2,9 +2,9 @@
2994 #define __ASM_AVR32_KMAP_TYPES_H
2995
2996 #ifdef CONFIG_DEBUG_HIGHMEM
2997 -# define KM_TYPE_NR 29
2998 +# define KM_TYPE_NR 30
2999 #else
3000 -# define KM_TYPE_NR 14
3001 +# define KM_TYPE_NR 15
3002 #endif
3003
3004 #endif /* __ASM_AVR32_KMAP_TYPES_H */
3005 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
3006 index b2f2d2d..d1c85cb 100644
3007 --- a/arch/avr32/mm/fault.c
3008 +++ b/arch/avr32/mm/fault.c
3009 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
3010
3011 int exception_trace = 1;
3012
3013 +#ifdef CONFIG_PAX_PAGEEXEC
3014 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3015 +{
3016 + unsigned long i;
3017 +
3018 + printk(KERN_ERR "PAX: bytes at PC: ");
3019 + for (i = 0; i < 20; i++) {
3020 + unsigned char c;
3021 + if (get_user(c, (unsigned char *)pc+i))
3022 + printk(KERN_CONT "???????? ");
3023 + else
3024 + printk(KERN_CONT "%02x ", c);
3025 + }
3026 + printk("\n");
3027 +}
3028 +#endif
3029 +
3030 /*
3031 * This routine handles page faults. It determines the address and the
3032 * problem, and then passes it off to one of the appropriate routines.
3033 @@ -174,6 +191,16 @@ bad_area:
3034 up_read(&mm->mmap_sem);
3035
3036 if (user_mode(regs)) {
3037 +
3038 +#ifdef CONFIG_PAX_PAGEEXEC
3039 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3040 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3041 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3042 + do_group_exit(SIGKILL);
3043 + }
3044 + }
3045 +#endif
3046 +
3047 if (exception_trace && printk_ratelimit())
3048 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3049 "sp %08lx ecr %lu\n",
3050 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3051 index 568885a..f8008df 100644
3052 --- a/arch/blackfin/include/asm/cache.h
3053 +++ b/arch/blackfin/include/asm/cache.h
3054 @@ -7,6 +7,7 @@
3055 #ifndef __ARCH_BLACKFIN_CACHE_H
3056 #define __ARCH_BLACKFIN_CACHE_H
3057
3058 +#include <linux/const.h>
3059 #include <linux/linkage.h> /* for asmlinkage */
3060
3061 /*
3062 @@ -14,7 +15,7 @@
3063 * Blackfin loads 32 bytes for cache
3064 */
3065 #define L1_CACHE_SHIFT 5
3066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3067 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3068 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3069
3070 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3071 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3072 index aea2718..3639a60 100644
3073 --- a/arch/cris/include/arch-v10/arch/cache.h
3074 +++ b/arch/cris/include/arch-v10/arch/cache.h
3075 @@ -1,8 +1,9 @@
3076 #ifndef _ASM_ARCH_CACHE_H
3077 #define _ASM_ARCH_CACHE_H
3078
3079 +#include <linux/const.h>
3080 /* Etrax 100LX have 32-byte cache-lines. */
3081 -#define L1_CACHE_BYTES 32
3082 #define L1_CACHE_SHIFT 5
3083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3084
3085 #endif /* _ASM_ARCH_CACHE_H */
3086 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3087 index 7caf25d..ee65ac5 100644
3088 --- a/arch/cris/include/arch-v32/arch/cache.h
3089 +++ b/arch/cris/include/arch-v32/arch/cache.h
3090 @@ -1,11 +1,12 @@
3091 #ifndef _ASM_CRIS_ARCH_CACHE_H
3092 #define _ASM_CRIS_ARCH_CACHE_H
3093
3094 +#include <linux/const.h>
3095 #include <arch/hwregs/dma.h>
3096
3097 /* A cache-line is 32 bytes. */
3098 -#define L1_CACHE_BYTES 32
3099 #define L1_CACHE_SHIFT 5
3100 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3101
3102 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3103
3104 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3105 index b86329d..6709906 100644
3106 --- a/arch/frv/include/asm/atomic.h
3107 +++ b/arch/frv/include/asm/atomic.h
3108 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3109 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3110 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3111
3112 +#define atomic64_read_unchecked(v) atomic64_read(v)
3113 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3114 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3115 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3116 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3117 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3118 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3119 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3120 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3121 +
3122 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3123 {
3124 int c, old;
3125 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3126 index 2797163..c2a401d 100644
3127 --- a/arch/frv/include/asm/cache.h
3128 +++ b/arch/frv/include/asm/cache.h
3129 @@ -12,10 +12,11 @@
3130 #ifndef __ASM_CACHE_H
3131 #define __ASM_CACHE_H
3132
3133 +#include <linux/const.h>
3134
3135 /* bytes per L1 cache line */
3136 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3137 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3138 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3139
3140 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3141 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3142 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3143 index 43901f2..0d8b865 100644
3144 --- a/arch/frv/include/asm/kmap_types.h
3145 +++ b/arch/frv/include/asm/kmap_types.h
3146 @@ -2,6 +2,6 @@
3147 #ifndef _ASM_KMAP_TYPES_H
3148 #define _ASM_KMAP_TYPES_H
3149
3150 -#define KM_TYPE_NR 17
3151 +#define KM_TYPE_NR 18
3152
3153 #endif
3154 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3155 index 385fd30..3aaf4fe 100644
3156 --- a/arch/frv/mm/elf-fdpic.c
3157 +++ b/arch/frv/mm/elf-fdpic.c
3158 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 {
3160 struct vm_area_struct *vma;
3161 unsigned long limit;
3162 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3163
3164 if (len > TASK_SIZE)
3165 return -ENOMEM;
3166 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3167 if (addr) {
3168 addr = PAGE_ALIGN(addr);
3169 vma = find_vma(current->mm, addr);
3170 - if (TASK_SIZE - len >= addr &&
3171 - (!vma || addr + len <= vma->vm_start))
3172 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3173 goto success;
3174 }
3175
3176 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3177 for (; vma; vma = vma->vm_next) {
3178 if (addr > limit)
3179 break;
3180 - if (addr + len <= vma->vm_start)
3181 + if (check_heap_stack_gap(vma, addr, len, offset))
3182 goto success;
3183 addr = vma->vm_end;
3184 }
3185 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3186 for (; vma; vma = vma->vm_next) {
3187 if (addr > limit)
3188 break;
3189 - if (addr + len <= vma->vm_start)
3190 + if (check_heap_stack_gap(vma, addr, len, offset))
3191 goto success;
3192 addr = vma->vm_end;
3193 }
3194 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3195 index f4ca594..adc72fd6 100644
3196 --- a/arch/hexagon/include/asm/cache.h
3197 +++ b/arch/hexagon/include/asm/cache.h
3198 @@ -21,9 +21,11 @@
3199 #ifndef __ASM_CACHE_H
3200 #define __ASM_CACHE_H
3201
3202 +#include <linux/const.h>
3203 +
3204 /* Bytes per L1 cache line */
3205 -#define L1_CACHE_SHIFT (5)
3206 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3207 +#define L1_CACHE_SHIFT 5
3208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3209
3210 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3211 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3212 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3213 index 6e6fe18..a6ae668 100644
3214 --- a/arch/ia64/include/asm/atomic.h
3215 +++ b/arch/ia64/include/asm/atomic.h
3216 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3217 #define atomic64_inc(v) atomic64_add(1, (v))
3218 #define atomic64_dec(v) atomic64_sub(1, (v))
3219
3220 +#define atomic64_read_unchecked(v) atomic64_read(v)
3221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3229 +
3230 /* Atomic operations are already serializing */
3231 #define smp_mb__before_atomic_dec() barrier()
3232 #define smp_mb__after_atomic_dec() barrier()
3233 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3234 index 988254a..e1ee885 100644
3235 --- a/arch/ia64/include/asm/cache.h
3236 +++ b/arch/ia64/include/asm/cache.h
3237 @@ -1,6 +1,7 @@
3238 #ifndef _ASM_IA64_CACHE_H
3239 #define _ASM_IA64_CACHE_H
3240
3241 +#include <linux/const.h>
3242
3243 /*
3244 * Copyright (C) 1998-2000 Hewlett-Packard Co
3245 @@ -9,7 +10,7 @@
3246
3247 /* Bytes per L1 (data) cache line. */
3248 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3249 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3250 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3251
3252 #ifdef CONFIG_SMP
3253 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3254 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3255 index b5298eb..67c6e62 100644
3256 --- a/arch/ia64/include/asm/elf.h
3257 +++ b/arch/ia64/include/asm/elf.h
3258 @@ -42,6 +42,13 @@
3259 */
3260 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3261
3262 +#ifdef CONFIG_PAX_ASLR
3263 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3264 +
3265 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3266 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3267 +#endif
3268 +
3269 #define PT_IA_64_UNWIND 0x70000001
3270
3271 /* IA-64 relocations: */
3272 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3273 index 96a8d92..617a1cf 100644
3274 --- a/arch/ia64/include/asm/pgalloc.h
3275 +++ b/arch/ia64/include/asm/pgalloc.h
3276 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3277 pgd_val(*pgd_entry) = __pa(pud);
3278 }
3279
3280 +static inline void
3281 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3282 +{
3283 + pgd_populate(mm, pgd_entry, pud);
3284 +}
3285 +
3286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3287 {
3288 return quicklist_alloc(0, GFP_KERNEL, NULL);
3289 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3290 pud_val(*pud_entry) = __pa(pmd);
3291 }
3292
3293 +static inline void
3294 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3295 +{
3296 + pud_populate(mm, pud_entry, pmd);
3297 +}
3298 +
3299 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3300 {
3301 return quicklist_alloc(0, GFP_KERNEL, NULL);
3302 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3303 index 815810c..d60bd4c 100644
3304 --- a/arch/ia64/include/asm/pgtable.h
3305 +++ b/arch/ia64/include/asm/pgtable.h
3306 @@ -12,7 +12,7 @@
3307 * David Mosberger-Tang <davidm@hpl.hp.com>
3308 */
3309
3310 -
3311 +#include <linux/const.h>
3312 #include <asm/mman.h>
3313 #include <asm/page.h>
3314 #include <asm/processor.h>
3315 @@ -142,6 +142,17 @@
3316 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3317 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3318 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3319 +
3320 +#ifdef CONFIG_PAX_PAGEEXEC
3321 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3322 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3323 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3324 +#else
3325 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3326 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3327 +# define PAGE_COPY_NOEXEC PAGE_COPY
3328 +#endif
3329 +
3330 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3331 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3332 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3333 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3334 index 54ff557..70c88b7 100644
3335 --- a/arch/ia64/include/asm/spinlock.h
3336 +++ b/arch/ia64/include/asm/spinlock.h
3337 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3338 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3339
3340 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3341 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3342 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3343 }
3344
3345 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3346 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3347 index 449c8c0..50cdf87 100644
3348 --- a/arch/ia64/include/asm/uaccess.h
3349 +++ b/arch/ia64/include/asm/uaccess.h
3350 @@ -42,6 +42,8 @@
3351 #include <asm/pgtable.h>
3352 #include <asm/io.h>
3353
3354 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3355 +
3356 /*
3357 * For historical reasons, the following macros are grossly misnamed:
3358 */
3359 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3360 static inline unsigned long
3361 __copy_to_user (void __user *to, const void *from, unsigned long count)
3362 {
3363 + if (count > INT_MAX)
3364 + return count;
3365 +
3366 + if (!__builtin_constant_p(count))
3367 + check_object_size(from, count, true);
3368 +
3369 return __copy_user(to, (__force void __user *) from, count);
3370 }
3371
3372 static inline unsigned long
3373 __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 {
3375 + if (count > INT_MAX)
3376 + return count;
3377 +
3378 + if (!__builtin_constant_p(count))
3379 + check_object_size(to, count, false);
3380 +
3381 return __copy_user((__force void __user *) to, from, count);
3382 }
3383
3384 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3385 ({ \
3386 void __user *__cu_to = (to); \
3387 const void *__cu_from = (from); \
3388 - long __cu_len = (n); \
3389 + unsigned long __cu_len = (n); \
3390 \
3391 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3392 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3393 + if (!__builtin_constant_p(n)) \
3394 + check_object_size(__cu_from, __cu_len, true); \
3395 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3396 + } \
3397 __cu_len; \
3398 })
3399
3400 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3401 ({ \
3402 void *__cu_to = (to); \
3403 const void __user *__cu_from = (from); \
3404 - long __cu_len = (n); \
3405 + unsigned long __cu_len = (n); \
3406 \
3407 __chk_user_ptr(__cu_from); \
3408 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3409 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3410 + if (!__builtin_constant_p(n)) \
3411 + check_object_size(__cu_to, __cu_len, false); \
3412 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3413 + } \
3414 __cu_len; \
3415 })
3416
3417 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3418 index 24603be..948052d 100644
3419 --- a/arch/ia64/kernel/module.c
3420 +++ b/arch/ia64/kernel/module.c
3421 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3422 void
3423 module_free (struct module *mod, void *module_region)
3424 {
3425 - if (mod && mod->arch.init_unw_table &&
3426 - module_region == mod->module_init) {
3427 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3428 unw_remove_unwind_table(mod->arch.init_unw_table);
3429 mod->arch.init_unw_table = NULL;
3430 }
3431 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3432 }
3433
3434 static inline int
3435 +in_init_rx (const struct module *mod, uint64_t addr)
3436 +{
3437 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3438 +}
3439 +
3440 +static inline int
3441 +in_init_rw (const struct module *mod, uint64_t addr)
3442 +{
3443 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3444 +}
3445 +
3446 +static inline int
3447 in_init (const struct module *mod, uint64_t addr)
3448 {
3449 - return addr - (uint64_t) mod->module_init < mod->init_size;
3450 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3451 +}
3452 +
3453 +static inline int
3454 +in_core_rx (const struct module *mod, uint64_t addr)
3455 +{
3456 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3457 +}
3458 +
3459 +static inline int
3460 +in_core_rw (const struct module *mod, uint64_t addr)
3461 +{
3462 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3463 }
3464
3465 static inline int
3466 in_core (const struct module *mod, uint64_t addr)
3467 {
3468 - return addr - (uint64_t) mod->module_core < mod->core_size;
3469 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3470 }
3471
3472 static inline int
3473 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3474 break;
3475
3476 case RV_BDREL:
3477 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3478 + if (in_init_rx(mod, val))
3479 + val -= (uint64_t) mod->module_init_rx;
3480 + else if (in_init_rw(mod, val))
3481 + val -= (uint64_t) mod->module_init_rw;
3482 + else if (in_core_rx(mod, val))
3483 + val -= (uint64_t) mod->module_core_rx;
3484 + else if (in_core_rw(mod, val))
3485 + val -= (uint64_t) mod->module_core_rw;
3486 break;
3487
3488 case RV_LTV:
3489 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3490 * addresses have been selected...
3491 */
3492 uint64_t gp;
3493 - if (mod->core_size > MAX_LTOFF)
3494 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3495 /*
3496 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3497 * at the end of the module.
3498 */
3499 - gp = mod->core_size - MAX_LTOFF / 2;
3500 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3501 else
3502 - gp = mod->core_size / 2;
3503 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3504 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3505 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3506 mod->arch.gp = gp;
3507 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3508 }
3509 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3510 index d9439ef..d0cac6b 100644
3511 --- a/arch/ia64/kernel/sys_ia64.c
3512 +++ b/arch/ia64/kernel/sys_ia64.c
3513 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3514 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3515 struct mm_struct *mm = current->mm;
3516 struct vm_area_struct *vma;
3517 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3518
3519 if (len > RGN_MAP_LIMIT)
3520 return -ENOMEM;
3521 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3522 if (REGION_NUMBER(addr) == RGN_HPAGE)
3523 addr = 0;
3524 #endif
3525 +
3526 +#ifdef CONFIG_PAX_RANDMMAP
3527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3528 + addr = mm->free_area_cache;
3529 + else
3530 +#endif
3531 +
3532 if (!addr)
3533 addr = mm->free_area_cache;
3534
3535 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3536 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3537 /* At this point: (!vma || addr < vma->vm_end). */
3538 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3539 - if (start_addr != TASK_UNMAPPED_BASE) {
3540 + if (start_addr != mm->mmap_base) {
3541 /* Start a new search --- just in case we missed some holes. */
3542 - addr = TASK_UNMAPPED_BASE;
3543 + addr = mm->mmap_base;
3544 goto full_search;
3545 }
3546 return -ENOMEM;
3547 }
3548 - if (!vma || addr + len <= vma->vm_start) {
3549 + if (check_heap_stack_gap(vma, addr, len, offset)) {
3550 /* Remember the address where we stopped this search: */
3551 mm->free_area_cache = addr + len;
3552 return addr;
3553 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3554 index c64460b..4d250a6 100644
3555 --- a/arch/ia64/kernel/topology.c
3556 +++ b/arch/ia64/kernel/topology.c
3557 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3558 return NOTIFY_OK;
3559 }
3560
3561 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
3562 +static struct notifier_block cache_cpu_notifier =
3563 {
3564 .notifier_call = cache_cpu_callback
3565 };
3566 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3567 index 0ccb28f..8992469 100644
3568 --- a/arch/ia64/kernel/vmlinux.lds.S
3569 +++ b/arch/ia64/kernel/vmlinux.lds.S
3570 @@ -198,7 +198,7 @@ SECTIONS {
3571 /* Per-cpu data: */
3572 . = ALIGN(PERCPU_PAGE_SIZE);
3573 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3574 - __phys_per_cpu_start = __per_cpu_load;
3575 + __phys_per_cpu_start = per_cpu_load;
3576 /*
3577 * ensure percpu data fits
3578 * into percpu page size
3579 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3580 index 6cf0341..d352594 100644
3581 --- a/arch/ia64/mm/fault.c
3582 +++ b/arch/ia64/mm/fault.c
3583 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3584 return pte_present(pte);
3585 }
3586
3587 +#ifdef CONFIG_PAX_PAGEEXEC
3588 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3589 +{
3590 + unsigned long i;
3591 +
3592 + printk(KERN_ERR "PAX: bytes at PC: ");
3593 + for (i = 0; i < 8; i++) {
3594 + unsigned int c;
3595 + if (get_user(c, (unsigned int *)pc+i))
3596 + printk(KERN_CONT "???????? ");
3597 + else
3598 + printk(KERN_CONT "%08x ", c);
3599 + }
3600 + printk("\n");
3601 +}
3602 +#endif
3603 +
3604 # define VM_READ_BIT 0
3605 # define VM_WRITE_BIT 1
3606 # define VM_EXEC_BIT 2
3607 @@ -149,8 +166,21 @@ retry:
3608 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3609 goto bad_area;
3610
3611 - if ((vma->vm_flags & mask) != mask)
3612 + if ((vma->vm_flags & mask) != mask) {
3613 +
3614 +#ifdef CONFIG_PAX_PAGEEXEC
3615 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3616 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3617 + goto bad_area;
3618 +
3619 + up_read(&mm->mmap_sem);
3620 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3621 + do_group_exit(SIGKILL);
3622 + }
3623 +#endif
3624 +
3625 goto bad_area;
3626 + }
3627
3628 /*
3629 * If for any reason at all we couldn't handle the fault, make
3630 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3631 index 5ca674b..127c3cb 100644
3632 --- a/arch/ia64/mm/hugetlbpage.c
3633 +++ b/arch/ia64/mm/hugetlbpage.c
3634 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3635 unsigned long pgoff, unsigned long flags)
3636 {
3637 struct vm_area_struct *vmm;
3638 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3639
3640 if (len > RGN_MAP_LIMIT)
3641 return -ENOMEM;
3642 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3643 /* At this point: (!vmm || addr < vmm->vm_end). */
3644 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3645 return -ENOMEM;
3646 - if (!vmm || (addr + len) <= vmm->vm_start)
3647 + if (check_heap_stack_gap(vmm, addr, len, offset))
3648 return addr;
3649 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3650 }
3651 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3652 index 082e383..fb7be80 100644
3653 --- a/arch/ia64/mm/init.c
3654 +++ b/arch/ia64/mm/init.c
3655 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3656 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3657 vma->vm_end = vma->vm_start + PAGE_SIZE;
3658 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3659 +
3660 +#ifdef CONFIG_PAX_PAGEEXEC
3661 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3662 + vma->vm_flags &= ~VM_EXEC;
3663 +
3664 +#ifdef CONFIG_PAX_MPROTECT
3665 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3666 + vma->vm_flags &= ~VM_MAYEXEC;
3667 +#endif
3668 +
3669 + }
3670 +#endif
3671 +
3672 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3673 down_write(&current->mm->mmap_sem);
3674 if (insert_vm_struct(current->mm, vma)) {
3675 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3676 index 40b3ee9..8c2c112 100644
3677 --- a/arch/m32r/include/asm/cache.h
3678 +++ b/arch/m32r/include/asm/cache.h
3679 @@ -1,8 +1,10 @@
3680 #ifndef _ASM_M32R_CACHE_H
3681 #define _ASM_M32R_CACHE_H
3682
3683 +#include <linux/const.h>
3684 +
3685 /* L1 cache line size */
3686 #define L1_CACHE_SHIFT 4
3687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3689
3690 #endif /* _ASM_M32R_CACHE_H */
3691 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3692 index 82abd15..d95ae5d 100644
3693 --- a/arch/m32r/lib/usercopy.c
3694 +++ b/arch/m32r/lib/usercopy.c
3695 @@ -14,6 +14,9 @@
3696 unsigned long
3697 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3698 {
3699 + if ((long)n < 0)
3700 + return n;
3701 +
3702 prefetch(from);
3703 if (access_ok(VERIFY_WRITE, to, n))
3704 __copy_user(to,from,n);
3705 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3706 unsigned long
3707 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3708 {
3709 + if ((long)n < 0)
3710 + return n;
3711 +
3712 prefetchw(to);
3713 if (access_ok(VERIFY_READ, from, n))
3714 __copy_user_zeroing(to,from,n);
3715 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3716 index 0395c51..5f26031 100644
3717 --- a/arch/m68k/include/asm/cache.h
3718 +++ b/arch/m68k/include/asm/cache.h
3719 @@ -4,9 +4,11 @@
3720 #ifndef __ARCH_M68K_CACHE_H
3721 #define __ARCH_M68K_CACHE_H
3722
3723 +#include <linux/const.h>
3724 +
3725 /* bytes per L1 cache line */
3726 #define L1_CACHE_SHIFT 4
3727 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3729
3730 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3731
3732 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3733 index 4efe96a..60e8699 100644
3734 --- a/arch/microblaze/include/asm/cache.h
3735 +++ b/arch/microblaze/include/asm/cache.h
3736 @@ -13,11 +13,12 @@
3737 #ifndef _ASM_MICROBLAZE_CACHE_H
3738 #define _ASM_MICROBLAZE_CACHE_H
3739
3740 +#include <linux/const.h>
3741 #include <asm/registers.h>
3742
3743 #define L1_CACHE_SHIFT 5
3744 /* word-granular cache in microblaze */
3745 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3751 index 01cc6ba..bcb7a5d 100644
3752 --- a/arch/mips/include/asm/atomic.h
3753 +++ b/arch/mips/include/asm/atomic.h
3754 @@ -21,6 +21,10 @@
3755 #include <asm/cmpxchg.h>
3756 #include <asm/war.h>
3757
3758 +#ifdef CONFIG_GENERIC_ATOMIC64
3759 +#include <asm-generic/atomic64.h>
3760 +#endif
3761 +
3762 #define ATOMIC_INIT(i) { (i) }
3763
3764 /*
3765 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3766 */
3767 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3768
3769 +#define atomic64_read_unchecked(v) atomic64_read(v)
3770 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3771 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3772 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3773 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3774 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3775 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3776 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3777 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3778 +
3779 #endif /* CONFIG_64BIT */
3780
3781 /*
3782 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3783 index b4db69f..8f3b093 100644
3784 --- a/arch/mips/include/asm/cache.h
3785 +++ b/arch/mips/include/asm/cache.h
3786 @@ -9,10 +9,11 @@
3787 #ifndef _ASM_CACHE_H
3788 #define _ASM_CACHE_H
3789
3790 +#include <linux/const.h>
3791 #include <kmalloc.h>
3792
3793 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3794 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3795 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3796
3797 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3799 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3800 index 455c0ac..ad65fbe 100644
3801 --- a/arch/mips/include/asm/elf.h
3802 +++ b/arch/mips/include/asm/elf.h
3803 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3804 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3805 #endif
3806
3807 +#ifdef CONFIG_PAX_ASLR
3808 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3809 +
3810 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3811 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3812 +#endif
3813 +
3814 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3815 struct linux_binprm;
3816 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3817 int uses_interp);
3818
3819 -struct mm_struct;
3820 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3821 -#define arch_randomize_brk arch_randomize_brk
3822 -
3823 #endif /* _ASM_ELF_H */
3824 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3825 index c1f6afa..38cc6e9 100644
3826 --- a/arch/mips/include/asm/exec.h
3827 +++ b/arch/mips/include/asm/exec.h
3828 @@ -12,6 +12,6 @@
3829 #ifndef _ASM_EXEC_H
3830 #define _ASM_EXEC_H
3831
3832 -extern unsigned long arch_align_stack(unsigned long sp);
3833 +#define arch_align_stack(x) ((x) & ~0xfUL)
3834
3835 #endif /* _ASM_EXEC_H */
3836 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3837 index da9bd7d..91aa7ab 100644
3838 --- a/arch/mips/include/asm/page.h
3839 +++ b/arch/mips/include/asm/page.h
3840 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3841 #ifdef CONFIG_CPU_MIPS32
3842 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3843 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3844 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3845 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3846 #else
3847 typedef struct { unsigned long long pte; } pte_t;
3848 #define pte_val(x) ((x).pte)
3849 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3850 index 881d18b..cea38bc 100644
3851 --- a/arch/mips/include/asm/pgalloc.h
3852 +++ b/arch/mips/include/asm/pgalloc.h
3853 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3854 {
3855 set_pud(pud, __pud((unsigned long)pmd));
3856 }
3857 +
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 #endif
3863
3864 /*
3865 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3866 index 18806a5..141ffcf 100644
3867 --- a/arch/mips/include/asm/thread_info.h
3868 +++ b/arch/mips/include/asm/thread_info.h
3869 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3870 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3871 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3872 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3873 +/* li takes a 32bit immediate */
3874 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3875 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3876
3877 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3878 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3879 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3880 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3881 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3882 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3883 +
3884 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3885
3886 /* work to do in syscall_trace_leave() */
3887 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3888 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3889
3890 /* work to do on interrupt/exception return */
3891 #define _TIF_WORK_MASK \
3892 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3893 /* work to do on any return to u-space */
3894 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3895 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3896
3897 #endif /* __KERNEL__ */
3898
3899 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3900 index 9fdd8bc..4bd7f1a 100644
3901 --- a/arch/mips/kernel/binfmt_elfn32.c
3902 +++ b/arch/mips/kernel/binfmt_elfn32.c
3903 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3904 #undef ELF_ET_DYN_BASE
3905 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3906
3907 +#ifdef CONFIG_PAX_ASLR
3908 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3909 +
3910 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3911 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3912 +#endif
3913 +
3914 #include <asm/processor.h>
3915 #include <linux/module.h>
3916 #include <linux/elfcore.h>
3917 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3918 index ff44823..97f8906 100644
3919 --- a/arch/mips/kernel/binfmt_elfo32.c
3920 +++ b/arch/mips/kernel/binfmt_elfo32.c
3921 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3922 #undef ELF_ET_DYN_BASE
3923 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3924
3925 +#ifdef CONFIG_PAX_ASLR
3926 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3927 +
3928 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3929 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3930 +#endif
3931 +
3932 #include <asm/processor.h>
3933
3934 /*
3935 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3936 index 69b17a9..9db82f9 100644
3937 --- a/arch/mips/kernel/process.c
3938 +++ b/arch/mips/kernel/process.c
3939 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3940 out:
3941 return pc;
3942 }
3943 -
3944 -/*
3945 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3946 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3947 - */
3948 -unsigned long arch_align_stack(unsigned long sp)
3949 -{
3950 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3951 - sp -= get_random_int() & ~PAGE_MASK;
3952 -
3953 - return sp & ALMASK;
3954 -}
3955 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3956 index 4812c6d..2069554 100644
3957 --- a/arch/mips/kernel/ptrace.c
3958 +++ b/arch/mips/kernel/ptrace.c
3959 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3960 return arch;
3961 }
3962
3963 +#ifdef CONFIG_GRKERNSEC_SETXID
3964 +extern void gr_delayed_cred_worker(void);
3965 +#endif
3966 +
3967 /*
3968 * Notification of system call entry/exit
3969 * - triggered by current->work.syscall_trace
3970 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3971 /* do the secure computing check first */
3972 secure_computing_strict(regs->regs[2]);
3973
3974 +#ifdef CONFIG_GRKERNSEC_SETXID
3975 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3976 + gr_delayed_cred_worker();
3977 +#endif
3978 +
3979 if (!(current->ptrace & PT_PTRACED))
3980 goto out;
3981
3982 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3983 index 374f66e..1c882a0 100644
3984 --- a/arch/mips/kernel/scall32-o32.S
3985 +++ b/arch/mips/kernel/scall32-o32.S
3986 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3987
3988 stack_done:
3989 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3990 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3991 + li t1, _TIF_SYSCALL_WORK
3992 and t0, t1
3993 bnez t0, syscall_trace_entry # -> yes
3994
3995 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3996 index 169de6a..f594a89 100644
3997 --- a/arch/mips/kernel/scall64-64.S
3998 +++ b/arch/mips/kernel/scall64-64.S
3999 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
4000
4001 sd a3, PT_R26(sp) # save a3 for syscall restarting
4002
4003 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4004 + li t1, _TIF_SYSCALL_WORK
4005 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4006 and t0, t1, t0
4007 bnez t0, syscall_trace_entry
4008 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
4009 index 86ec03f..1235baf 100644
4010 --- a/arch/mips/kernel/scall64-n32.S
4011 +++ b/arch/mips/kernel/scall64-n32.S
4012 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
4013
4014 sd a3, PT_R26(sp) # save a3 for syscall restarting
4015
4016 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4017 + li t1, _TIF_SYSCALL_WORK
4018 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4019 and t0, t1, t0
4020 bnez t0, n32_syscall_trace_entry
4021 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
4022 index 53c2d72..3734584 100644
4023 --- a/arch/mips/kernel/scall64-o32.S
4024 +++ b/arch/mips/kernel/scall64-o32.S
4025 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
4026 PTR 4b, bad_stack
4027 .previous
4028
4029 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4030 + li t1, _TIF_SYSCALL_WORK
4031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4032 and t0, t1, t0
4033 bnez t0, trace_a_syscall
4034 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4035 index ddcec1e..c7f983e 100644
4036 --- a/arch/mips/mm/fault.c
4037 +++ b/arch/mips/mm/fault.c
4038 @@ -27,6 +27,23 @@
4039 #include <asm/highmem.h> /* For VMALLOC_END */
4040 #include <linux/kdebug.h>
4041
4042 +#ifdef CONFIG_PAX_PAGEEXEC
4043 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4044 +{
4045 + unsigned long i;
4046 +
4047 + printk(KERN_ERR "PAX: bytes at PC: ");
4048 + for (i = 0; i < 5; i++) {
4049 + unsigned int c;
4050 + if (get_user(c, (unsigned int *)pc+i))
4051 + printk(KERN_CONT "???????? ");
4052 + else
4053 + printk(KERN_CONT "%08x ", c);
4054 + }
4055 + printk("\n");
4056 +}
4057 +#endif
4058 +
4059 /*
4060 * This routine handles page faults. It determines the address,
4061 * and the problem, and then passes it off to one of the appropriate
4062 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4063 index 302d779..6459dc0 100644
4064 --- a/arch/mips/mm/mmap.c
4065 +++ b/arch/mips/mm/mmap.c
4066 @@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4067 struct vm_area_struct *vma;
4068 unsigned long addr = addr0;
4069 int do_color_align;
4070 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071
4072 if (unlikely(len > TASK_SIZE))
4073 return -ENOMEM;
4074 @@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4075 do_color_align = 1;
4076
4077 /* requesting a specific address */
4078 +
4079 +#ifdef CONFIG_PAX_RANDMMAP
4080 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4081 +#endif
4082 +
4083 if (addr) {
4084 if (do_color_align)
4085 addr = COLOUR_ALIGN(addr, pgoff);
4086 @@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4087 addr = PAGE_ALIGN(addr);
4088
4089 vma = find_vma(mm, addr);
4090 - if (TASK_SIZE - len >= addr &&
4091 - (!vma || addr + len <= vma->vm_start))
4092 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4093 return addr;
4094 }
4095
4096 @@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4097 /* At this point: (!vma || addr < vma->vm_end). */
4098 if (TASK_SIZE - len < addr)
4099 return -ENOMEM;
4100 - if (!vma || addr + len <= vma->vm_start)
4101 + if (check_heap_stack_gap(vmm, addr, len, offset))
4102 return addr;
4103 addr = vma->vm_end;
4104 if (do_color_align)
4105 @@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4106 /* make sure it can fit in the remaining address space */
4107 if (likely(addr > len)) {
4108 vma = find_vma(mm, addr - len);
4109 - if (!vma || addr <= vma->vm_start) {
4110 + if (check_heap_stack_gap(vmm, addr - len, len, offset))
4111 /* cache the address as a hint for next time */
4112 return mm->free_area_cache = addr - len;
4113 }
4114 @@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4115 goto bottomup;
4116
4117 addr = mm->mmap_base - len;
4118 - if (do_color_align)
4119 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4120
4121 do {
4122 + if (do_color_align)
4123 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4124 /*
4125 * Lookup failure means no vma is above this address,
4126 * else if new region fits below vma->vm_start,
4127 * return with success:
4128 */
4129 vma = find_vma(mm, addr);
4130 - if (likely(!vma || addr + len <= vma->vm_start)) {
4131 + if (check_heap_stack_gap(vmm, addr, len, offset)) {
4132 /* cache the address as a hint for next time */
4133 return mm->free_area_cache = addr;
4134 }
4135 @@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4136 mm->cached_hole_size = vma->vm_start - addr;
4137
4138 /* try just below the current vma->vm_start */
4139 - addr = vma->vm_start - len;
4140 - if (do_color_align)
4141 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4142 - } while (likely(len < vma->vm_start));
4143 + addr = skip_heap_stack_gap(vma, len, offset);
4144 + } while (!IS_ERR_VALUE(addr));
4145
4146 bottomup:
4147 /*
4148 @@ -223,6 +226,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149 {
4150 unsigned long random_factor = 0UL;
4151
4152 +#ifdef CONFIG_PAX_RANDMMAP
4153 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4154 +#endif
4155 +
4156 if (current->flags & PF_RANDOMIZE) {
4157 random_factor = get_random_int();
4158 random_factor = random_factor << PAGE_SHIFT;
4159 @@ -234,38 +241,23 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4160
4161 if (mmap_is_legacy()) {
4162 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4163 +
4164 +#ifdef CONFIG_PAX_RANDMMAP
4165 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4166 + mm->mmap_base += mm->delta_mmap;
4167 +#endif
4168 +
4169 mm->get_unmapped_area = arch_get_unmapped_area;
4170 mm->unmap_area = arch_unmap_area;
4171 } else {
4172 mm->mmap_base = mmap_base(random_factor);
4173 +
4174 +#ifdef CONFIG_PAX_RANDMMAP
4175 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4176 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4177 +#endif
4178 +
4179 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4180 mm->unmap_area = arch_unmap_area_topdown;
4181 }
4182 }
4183 -
4184 -static inline unsigned long brk_rnd(void)
4185 -{
4186 - unsigned long rnd = get_random_int();
4187 -
4188 - rnd = rnd << PAGE_SHIFT;
4189 - /* 8MB for 32bit, 256MB for 64bit */
4190 - if (TASK_IS_32BIT_ADDR)
4191 - rnd = rnd & 0x7ffffful;
4192 - else
4193 - rnd = rnd & 0xffffffful;
4194 -
4195 - return rnd;
4196 -}
4197 -
4198 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4199 -{
4200 - unsigned long base = mm->brk;
4201 - unsigned long ret;
4202 -
4203 - ret = PAGE_ALIGN(base + brk_rnd());
4204 -
4205 - if (ret < mm->brk)
4206 - return mm->brk;
4207 -
4208 - return ret;
4209 -}
4210 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4211 index 967d144..db12197 100644
4212 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4213 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4214 @@ -11,12 +11,14 @@
4215 #ifndef _ASM_PROC_CACHE_H
4216 #define _ASM_PROC_CACHE_H
4217
4218 +#include <linux/const.h>
4219 +
4220 /* L1 cache */
4221
4222 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4223 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4224 -#define L1_CACHE_BYTES 16 /* bytes per entry */
4225 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4226 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4227 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4228
4229 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4230 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4231 index bcb5df2..84fabd2 100644
4232 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4233 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4234 @@ -16,13 +16,15 @@
4235 #ifndef _ASM_PROC_CACHE_H
4236 #define _ASM_PROC_CACHE_H
4237
4238 +#include <linux/const.h>
4239 +
4240 /*
4241 * L1 cache
4242 */
4243 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4244 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4245 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4246 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4247 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4248 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4249
4250 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4251 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4252 index 4ce7a01..449202a 100644
4253 --- a/arch/openrisc/include/asm/cache.h
4254 +++ b/arch/openrisc/include/asm/cache.h
4255 @@ -19,11 +19,13 @@
4256 #ifndef __ASM_OPENRISC_CACHE_H
4257 #define __ASM_OPENRISC_CACHE_H
4258
4259 +#include <linux/const.h>
4260 +
4261 /* FIXME: How can we replace these with values from the CPU...
4262 * they shouldn't be hard-coded!
4263 */
4264
4265 -#define L1_CACHE_BYTES 16
4266 #define L1_CACHE_SHIFT 4
4267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4268
4269 #endif /* __ASM_OPENRISC_CACHE_H */
4270 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4271 index af9cf30..2aae9b2 100644
4272 --- a/arch/parisc/include/asm/atomic.h
4273 +++ b/arch/parisc/include/asm/atomic.h
4274 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4275
4276 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4277
4278 +#define atomic64_read_unchecked(v) atomic64_read(v)
4279 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4280 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4281 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4282 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4283 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4284 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4285 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4286 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4287 +
4288 #endif /* !CONFIG_64BIT */
4289
4290
4291 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4292 index 47f11c7..3420df2 100644
4293 --- a/arch/parisc/include/asm/cache.h
4294 +++ b/arch/parisc/include/asm/cache.h
4295 @@ -5,6 +5,7 @@
4296 #ifndef __ARCH_PARISC_CACHE_H
4297 #define __ARCH_PARISC_CACHE_H
4298
4299 +#include <linux/const.h>
4300
4301 /*
4302 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4303 @@ -15,13 +16,13 @@
4304 * just ruin performance.
4305 */
4306 #ifdef CONFIG_PA20
4307 -#define L1_CACHE_BYTES 64
4308 #define L1_CACHE_SHIFT 6
4309 #else
4310 -#define L1_CACHE_BYTES 32
4311 #define L1_CACHE_SHIFT 5
4312 #endif
4313
4314 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4315 +
4316 #ifndef __ASSEMBLY__
4317
4318 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4319 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4320 index 19f6cb1..6c78cf2 100644
4321 --- a/arch/parisc/include/asm/elf.h
4322 +++ b/arch/parisc/include/asm/elf.h
4323 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4324
4325 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4326
4327 +#ifdef CONFIG_PAX_ASLR
4328 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4329 +
4330 +#define PAX_DELTA_MMAP_LEN 16
4331 +#define PAX_DELTA_STACK_LEN 16
4332 +#endif
4333 +
4334 /* This yields a mask that user programs can use to figure out what
4335 instruction set this CPU supports. This could be done in user space,
4336 but it's not easy, and we've already done it here. */
4337 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4338 index fc987a1..6e068ef 100644
4339 --- a/arch/parisc/include/asm/pgalloc.h
4340 +++ b/arch/parisc/include/asm/pgalloc.h
4341 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4342 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4343 }
4344
4345 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4346 +{
4347 + pgd_populate(mm, pgd, pmd);
4348 +}
4349 +
4350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4351 {
4352 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4353 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4354 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4355 #define pmd_free(mm, x) do { } while (0)
4356 #define pgd_populate(mm, pmd, pte) BUG()
4357 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4358
4359 #endif
4360
4361 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4362 index ee99f23..802b0a1 100644
4363 --- a/arch/parisc/include/asm/pgtable.h
4364 +++ b/arch/parisc/include/asm/pgtable.h
4365 @@ -212,6 +212,17 @@ struct vm_area_struct;
4366 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4367 #define PAGE_COPY PAGE_EXECREAD
4368 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4369 +
4370 +#ifdef CONFIG_PAX_PAGEEXEC
4371 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4372 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4373 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4374 +#else
4375 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4376 +# define PAGE_COPY_NOEXEC PAGE_COPY
4377 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4378 +#endif
4379 +
4380 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4381 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4382 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4383 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4384 index 4ba2c93..f5e3974 100644
4385 --- a/arch/parisc/include/asm/uaccess.h
4386 +++ b/arch/parisc/include/asm/uaccess.h
4387 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4388 const void __user *from,
4389 unsigned long n)
4390 {
4391 - int sz = __compiletime_object_size(to);
4392 + size_t sz = __compiletime_object_size(to);
4393 int ret = -EFAULT;
4394
4395 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4396 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4397 ret = __copy_from_user(to, from, n);
4398 else
4399 copy_from_user_overflow();
4400 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4401 index 5e34ccf..672bc9c 100644
4402 --- a/arch/parisc/kernel/module.c
4403 +++ b/arch/parisc/kernel/module.c
4404 @@ -98,16 +98,38 @@
4405
4406 /* three functions to determine where in the module core
4407 * or init pieces the location is */
4408 +static inline int in_init_rx(struct module *me, void *loc)
4409 +{
4410 + return (loc >= me->module_init_rx &&
4411 + loc < (me->module_init_rx + me->init_size_rx));
4412 +}
4413 +
4414 +static inline int in_init_rw(struct module *me, void *loc)
4415 +{
4416 + return (loc >= me->module_init_rw &&
4417 + loc < (me->module_init_rw + me->init_size_rw));
4418 +}
4419 +
4420 static inline int in_init(struct module *me, void *loc)
4421 {
4422 - return (loc >= me->module_init &&
4423 - loc <= (me->module_init + me->init_size));
4424 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4425 +}
4426 +
4427 +static inline int in_core_rx(struct module *me, void *loc)
4428 +{
4429 + return (loc >= me->module_core_rx &&
4430 + loc < (me->module_core_rx + me->core_size_rx));
4431 +}
4432 +
4433 +static inline int in_core_rw(struct module *me, void *loc)
4434 +{
4435 + return (loc >= me->module_core_rw &&
4436 + loc < (me->module_core_rw + me->core_size_rw));
4437 }
4438
4439 static inline int in_core(struct module *me, void *loc)
4440 {
4441 - return (loc >= me->module_core &&
4442 - loc <= (me->module_core + me->core_size));
4443 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4444 }
4445
4446 static inline int in_local(struct module *me, void *loc)
4447 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4448 }
4449
4450 /* align things a bit */
4451 - me->core_size = ALIGN(me->core_size, 16);
4452 - me->arch.got_offset = me->core_size;
4453 - me->core_size += gots * sizeof(struct got_entry);
4454 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4455 + me->arch.got_offset = me->core_size_rw;
4456 + me->core_size_rw += gots * sizeof(struct got_entry);
4457
4458 - me->core_size = ALIGN(me->core_size, 16);
4459 - me->arch.fdesc_offset = me->core_size;
4460 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4461 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4462 + me->arch.fdesc_offset = me->core_size_rw;
4463 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4464
4465 me->arch.got_max = gots;
4466 me->arch.fdesc_max = fdescs;
4467 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4468
4469 BUG_ON(value == 0);
4470
4471 - got = me->module_core + me->arch.got_offset;
4472 + got = me->module_core_rw + me->arch.got_offset;
4473 for (i = 0; got[i].addr; i++)
4474 if (got[i].addr == value)
4475 goto out;
4476 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4477 #ifdef CONFIG_64BIT
4478 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4479 {
4480 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4481 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4482
4483 if (!value) {
4484 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4485 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4486
4487 /* Create new one */
4488 fdesc->addr = value;
4489 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4490 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4491 return (Elf_Addr)fdesc;
4492 }
4493 #endif /* CONFIG_64BIT */
4494 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4495
4496 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4497 end = table + sechdrs[me->arch.unwind_section].sh_size;
4498 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4499 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4500
4501 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4502 me->arch.unwind_section, table, end, gp);
4503 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4504 index f76c108..92bad82 100644
4505 --- a/arch/parisc/kernel/sys_parisc.c
4506 +++ b/arch/parisc/kernel/sys_parisc.c
4507 @@ -33,9 +33,11 @@
4508 #include <linux/utsname.h>
4509 #include <linux/personality.h>
4510
4511 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4512 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4513 + unsigned long flags)
4514 {
4515 struct vm_area_struct *vma;
4516 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4517
4518 addr = PAGE_ALIGN(addr);
4519
4520 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4521 /* At this point: (!vma || addr < vma->vm_end). */
4522 if (TASK_SIZE - len < addr)
4523 return -ENOMEM;
4524 - if (!vma || addr + len <= vma->vm_start)
4525 + if (check_heap_stack_gap(vma, addr, len, offset))
4526 return addr;
4527 addr = vma->vm_end;
4528 }
4529 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4530 return offset & 0x3FF000;
4531 }
4532
4533 -static unsigned long get_shared_area(struct address_space *mapping,
4534 - unsigned long addr, unsigned long len, unsigned long pgoff)
4535 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4536 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4537 {
4538 struct vm_area_struct *vma;
4539 int offset = mapping ? get_offset(mapping) : 0;
4540 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4541
4542 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4543
4544 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4545 /* At this point: (!vma || addr < vma->vm_end). */
4546 if (TASK_SIZE - len < addr)
4547 return -ENOMEM;
4548 - if (!vma || addr + len <= vma->vm_start)
4549 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
4550 return addr;
4551 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4552 if (addr < vma->vm_end) /* handle wraparound */
4553 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4554 if (flags & MAP_FIXED)
4555 return addr;
4556 if (!addr)
4557 - addr = TASK_UNMAPPED_BASE;
4558 + addr = current->mm->mmap_base;
4559
4560 if (filp) {
4561 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4562 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4563 } else if(flags & MAP_SHARED) {
4564 - addr = get_shared_area(NULL, addr, len, pgoff);
4565 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4566 } else {
4567 - addr = get_unshared_area(addr, len);
4568 + addr = get_unshared_area(filp, addr, len, flags);
4569 }
4570 return addr;
4571 }
4572 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4573 index 45ba99f..8e22c33 100644
4574 --- a/arch/parisc/kernel/traps.c
4575 +++ b/arch/parisc/kernel/traps.c
4576 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4577
4578 down_read(&current->mm->mmap_sem);
4579 vma = find_vma(current->mm,regs->iaoq[0]);
4580 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4581 - && (vma->vm_flags & VM_EXEC)) {
4582 -
4583 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4584 fault_address = regs->iaoq[0];
4585 fault_space = regs->iasq[0];
4586
4587 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4588 index 18162ce..94de376 100644
4589 --- a/arch/parisc/mm/fault.c
4590 +++ b/arch/parisc/mm/fault.c
4591 @@ -15,6 +15,7 @@
4592 #include <linux/sched.h>
4593 #include <linux/interrupt.h>
4594 #include <linux/module.h>
4595 +#include <linux/unistd.h>
4596
4597 #include <asm/uaccess.h>
4598 #include <asm/traps.h>
4599 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4600 static unsigned long
4601 parisc_acctyp(unsigned long code, unsigned int inst)
4602 {
4603 - if (code == 6 || code == 16)
4604 + if (code == 6 || code == 7 || code == 16)
4605 return VM_EXEC;
4606
4607 switch (inst & 0xf0000000) {
4608 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4609 }
4610 #endif
4611
4612 +#ifdef CONFIG_PAX_PAGEEXEC
4613 +/*
4614 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4615 + *
4616 + * returns 1 when task should be killed
4617 + * 2 when rt_sigreturn trampoline was detected
4618 + * 3 when unpatched PLT trampoline was detected
4619 + */
4620 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4621 +{
4622 +
4623 +#ifdef CONFIG_PAX_EMUPLT
4624 + int err;
4625 +
4626 + do { /* PaX: unpatched PLT emulation */
4627 + unsigned int bl, depwi;
4628 +
4629 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4630 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4631 +
4632 + if (err)
4633 + break;
4634 +
4635 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4636 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4637 +
4638 + err = get_user(ldw, (unsigned int *)addr);
4639 + err |= get_user(bv, (unsigned int *)(addr+4));
4640 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4641 +
4642 + if (err)
4643 + break;
4644 +
4645 + if (ldw == 0x0E801096U &&
4646 + bv == 0xEAC0C000U &&
4647 + ldw2 == 0x0E881095U)
4648 + {
4649 + unsigned int resolver, map;
4650 +
4651 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4652 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4653 + if (err)
4654 + break;
4655 +
4656 + regs->gr[20] = instruction_pointer(regs)+8;
4657 + regs->gr[21] = map;
4658 + regs->gr[22] = resolver;
4659 + regs->iaoq[0] = resolver | 3UL;
4660 + regs->iaoq[1] = regs->iaoq[0] + 4;
4661 + return 3;
4662 + }
4663 + }
4664 + } while (0);
4665 +#endif
4666 +
4667 +#ifdef CONFIG_PAX_EMUTRAMP
4668 +
4669 +#ifndef CONFIG_PAX_EMUSIGRT
4670 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4671 + return 1;
4672 +#endif
4673 +
4674 + do { /* PaX: rt_sigreturn emulation */
4675 + unsigned int ldi1, ldi2, bel, nop;
4676 +
4677 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4678 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4679 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4680 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4681 +
4682 + if (err)
4683 + break;
4684 +
4685 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4686 + ldi2 == 0x3414015AU &&
4687 + bel == 0xE4008200U &&
4688 + nop == 0x08000240U)
4689 + {
4690 + regs->gr[25] = (ldi1 & 2) >> 1;
4691 + regs->gr[20] = __NR_rt_sigreturn;
4692 + regs->gr[31] = regs->iaoq[1] + 16;
4693 + regs->sr[0] = regs->iasq[1];
4694 + regs->iaoq[0] = 0x100UL;
4695 + regs->iaoq[1] = regs->iaoq[0] + 4;
4696 + regs->iasq[0] = regs->sr[2];
4697 + regs->iasq[1] = regs->sr[2];
4698 + return 2;
4699 + }
4700 + } while (0);
4701 +#endif
4702 +
4703 + return 1;
4704 +}
4705 +
4706 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4707 +{
4708 + unsigned long i;
4709 +
4710 + printk(KERN_ERR "PAX: bytes at PC: ");
4711 + for (i = 0; i < 5; i++) {
4712 + unsigned int c;
4713 + if (get_user(c, (unsigned int *)pc+i))
4714 + printk(KERN_CONT "???????? ");
4715 + else
4716 + printk(KERN_CONT "%08x ", c);
4717 + }
4718 + printk("\n");
4719 +}
4720 +#endif
4721 +
4722 int fixup_exception(struct pt_regs *regs)
4723 {
4724 const struct exception_table_entry *fix;
4725 @@ -192,8 +303,33 @@ good_area:
4726
4727 acc_type = parisc_acctyp(code,regs->iir);
4728
4729 - if ((vma->vm_flags & acc_type) != acc_type)
4730 + if ((vma->vm_flags & acc_type) != acc_type) {
4731 +
4732 +#ifdef CONFIG_PAX_PAGEEXEC
4733 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4734 + (address & ~3UL) == instruction_pointer(regs))
4735 + {
4736 + up_read(&mm->mmap_sem);
4737 + switch (pax_handle_fetch_fault(regs)) {
4738 +
4739 +#ifdef CONFIG_PAX_EMUPLT
4740 + case 3:
4741 + return;
4742 +#endif
4743 +
4744 +#ifdef CONFIG_PAX_EMUTRAMP
4745 + case 2:
4746 + return;
4747 +#endif
4748 +
4749 + }
4750 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4751 + do_group_exit(SIGKILL);
4752 + }
4753 +#endif
4754 +
4755 goto bad_area;
4756 + }
4757
4758 /*
4759 * If for any reason at all we couldn't handle the fault, make
4760 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4761 index e3b1d41..8e81edf 100644
4762 --- a/arch/powerpc/include/asm/atomic.h
4763 +++ b/arch/powerpc/include/asm/atomic.h
4764 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4765 return t1;
4766 }
4767
4768 +#define atomic64_read_unchecked(v) atomic64_read(v)
4769 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4770 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4771 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4772 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4773 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4774 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4775 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4776 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4777 +
4778 #endif /* __powerpc64__ */
4779
4780 #endif /* __KERNEL__ */
4781 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4782 index 9e495c9..b6878e5 100644
4783 --- a/arch/powerpc/include/asm/cache.h
4784 +++ b/arch/powerpc/include/asm/cache.h
4785 @@ -3,6 +3,7 @@
4786
4787 #ifdef __KERNEL__
4788
4789 +#include <linux/const.h>
4790
4791 /* bytes per L1 cache line */
4792 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4793 @@ -22,7 +23,7 @@
4794 #define L1_CACHE_SHIFT 7
4795 #endif
4796
4797 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4801
4802 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4803 index 6abf0a1..459d0f1 100644
4804 --- a/arch/powerpc/include/asm/elf.h
4805 +++ b/arch/powerpc/include/asm/elf.h
4806 @@ -28,8 +28,19 @@
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810 -extern unsigned long randomize_et_dyn(unsigned long base);
4811 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4812 +#define ELF_ET_DYN_BASE (0x20000000)
4813 +
4814 +#ifdef CONFIG_PAX_ASLR
4815 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4816 +
4817 +#ifdef __powerpc64__
4818 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4819 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4820 +#else
4821 +#define PAX_DELTA_MMAP_LEN 15
4822 +#define PAX_DELTA_STACK_LEN 15
4823 +#endif
4824 +#endif
4825
4826 /*
4827 * Our registers are always unsigned longs, whether we're a 32 bit
4828 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4829 (0x7ff >> (PAGE_SHIFT - 12)) : \
4830 (0x3ffff >> (PAGE_SHIFT - 12)))
4831
4832 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4833 -#define arch_randomize_brk arch_randomize_brk
4834 -
4835 -
4836 #ifdef CONFIG_SPU_BASE
4837 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4838 #define NT_SPU 1
4839 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4840 index 8196e9c..d83a9f3 100644
4841 --- a/arch/powerpc/include/asm/exec.h
4842 +++ b/arch/powerpc/include/asm/exec.h
4843 @@ -4,6 +4,6 @@
4844 #ifndef _ASM_POWERPC_EXEC_H
4845 #define _ASM_POWERPC_EXEC_H
4846
4847 -extern unsigned long arch_align_stack(unsigned long sp);
4848 +#define arch_align_stack(x) ((x) & ~0xfUL)
4849
4850 #endif /* _ASM_POWERPC_EXEC_H */
4851 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4852 index 5acabbd..7ea14fa 100644
4853 --- a/arch/powerpc/include/asm/kmap_types.h
4854 +++ b/arch/powerpc/include/asm/kmap_types.h
4855 @@ -10,7 +10,7 @@
4856 * 2 of the License, or (at your option) any later version.
4857 */
4858
4859 -#define KM_TYPE_NR 16
4860 +#define KM_TYPE_NR 17
4861
4862 #endif /* __KERNEL__ */
4863 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4864 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4865 index 8565c25..2865190 100644
4866 --- a/arch/powerpc/include/asm/mman.h
4867 +++ b/arch/powerpc/include/asm/mman.h
4868 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4869 }
4870 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4871
4872 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4873 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4874 {
4875 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4876 }
4877 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4878 index f072e97..b436dee 100644
4879 --- a/arch/powerpc/include/asm/page.h
4880 +++ b/arch/powerpc/include/asm/page.h
4881 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4882 * and needs to be executable. This means the whole heap ends
4883 * up being executable.
4884 */
4885 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4886 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4887 +#define VM_DATA_DEFAULT_FLAGS32 \
4888 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4889 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4890
4891 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4892 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4893 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4894 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4895 #endif
4896
4897 +#define ktla_ktva(addr) (addr)
4898 +#define ktva_ktla(addr) (addr)
4899 +
4900 /*
4901 * Use the top bit of the higher-level page table entries to indicate whether
4902 * the entries we point to contain hugepages. This works because we know that
4903 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4904 index cd915d6..c10cee8 100644
4905 --- a/arch/powerpc/include/asm/page_64.h
4906 +++ b/arch/powerpc/include/asm/page_64.h
4907 @@ -154,15 +154,18 @@ do { \
4908 * stack by default, so in the absence of a PT_GNU_STACK program header
4909 * we turn execute permission off.
4910 */
4911 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4912 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4913 +#define VM_STACK_DEFAULT_FLAGS32 \
4914 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4915 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4916
4917 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4918 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4919
4920 +#ifndef CONFIG_PAX_PAGEEXEC
4921 #define VM_STACK_DEFAULT_FLAGS \
4922 (is_32bit_task() ? \
4923 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4924 +#endif
4925
4926 #include <asm-generic/getorder.h>
4927
4928 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4929 index 292725c..f87ae14 100644
4930 --- a/arch/powerpc/include/asm/pgalloc-64.h
4931 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4932 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4933 #ifndef CONFIG_PPC_64K_PAGES
4934
4935 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4936 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4937
4938 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4939 {
4940 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4941 pud_set(pud, (unsigned long)pmd);
4942 }
4943
4944 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4945 +{
4946 + pud_populate(mm, pud, pmd);
4947 +}
4948 +
4949 #define pmd_populate(mm, pmd, pte_page) \
4950 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4951 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4952 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4953 #else /* CONFIG_PPC_64K_PAGES */
4954
4955 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4956 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4957
4958 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4959 pte_t *pte)
4960 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4961 index a9cbd3b..3b67efa 100644
4962 --- a/arch/powerpc/include/asm/pgtable.h
4963 +++ b/arch/powerpc/include/asm/pgtable.h
4964 @@ -2,6 +2,7 @@
4965 #define _ASM_POWERPC_PGTABLE_H
4966 #ifdef __KERNEL__
4967
4968 +#include <linux/const.h>
4969 #ifndef __ASSEMBLY__
4970 #include <asm/processor.h> /* For TASK_SIZE */
4971 #include <asm/mmu.h>
4972 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4973 index 4aad413..85d86bf 100644
4974 --- a/arch/powerpc/include/asm/pte-hash32.h
4975 +++ b/arch/powerpc/include/asm/pte-hash32.h
4976 @@ -21,6 +21,7 @@
4977 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4978 #define _PAGE_USER 0x004 /* usermode access allowed */
4979 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4980 +#define _PAGE_EXEC _PAGE_GUARDED
4981 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4982 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4983 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4984 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4985 index d24c141..b60696e 100644
4986 --- a/arch/powerpc/include/asm/reg.h
4987 +++ b/arch/powerpc/include/asm/reg.h
4988 @@ -215,6 +215,7 @@
4989 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4990 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4991 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4992 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4993 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4994 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4995 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4996 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4997 index 406b7b9..af63426 100644
4998 --- a/arch/powerpc/include/asm/thread_info.h
4999 +++ b/arch/powerpc/include/asm/thread_info.h
5000 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
5001 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
5002 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
5003 #define TIF_SINGLESTEP 8 /* singlestepping active */
5004 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
5005 #define TIF_SECCOMP 10 /* secure computing */
5006 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
5007 #define TIF_NOERROR 12 /* Force successful syscall return */
5008 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
5009 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
5010 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
5011 for stack store? */
5012 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
5013 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
5014 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
5015
5016 /* as above, but as bit values */
5017 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5018 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
5019 #define _TIF_UPROBE (1<<TIF_UPROBE)
5020 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5021 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
5022 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5023 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5024 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
5025 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
5026 + _TIF_GRSEC_SETXID)
5027
5028 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
5029 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
5030 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
5031 index 4db4959..335e00c 100644
5032 --- a/arch/powerpc/include/asm/uaccess.h
5033 +++ b/arch/powerpc/include/asm/uaccess.h
5034 @@ -13,6 +13,8 @@
5035 #define VERIFY_READ 0
5036 #define VERIFY_WRITE 1
5037
5038 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5039 +
5040 /*
5041 * The fs value determines whether argument validity checking should be
5042 * performed or not. If get_fs() == USER_DS, checking is performed, with
5043 @@ -318,52 +320,6 @@ do { \
5044 extern unsigned long __copy_tofrom_user(void __user *to,
5045 const void __user *from, unsigned long size);
5046
5047 -#ifndef __powerpc64__
5048 -
5049 -static inline unsigned long copy_from_user(void *to,
5050 - const void __user *from, unsigned long n)
5051 -{
5052 - unsigned long over;
5053 -
5054 - if (access_ok(VERIFY_READ, from, n))
5055 - return __copy_tofrom_user((__force void __user *)to, from, n);
5056 - if ((unsigned long)from < TASK_SIZE) {
5057 - over = (unsigned long)from + n - TASK_SIZE;
5058 - return __copy_tofrom_user((__force void __user *)to, from,
5059 - n - over) + over;
5060 - }
5061 - return n;
5062 -}
5063 -
5064 -static inline unsigned long copy_to_user(void __user *to,
5065 - const void *from, unsigned long n)
5066 -{
5067 - unsigned long over;
5068 -
5069 - if (access_ok(VERIFY_WRITE, to, n))
5070 - return __copy_tofrom_user(to, (__force void __user *)from, n);
5071 - if ((unsigned long)to < TASK_SIZE) {
5072 - over = (unsigned long)to + n - TASK_SIZE;
5073 - return __copy_tofrom_user(to, (__force void __user *)from,
5074 - n - over) + over;
5075 - }
5076 - return n;
5077 -}
5078 -
5079 -#else /* __powerpc64__ */
5080 -
5081 -#define __copy_in_user(to, from, size) \
5082 - __copy_tofrom_user((to), (from), (size))
5083 -
5084 -extern unsigned long copy_from_user(void *to, const void __user *from,
5085 - unsigned long n);
5086 -extern unsigned long copy_to_user(void __user *to, const void *from,
5087 - unsigned long n);
5088 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
5089 - unsigned long n);
5090 -
5091 -#endif /* __powerpc64__ */
5092 -
5093 static inline unsigned long __copy_from_user_inatomic(void *to,
5094 const void __user *from, unsigned long n)
5095 {
5096 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5097 if (ret == 0)
5098 return 0;
5099 }
5100 +
5101 + if (!__builtin_constant_p(n))
5102 + check_object_size(to, n, false);
5103 +
5104 return __copy_tofrom_user((__force void __user *)to, from, n);
5105 }
5106
5107 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5108 if (ret == 0)
5109 return 0;
5110 }
5111 +
5112 + if (!__builtin_constant_p(n))
5113 + check_object_size(from, n, true);
5114 +
5115 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5116 }
5117
5118 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5119 return __copy_to_user_inatomic(to, from, size);
5120 }
5121
5122 +#ifndef __powerpc64__
5123 +
5124 +static inline unsigned long __must_check copy_from_user(void *to,
5125 + const void __user *from, unsigned long n)
5126 +{
5127 + unsigned long over;
5128 +
5129 + if ((long)n < 0)
5130 + return n;
5131 +
5132 + if (access_ok(VERIFY_READ, from, n)) {
5133 + if (!__builtin_constant_p(n))
5134 + check_object_size(to, n, false);
5135 + return __copy_tofrom_user((__force void __user *)to, from, n);
5136 + }
5137 + if ((unsigned long)from < TASK_SIZE) {
5138 + over = (unsigned long)from + n - TASK_SIZE;
5139 + if (!__builtin_constant_p(n - over))
5140 + check_object_size(to, n - over, false);
5141 + return __copy_tofrom_user((__force void __user *)to, from,
5142 + n - over) + over;
5143 + }
5144 + return n;
5145 +}
5146 +
5147 +static inline unsigned long __must_check copy_to_user(void __user *to,
5148 + const void *from, unsigned long n)
5149 +{
5150 + unsigned long over;
5151 +
5152 + if ((long)n < 0)
5153 + return n;
5154 +
5155 + if (access_ok(VERIFY_WRITE, to, n)) {
5156 + if (!__builtin_constant_p(n))
5157 + check_object_size(from, n, true);
5158 + return __copy_tofrom_user(to, (__force void __user *)from, n);
5159 + }
5160 + if ((unsigned long)to < TASK_SIZE) {
5161 + over = (unsigned long)to + n - TASK_SIZE;
5162 + if (!__builtin_constant_p(n))
5163 + check_object_size(from, n - over, true);
5164 + return __copy_tofrom_user(to, (__force void __user *)from,
5165 + n - over) + over;
5166 + }
5167 + return n;
5168 +}
5169 +
5170 +#else /* __powerpc64__ */
5171 +
5172 +#define __copy_in_user(to, from, size) \
5173 + __copy_tofrom_user((to), (from), (size))
5174 +
5175 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5176 +{
5177 + if ((long)n < 0 || n > INT_MAX)
5178 + return n;
5179 +
5180 + if (!__builtin_constant_p(n))
5181 + check_object_size(to, n, false);
5182 +
5183 + if (likely(access_ok(VERIFY_READ, from, n)))
5184 + n = __copy_from_user(to, from, n);
5185 + else
5186 + memset(to, 0, n);
5187 + return n;
5188 +}
5189 +
5190 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5191 +{
5192 + if ((long)n < 0 || n > INT_MAX)
5193 + return n;
5194 +
5195 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
5196 + if (!__builtin_constant_p(n))
5197 + check_object_size(from, n, true);
5198 + n = __copy_to_user(to, from, n);
5199 + }
5200 + return n;
5201 +}
5202 +
5203 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
5204 + unsigned long n);
5205 +
5206 +#endif /* __powerpc64__ */
5207 +
5208 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5209
5210 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5211 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5212 index 4684e33..acc4d19e 100644
5213 --- a/arch/powerpc/kernel/exceptions-64e.S
5214 +++ b/arch/powerpc/kernel/exceptions-64e.S
5215 @@ -715,6 +715,7 @@ storage_fault_common:
5216 std r14,_DAR(r1)
5217 std r15,_DSISR(r1)
5218 addi r3,r1,STACK_FRAME_OVERHEAD
5219 + bl .save_nvgprs
5220 mr r4,r14
5221 mr r5,r15
5222 ld r14,PACA_EXGEN+EX_R14(r13)
5223 @@ -723,8 +724,7 @@ storage_fault_common:
5224 cmpdi r3,0
5225 bne- 1f
5226 b .ret_from_except_lite
5227 -1: bl .save_nvgprs
5228 - mr r5,r3
5229 +1: mr r5,r3
5230 addi r3,r1,STACK_FRAME_OVERHEAD
5231 ld r4,_DAR(r1)
5232 bl .bad_page_fault
5233 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5234 index 10b658a..e542888 100644
5235 --- a/arch/powerpc/kernel/exceptions-64s.S
5236 +++ b/arch/powerpc/kernel/exceptions-64s.S
5237 @@ -1013,10 +1013,10 @@ handle_page_fault:
5238 11: ld r4,_DAR(r1)
5239 ld r5,_DSISR(r1)
5240 addi r3,r1,STACK_FRAME_OVERHEAD
5241 + bl .save_nvgprs
5242 bl .do_page_fault
5243 cmpdi r3,0
5244 beq+ 12f
5245 - bl .save_nvgprs
5246 mr r5,r3
5247 addi r3,r1,STACK_FRAME_OVERHEAD
5248 lwz r4,_DAR(r1)
5249 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5250 index 2e3200c..72095ce 100644
5251 --- a/arch/powerpc/kernel/module_32.c
5252 +++ b/arch/powerpc/kernel/module_32.c
5253 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5254 me->arch.core_plt_section = i;
5255 }
5256 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5257 - printk("Module doesn't contain .plt or .init.plt sections.\n");
5258 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5259 return -ENOEXEC;
5260 }
5261
5262 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5263
5264 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5265 /* Init, or core PLT? */
5266 - if (location >= mod->module_core
5267 - && location < mod->module_core + mod->core_size)
5268 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5269 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5270 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5271 - else
5272 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5273 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5274 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5275 + else {
5276 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5277 + return ~0UL;
5278 + }
5279
5280 /* Find this entry, or if that fails, the next avail. entry */
5281 while (entry->jump[0]) {
5282 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5283 index ba48233..16ac31d 100644
5284 --- a/arch/powerpc/kernel/process.c
5285 +++ b/arch/powerpc/kernel/process.c
5286 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5287 * Lookup NIP late so we have the best change of getting the
5288 * above info out without failing
5289 */
5290 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5291 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5292 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5293 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5294 #endif
5295 show_stack(current, (unsigned long *) regs->gpr[1]);
5296 if (!user_mode(regs))
5297 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5298 newsp = stack[0];
5299 ip = stack[STACK_FRAME_LR_SAVE];
5300 if (!firstframe || ip != lr) {
5301 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5302 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5303 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5304 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5305 - printk(" (%pS)",
5306 + printk(" (%pA)",
5307 (void *)current->ret_stack[curr_frame].ret);
5308 curr_frame--;
5309 }
5310 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5311 struct pt_regs *regs = (struct pt_regs *)
5312 (sp + STACK_FRAME_OVERHEAD);
5313 lr = regs->link;
5314 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5315 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5316 regs->trap, (void *)regs->nip, (void *)lr);
5317 firstframe = 1;
5318 }
5319 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5320 mtspr(SPRN_CTRLT, ctrl);
5321 }
5322 #endif /* CONFIG_PPC64 */
5323 -
5324 -unsigned long arch_align_stack(unsigned long sp)
5325 -{
5326 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5327 - sp -= get_random_int() & ~PAGE_MASK;
5328 - return sp & ~0xf;
5329 -}
5330 -
5331 -static inline unsigned long brk_rnd(void)
5332 -{
5333 - unsigned long rnd = 0;
5334 -
5335 - /* 8MB for 32bit, 1GB for 64bit */
5336 - if (is_32bit_task())
5337 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5338 - else
5339 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5340 -
5341 - return rnd << PAGE_SHIFT;
5342 -}
5343 -
5344 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5345 -{
5346 - unsigned long base = mm->brk;
5347 - unsigned long ret;
5348 -
5349 -#ifdef CONFIG_PPC_STD_MMU_64
5350 - /*
5351 - * If we are using 1TB segments and we are allowed to randomise
5352 - * the heap, we can put it above 1TB so it is backed by a 1TB
5353 - * segment. Otherwise the heap will be in the bottom 1TB
5354 - * which always uses 256MB segments and this may result in a
5355 - * performance penalty.
5356 - */
5357 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5358 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5359 -#endif
5360 -
5361 - ret = PAGE_ALIGN(base + brk_rnd());
5362 -
5363 - if (ret < mm->brk)
5364 - return mm->brk;
5365 -
5366 - return ret;
5367 -}
5368 -
5369 -unsigned long randomize_et_dyn(unsigned long base)
5370 -{
5371 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5372 -
5373 - if (ret < base)
5374 - return base;
5375 -
5376 - return ret;
5377 -}
5378 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5379 index 79d8e56..38ffcbb 100644
5380 --- a/arch/powerpc/kernel/ptrace.c
5381 +++ b/arch/powerpc/kernel/ptrace.c
5382 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5383 return ret;
5384 }
5385
5386 +#ifdef CONFIG_GRKERNSEC_SETXID
5387 +extern void gr_delayed_cred_worker(void);
5388 +#endif
5389 +
5390 /*
5391 * We must return the syscall number to actually look up in the table.
5392 * This can be -1L to skip running any syscall at all.
5393 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5394
5395 secure_computing_strict(regs->gpr[0]);
5396
5397 +#ifdef CONFIG_GRKERNSEC_SETXID
5398 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5399 + gr_delayed_cred_worker();
5400 +#endif
5401 +
5402 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5403 tracehook_report_syscall_entry(regs))
5404 /*
5405 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5406 {
5407 int step;
5408
5409 +#ifdef CONFIG_GRKERNSEC_SETXID
5410 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5411 + gr_delayed_cred_worker();
5412 +#endif
5413 +
5414 audit_syscall_exit(regs);
5415
5416 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5417 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5418 index 804e323..79181c1 100644
5419 --- a/arch/powerpc/kernel/signal_32.c
5420 +++ b/arch/powerpc/kernel/signal_32.c
5421 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5422 /* Save user registers on the stack */
5423 frame = &rt_sf->uc.uc_mcontext;
5424 addr = frame;
5425 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5426 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5427 if (save_user_regs(regs, frame, 0, 1))
5428 goto badframe;
5429 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5430 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5431 index d183f87..1867f1a 100644
5432 --- a/arch/powerpc/kernel/signal_64.c
5433 +++ b/arch/powerpc/kernel/signal_64.c
5434 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5435 current->thread.fpscr.val = 0;
5436
5437 /* Set up to return from userspace. */
5438 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5439 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5440 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5441 } else {
5442 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5443 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5444 index 3251840..3f7c77a 100644
5445 --- a/arch/powerpc/kernel/traps.c
5446 +++ b/arch/powerpc/kernel/traps.c
5447 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5448 return flags;
5449 }
5450
5451 +extern void gr_handle_kernel_exploit(void);
5452 +
5453 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5454 int signr)
5455 {
5456 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5457 panic("Fatal exception in interrupt");
5458 if (panic_on_oops)
5459 panic("Fatal exception");
5460 +
5461 + gr_handle_kernel_exploit();
5462 +
5463 do_exit(signr);
5464 }
5465
5466 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5467 index 1b2076f..835e4be 100644
5468 --- a/arch/powerpc/kernel/vdso.c
5469 +++ b/arch/powerpc/kernel/vdso.c
5470 @@ -34,6 +34,7 @@
5471 #include <asm/firmware.h>
5472 #include <asm/vdso.h>
5473 #include <asm/vdso_datapage.h>
5474 +#include <asm/mman.h>
5475
5476 #include "setup.h"
5477
5478 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5479 vdso_base = VDSO32_MBASE;
5480 #endif
5481
5482 - current->mm->context.vdso_base = 0;
5483 + current->mm->context.vdso_base = ~0UL;
5484
5485 /* vDSO has a problem and was disabled, just don't "enable" it for the
5486 * process
5487 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5488 vdso_base = get_unmapped_area(NULL, vdso_base,
5489 (vdso_pages << PAGE_SHIFT) +
5490 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5491 - 0, 0);
5492 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5493 if (IS_ERR_VALUE(vdso_base)) {
5494 rc = vdso_base;
5495 goto fail_mmapsem;
5496 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5497 index 5eea6f3..5d10396 100644
5498 --- a/arch/powerpc/lib/usercopy_64.c
5499 +++ b/arch/powerpc/lib/usercopy_64.c
5500 @@ -9,22 +9,6 @@
5501 #include <linux/module.h>
5502 #include <asm/uaccess.h>
5503
5504 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5505 -{
5506 - if (likely(access_ok(VERIFY_READ, from, n)))
5507 - n = __copy_from_user(to, from, n);
5508 - else
5509 - memset(to, 0, n);
5510 - return n;
5511 -}
5512 -
5513 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5514 -{
5515 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5516 - n = __copy_to_user(to, from, n);
5517 - return n;
5518 -}
5519 -
5520 unsigned long copy_in_user(void __user *to, const void __user *from,
5521 unsigned long n)
5522 {
5523 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5524 return n;
5525 }
5526
5527 -EXPORT_SYMBOL(copy_from_user);
5528 -EXPORT_SYMBOL(copy_to_user);
5529 EXPORT_SYMBOL(copy_in_user);
5530
5531 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5532 index 0a6b283..7674925 100644
5533 --- a/arch/powerpc/mm/fault.c
5534 +++ b/arch/powerpc/mm/fault.c
5535 @@ -32,6 +32,10 @@
5536 #include <linux/perf_event.h>
5537 #include <linux/magic.h>
5538 #include <linux/ratelimit.h>
5539 +#include <linux/slab.h>
5540 +#include <linux/pagemap.h>
5541 +#include <linux/compiler.h>
5542 +#include <linux/unistd.h>
5543
5544 #include <asm/firmware.h>
5545 #include <asm/page.h>
5546 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5547 }
5548 #endif
5549
5550 +#ifdef CONFIG_PAX_PAGEEXEC
5551 +/*
5552 + * PaX: decide what to do with offenders (regs->nip = fault address)
5553 + *
5554 + * returns 1 when task should be killed
5555 + */
5556 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5557 +{
5558 + return 1;
5559 +}
5560 +
5561 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5562 +{
5563 + unsigned long i;
5564 +
5565 + printk(KERN_ERR "PAX: bytes at PC: ");
5566 + for (i = 0; i < 5; i++) {
5567 + unsigned int c;
5568 + if (get_user(c, (unsigned int __user *)pc+i))
5569 + printk(KERN_CONT "???????? ");
5570 + else
5571 + printk(KERN_CONT "%08x ", c);
5572 + }
5573 + printk("\n");
5574 +}
5575 +#endif
5576 +
5577 /*
5578 * Check whether the instruction at regs->nip is a store using
5579 * an update addressing form which will update r1.
5580 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5581 * indicate errors in DSISR but can validly be set in SRR1.
5582 */
5583 if (trap == 0x400)
5584 - error_code &= 0x48200000;
5585 + error_code &= 0x58200000;
5586 else
5587 is_write = error_code & DSISR_ISSTORE;
5588 #else
5589 @@ -367,7 +398,7 @@ good_area:
5590 * "undefined". Of those that can be set, this is the only
5591 * one which seems bad.
5592 */
5593 - if (error_code & 0x10000000)
5594 + if (error_code & DSISR_GUARDED)
5595 /* Guarded storage error. */
5596 goto bad_area;
5597 #endif /* CONFIG_8xx */
5598 @@ -382,7 +413,7 @@ good_area:
5599 * processors use the same I/D cache coherency mechanism
5600 * as embedded.
5601 */
5602 - if (error_code & DSISR_PROTFAULT)
5603 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5604 goto bad_area;
5605 #endif /* CONFIG_PPC_STD_MMU */
5606
5607 @@ -465,6 +496,23 @@ bad_area:
5608 bad_area_nosemaphore:
5609 /* User mode accesses cause a SIGSEGV */
5610 if (user_mode(regs)) {
5611 +
5612 +#ifdef CONFIG_PAX_PAGEEXEC
5613 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5614 +#ifdef CONFIG_PPC_STD_MMU
5615 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5616 +#else
5617 + if (is_exec && regs->nip == address) {
5618 +#endif
5619 + switch (pax_handle_fetch_fault(regs)) {
5620 + }
5621 +
5622 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5623 + do_group_exit(SIGKILL);
5624 + }
5625 + }
5626 +#endif
5627 +
5628 _exception(SIGSEGV, regs, code, address);
5629 return 0;
5630 }
5631 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5632 index 67a42ed..c16ef80 100644
5633 --- a/arch/powerpc/mm/mmap_64.c
5634 +++ b/arch/powerpc/mm/mmap_64.c
5635 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
5636 {
5637 unsigned long rnd = 0;
5638
5639 +#ifdef CONFIG_PAX_RANDMMAP
5640 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5641 +#endif
5642 +
5643 if (current->flags & PF_RANDOMIZE) {
5644 /* 8MB for 32bit, 1GB for 64bit */
5645 if (is_32bit_task())
5646 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5647 */
5648 if (mmap_is_legacy()) {
5649 mm->mmap_base = TASK_UNMAPPED_BASE;
5650 +
5651 +#ifdef CONFIG_PAX_RANDMMAP
5652 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5653 + mm->mmap_base += mm->delta_mmap;
5654 +#endif
5655 +
5656 mm->get_unmapped_area = arch_get_unmapped_area;
5657 mm->unmap_area = arch_unmap_area;
5658 } else {
5659 mm->mmap_base = mmap_base();
5660 +
5661 +#ifdef CONFIG_PAX_RANDMMAP
5662 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5663 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5664 +#endif
5665 +
5666 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5667 mm->unmap_area = arch_unmap_area_topdown;
5668 }
5669 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5670 index 5829d2a..af84242 100644
5671 --- a/arch/powerpc/mm/slice.c
5672 +++ b/arch/powerpc/mm/slice.c
5673 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5674 if ((mm->task_size - len) < addr)
5675 return 0;
5676 vma = find_vma(mm, addr);
5677 - return (!vma || (addr + len) <= vma->vm_start);
5678 + return check_heap_stack_gap(vma, addr, len, 0);
5679 }
5680
5681 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5682 @@ -272,7 +272,7 @@ full_search:
5683 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5684 continue;
5685 }
5686 - if (!vma || addr + len <= vma->vm_start) {
5687 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5688 /*
5689 * Remember the place where we stopped the search:
5690 */
5691 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5692 }
5693 }
5694
5695 - addr = mm->mmap_base;
5696 - while (addr > len) {
5697 + if (mm->mmap_base < len)
5698 + addr = -ENOMEM;
5699 + else
5700 + addr = mm->mmap_base - len;
5701 +
5702 + while (!IS_ERR_VALUE(addr)) {
5703 /* Go down by chunk size */
5704 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5705 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5706
5707 /* Check for hit with different page size */
5708 mask = slice_range_to_mask(addr, len);
5709 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5710 * return with success:
5711 */
5712 vma = find_vma(mm, addr);
5713 - if (!vma || (addr + len) <= vma->vm_start) {
5714 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5715 /* remember the address as a hint for next time */
5716 if (use_cache)
5717 mm->free_area_cache = addr;
5718 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5719 mm->cached_hole_size = vma->vm_start - addr;
5720
5721 /* try just below the current vma->vm_start */
5722 - addr = vma->vm_start;
5723 + addr = skip_heap_stack_gap(vma, len, 0);
5724 }
5725
5726 /*
5727 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5728 if (fixed && addr > (mm->task_size - len))
5729 return -EINVAL;
5730
5731 +#ifdef CONFIG_PAX_RANDMMAP
5732 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5733 + addr = 0;
5734 +#endif
5735 +
5736 /* If hint, make sure it matches our alignment restrictions */
5737 if (!fixed && addr) {
5738 addr = _ALIGN_UP(addr, 1ul << pshift);
5739 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5740 index c797832..ce575c8 100644
5741 --- a/arch/s390/include/asm/atomic.h
5742 +++ b/arch/s390/include/asm/atomic.h
5743 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5744 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5745 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5746
5747 +#define atomic64_read_unchecked(v) atomic64_read(v)
5748 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5749 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5750 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5751 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5752 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5753 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5754 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5755 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5756 +
5757 #define smp_mb__before_atomic_dec() smp_mb()
5758 #define smp_mb__after_atomic_dec() smp_mb()
5759 #define smp_mb__before_atomic_inc() smp_mb()
5760 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5761 index 4d7ccac..d03d0ad 100644
5762 --- a/arch/s390/include/asm/cache.h
5763 +++ b/arch/s390/include/asm/cache.h
5764 @@ -9,8 +9,10 @@
5765 #ifndef __ARCH_S390_CACHE_H
5766 #define __ARCH_S390_CACHE_H
5767
5768 -#define L1_CACHE_BYTES 256
5769 +#include <linux/const.h>
5770 +
5771 #define L1_CACHE_SHIFT 8
5772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5773 #define NET_SKB_PAD 32
5774
5775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5776 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5777 index 178ff96..8c93bd1 100644
5778 --- a/arch/s390/include/asm/elf.h
5779 +++ b/arch/s390/include/asm/elf.h
5780 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5781 the loader. We need to make sure that it is out of the way of the program
5782 that it will "exec", and that there is sufficient room for the brk. */
5783
5784 -extern unsigned long randomize_et_dyn(unsigned long base);
5785 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5786 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5787 +
5788 +#ifdef CONFIG_PAX_ASLR
5789 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5790 +
5791 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5792 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5793 +#endif
5794
5795 /* This yields a mask that user programs can use to figure out what
5796 instruction set this CPU supports. */
5797 @@ -210,9 +216,6 @@ struct linux_binprm;
5798 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5799 int arch_setup_additional_pages(struct linux_binprm *, int);
5800
5801 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5802 -#define arch_randomize_brk arch_randomize_brk
5803 -
5804 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5805
5806 #endif
5807 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5808 index c4a93d6..4d2a9b4 100644
5809 --- a/arch/s390/include/asm/exec.h
5810 +++ b/arch/s390/include/asm/exec.h
5811 @@ -7,6 +7,6 @@
5812 #ifndef __ASM_EXEC_H
5813 #define __ASM_EXEC_H
5814
5815 -extern unsigned long arch_align_stack(unsigned long sp);
5816 +#define arch_align_stack(x) ((x) & ~0xfUL)
5817
5818 #endif /* __ASM_EXEC_H */
5819 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5820 index 34268df..ea97318 100644
5821 --- a/arch/s390/include/asm/uaccess.h
5822 +++ b/arch/s390/include/asm/uaccess.h
5823 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5824 copy_to_user(void __user *to, const void *from, unsigned long n)
5825 {
5826 might_fault();
5827 +
5828 + if ((long)n < 0)
5829 + return n;
5830 +
5831 if (access_ok(VERIFY_WRITE, to, n))
5832 n = __copy_to_user(to, from, n);
5833 return n;
5834 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5835 static inline unsigned long __must_check
5836 __copy_from_user(void *to, const void __user *from, unsigned long n)
5837 {
5838 + if ((long)n < 0)
5839 + return n;
5840 +
5841 if (__builtin_constant_p(n) && (n <= 256))
5842 return uaccess.copy_from_user_small(n, from, to);
5843 else
5844 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5845 static inline unsigned long __must_check
5846 copy_from_user(void *to, const void __user *from, unsigned long n)
5847 {
5848 - unsigned int sz = __compiletime_object_size(to);
5849 + size_t sz = __compiletime_object_size(to);
5850
5851 might_fault();
5852 - if (unlikely(sz != -1 && sz < n)) {
5853 +
5854 + if ((long)n < 0)
5855 + return n;
5856 +
5857 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5858 copy_from_user_overflow();
5859 return n;
5860 }
5861 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5862 index 4610dea..cf0af21 100644
5863 --- a/arch/s390/kernel/module.c
5864 +++ b/arch/s390/kernel/module.c
5865 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5866
5867 /* Increase core size by size of got & plt and set start
5868 offsets for got and plt. */
5869 - me->core_size = ALIGN(me->core_size, 4);
5870 - me->arch.got_offset = me->core_size;
5871 - me->core_size += me->arch.got_size;
5872 - me->arch.plt_offset = me->core_size;
5873 - me->core_size += me->arch.plt_size;
5874 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5875 + me->arch.got_offset = me->core_size_rw;
5876 + me->core_size_rw += me->arch.got_size;
5877 + me->arch.plt_offset = me->core_size_rx;
5878 + me->core_size_rx += me->arch.plt_size;
5879 return 0;
5880 }
5881
5882 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5883 if (info->got_initialized == 0) {
5884 Elf_Addr *gotent;
5885
5886 - gotent = me->module_core + me->arch.got_offset +
5887 + gotent = me->module_core_rw + me->arch.got_offset +
5888 info->got_offset;
5889 *gotent = val;
5890 info->got_initialized = 1;
5891 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5892 else if (r_type == R_390_GOTENT ||
5893 r_type == R_390_GOTPLTENT)
5894 *(unsigned int *) loc =
5895 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5896 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5897 else if (r_type == R_390_GOT64 ||
5898 r_type == R_390_GOTPLT64)
5899 *(unsigned long *) loc = val;
5900 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5901 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5902 if (info->plt_initialized == 0) {
5903 unsigned int *ip;
5904 - ip = me->module_core + me->arch.plt_offset +
5905 + ip = me->module_core_rx + me->arch.plt_offset +
5906 info->plt_offset;
5907 #ifndef CONFIG_64BIT
5908 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5909 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5910 val - loc + 0xffffUL < 0x1ffffeUL) ||
5911 (r_type == R_390_PLT32DBL &&
5912 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5913 - val = (Elf_Addr) me->module_core +
5914 + val = (Elf_Addr) me->module_core_rx +
5915 me->arch.plt_offset +
5916 info->plt_offset;
5917 val += rela->r_addend - loc;
5918 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5919 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5920 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5921 val = val + rela->r_addend -
5922 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5923 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5924 if (r_type == R_390_GOTOFF16)
5925 *(unsigned short *) loc = val;
5926 else if (r_type == R_390_GOTOFF32)
5927 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5928 break;
5929 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5930 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5931 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5932 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5933 rela->r_addend - loc;
5934 if (r_type == R_390_GOTPC)
5935 *(unsigned int *) loc = val;
5936 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5937 index cd31ad4..201c5a3 100644
5938 --- a/arch/s390/kernel/process.c
5939 +++ b/arch/s390/kernel/process.c
5940 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5941 }
5942 return 0;
5943 }
5944 -
5945 -unsigned long arch_align_stack(unsigned long sp)
5946 -{
5947 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5948 - sp -= get_random_int() & ~PAGE_MASK;
5949 - return sp & ~0xf;
5950 -}
5951 -
5952 -static inline unsigned long brk_rnd(void)
5953 -{
5954 - /* 8MB for 32bit, 1GB for 64bit */
5955 - if (is_32bit_task())
5956 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5957 - else
5958 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5959 -}
5960 -
5961 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5962 -{
5963 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5964 -
5965 - if (ret < mm->brk)
5966 - return mm->brk;
5967 - return ret;
5968 -}
5969 -
5970 -unsigned long randomize_et_dyn(unsigned long base)
5971 -{
5972 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5973 -
5974 - if (!(current->flags & PF_RANDOMIZE))
5975 - return base;
5976 - if (ret < base)
5977 - return base;
5978 - return ret;
5979 -}
5980 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5981 index c59a5ef..3fae59c 100644
5982 --- a/arch/s390/mm/mmap.c
5983 +++ b/arch/s390/mm/mmap.c
5984 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 */
5986 if (mmap_is_legacy()) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE;
5988 +
5989 +#ifdef CONFIG_PAX_RANDMMAP
5990 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5991 + mm->mmap_base += mm->delta_mmap;
5992 +#endif
5993 +
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 mm->mmap_base = mmap_base();
5998 +
5999 +#ifdef CONFIG_PAX_RANDMMAP
6000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6001 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6002 +#endif
6003 +
6004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6005 mm->unmap_area = arch_unmap_area_topdown;
6006 }
6007 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 */
6009 if (mmap_is_legacy()) {
6010 mm->mmap_base = TASK_UNMAPPED_BASE;
6011 +
6012 +#ifdef CONFIG_PAX_RANDMMAP
6013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6014 + mm->mmap_base += mm->delta_mmap;
6015 +#endif
6016 +
6017 mm->get_unmapped_area = s390_get_unmapped_area;
6018 mm->unmap_area = arch_unmap_area;
6019 } else {
6020 mm->mmap_base = mmap_base();
6021 +
6022 +#ifdef CONFIG_PAX_RANDMMAP
6023 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6024 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6025 +#endif
6026 +
6027 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
6028 mm->unmap_area = arch_unmap_area_topdown;
6029 }
6030 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
6031 index ae3d59f..f65f075 100644
6032 --- a/arch/score/include/asm/cache.h
6033 +++ b/arch/score/include/asm/cache.h
6034 @@ -1,7 +1,9 @@
6035 #ifndef _ASM_SCORE_CACHE_H
6036 #define _ASM_SCORE_CACHE_H
6037
6038 +#include <linux/const.h>
6039 +
6040 #define L1_CACHE_SHIFT 4
6041 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6043
6044 #endif /* _ASM_SCORE_CACHE_H */
6045 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
6046 index f9f3cd5..58ff438 100644
6047 --- a/arch/score/include/asm/exec.h
6048 +++ b/arch/score/include/asm/exec.h
6049 @@ -1,6 +1,6 @@
6050 #ifndef _ASM_SCORE_EXEC_H
6051 #define _ASM_SCORE_EXEC_H
6052
6053 -extern unsigned long arch_align_stack(unsigned long sp);
6054 +#define arch_align_stack(x) (x)
6055
6056 #endif /* _ASM_SCORE_EXEC_H */
6057 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
6058 index 637970c..0b6556b 100644
6059 --- a/arch/score/kernel/process.c
6060 +++ b/arch/score/kernel/process.c
6061 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
6062
6063 return task_pt_regs(task)->cp0_epc;
6064 }
6065 -
6066 -unsigned long arch_align_stack(unsigned long sp)
6067 -{
6068 - return sp;
6069 -}
6070 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6071 index ef9e555..331bd29 100644
6072 --- a/arch/sh/include/asm/cache.h
6073 +++ b/arch/sh/include/asm/cache.h
6074 @@ -9,10 +9,11 @@
6075 #define __ASM_SH_CACHE_H
6076 #ifdef __KERNEL__
6077
6078 +#include <linux/const.h>
6079 #include <linux/init.h>
6080 #include <cpu/cache.h>
6081
6082 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6084
6085 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6086
6087 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6088 index afeb710..e8366ef 100644
6089 --- a/arch/sh/mm/mmap.c
6090 +++ b/arch/sh/mm/mmap.c
6091 @@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6092 struct vm_area_struct *vma;
6093 unsigned long start_addr;
6094 int do_colour_align;
6095 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6096
6097 if (flags & MAP_FIXED) {
6098 /* We do not accept a shared mapping if it would violate
6099 @@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6100 addr = PAGE_ALIGN(addr);
6101
6102 vma = find_vma(mm, addr);
6103 - if (TASK_SIZE - len >= addr &&
6104 - (!vma || addr + len <= vma->vm_start))
6105 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6106 return addr;
6107 }
6108
6109 @@ -106,7 +106,7 @@ full_search:
6110 }
6111 return -ENOMEM;
6112 }
6113 - if (likely(!vma || addr + len <= vma->vm_start)) {
6114 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6115 /*
6116 * Remember the place where we stopped the search:
6117 */
6118 @@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6119 struct mm_struct *mm = current->mm;
6120 unsigned long addr = addr0;
6121 int do_colour_align;
6122 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6123
6124 if (flags & MAP_FIXED) {
6125 /* We do not accept a shared mapping if it would violate
6126 @@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6127 addr = PAGE_ALIGN(addr);
6128
6129 vma = find_vma(mm, addr);
6130 - if (TASK_SIZE - len >= addr &&
6131 - (!vma || addr + len <= vma->vm_start))
6132 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6133 return addr;
6134 }
6135
6136 @@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6137 /* make sure it can fit in the remaining address space */
6138 if (likely(addr > len)) {
6139 vma = find_vma(mm, addr-len);
6140 - if (!vma || addr <= vma->vm_start) {
6141 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6142 /* remember the address as a hint for next time */
6143 return (mm->free_area_cache = addr-len);
6144 }
6145 @@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6146 if (unlikely(mm->mmap_base < len))
6147 goto bottomup;
6148
6149 - addr = mm->mmap_base-len;
6150 - if (do_colour_align)
6151 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6152 + addr = mm->mmap_base - len;
6153
6154 do {
6155 + if (do_colour_align)
6156 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6157 /*
6158 * Lookup failure means no vma is above this address,
6159 * else if new region fits below vma->vm_start,
6160 * return with success:
6161 */
6162 vma = find_vma(mm, addr);
6163 - if (likely(!vma || addr+len <= vma->vm_start)) {
6164 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6165 /* remember the address as a hint for next time */
6166 return (mm->free_area_cache = addr);
6167 }
6168 @@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6169 mm->cached_hole_size = vma->vm_start - addr;
6170
6171 /* try just below the current vma->vm_start */
6172 - addr = vma->vm_start-len;
6173 - if (do_colour_align)
6174 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6175 - } while (likely(len < vma->vm_start));
6176 + addr = skip_heap_stack_gap(vma, len, offset);
6177 + } while (!IS_ERR_VALUE(addr));
6178
6179 bottomup:
6180 /*
6181 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6182 index be56a24..443328f 100644
6183 --- a/arch/sparc/include/asm/atomic_64.h
6184 +++ b/arch/sparc/include/asm/atomic_64.h
6185 @@ -14,18 +14,40 @@
6186 #define ATOMIC64_INIT(i) { (i) }
6187
6188 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6189 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6190 +{
6191 + return v->counter;
6192 +}
6193 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6194 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6195 +{
6196 + return v->counter;
6197 +}
6198
6199 #define atomic_set(v, i) (((v)->counter) = i)
6200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6201 +{
6202 + v->counter = i;
6203 +}
6204 #define atomic64_set(v, i) (((v)->counter) = i)
6205 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6206 +{
6207 + v->counter = i;
6208 +}
6209
6210 extern void atomic_add(int, atomic_t *);
6211 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6212 extern void atomic64_add(long, atomic64_t *);
6213 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6214 extern void atomic_sub(int, atomic_t *);
6215 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6216 extern void atomic64_sub(long, atomic64_t *);
6217 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6218
6219 extern int atomic_add_ret(int, atomic_t *);
6220 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6221 extern long atomic64_add_ret(long, atomic64_t *);
6222 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6223 extern int atomic_sub_ret(int, atomic_t *);
6224 extern long atomic64_sub_ret(long, atomic64_t *);
6225
6226 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6227 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6228
6229 #define atomic_inc_return(v) atomic_add_ret(1, v)
6230 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6231 +{
6232 + return atomic_add_ret_unchecked(1, v);
6233 +}
6234 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6235 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6236 +{
6237 + return atomic64_add_ret_unchecked(1, v);
6238 +}
6239
6240 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6241 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6242
6243 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6244 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6245 +{
6246 + return atomic_add_ret_unchecked(i, v);
6247 +}
6248 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6249 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6250 +{
6251 + return atomic64_add_ret_unchecked(i, v);
6252 +}
6253
6254 /*
6255 * atomic_inc_and_test - increment and test
6256 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6257 * other cases.
6258 */
6259 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6260 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6261 +{
6262 + return atomic_inc_return_unchecked(v) == 0;
6263 +}
6264 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6265
6266 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6267 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6268 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6269
6270 #define atomic_inc(v) atomic_add(1, v)
6271 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6272 +{
6273 + atomic_add_unchecked(1, v);
6274 +}
6275 #define atomic64_inc(v) atomic64_add(1, v)
6276 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6277 +{
6278 + atomic64_add_unchecked(1, v);
6279 +}
6280
6281 #define atomic_dec(v) atomic_sub(1, v)
6282 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6283 +{
6284 + atomic_sub_unchecked(1, v);
6285 +}
6286 #define atomic64_dec(v) atomic64_sub(1, v)
6287 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6288 +{
6289 + atomic64_sub_unchecked(1, v);
6290 +}
6291
6292 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6293 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6294
6295 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6296 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6297 +{
6298 + return cmpxchg(&v->counter, old, new);
6299 +}
6300 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6301 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6302 +{
6303 + return xchg(&v->counter, new);
6304 +}
6305
6306 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6307 {
6308 - int c, old;
6309 + int c, old, new;
6310 c = atomic_read(v);
6311 for (;;) {
6312 - if (unlikely(c == (u)))
6313 + if (unlikely(c == u))
6314 break;
6315 - old = atomic_cmpxchg((v), c, c + (a));
6316 +
6317 + asm volatile("addcc %2, %0, %0\n"
6318 +
6319 +#ifdef CONFIG_PAX_REFCOUNT
6320 + "tvs %%icc, 6\n"
6321 +#endif
6322 +
6323 + : "=r" (new)
6324 + : "0" (c), "ir" (a)
6325 + : "cc");
6326 +
6327 + old = atomic_cmpxchg(v, c, new);
6328 if (likely(old == c))
6329 break;
6330 c = old;
6331 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6332 #define atomic64_cmpxchg(v, o, n) \
6333 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6334 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6335 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6336 +{
6337 + return xchg(&v->counter, new);
6338 +}
6339
6340 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6341 {
6342 - long c, old;
6343 + long c, old, new;
6344 c = atomic64_read(v);
6345 for (;;) {
6346 - if (unlikely(c == (u)))
6347 + if (unlikely(c == u))
6348 break;
6349 - old = atomic64_cmpxchg((v), c, c + (a));
6350 +
6351 + asm volatile("addcc %2, %0, %0\n"
6352 +
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + "tvs %%xcc, 6\n"
6355 +#endif
6356 +
6357 + : "=r" (new)
6358 + : "0" (c), "ir" (a)
6359 + : "cc");
6360 +
6361 + old = atomic64_cmpxchg(v, c, new);
6362 if (likely(old == c))
6363 break;
6364 c = old;
6365 }
6366 - return c != (u);
6367 + return c != u;
6368 }
6369
6370 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6371 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6372 index 5bb6991..5c2132e 100644
6373 --- a/arch/sparc/include/asm/cache.h
6374 +++ b/arch/sparc/include/asm/cache.h
6375 @@ -7,10 +7,12 @@
6376 #ifndef _SPARC_CACHE_H
6377 #define _SPARC_CACHE_H
6378
6379 +#include <linux/const.h>
6380 +
6381 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6382
6383 #define L1_CACHE_SHIFT 5
6384 -#define L1_CACHE_BYTES 32
6385 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6386
6387 #ifdef CONFIG_SPARC32
6388 #define SMP_CACHE_BYTES_SHIFT 5
6389 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6390 index ac74a2c..a9e58af 100644
6391 --- a/arch/sparc/include/asm/elf_32.h
6392 +++ b/arch/sparc/include/asm/elf_32.h
6393 @@ -114,6 +114,13 @@ typedef struct {
6394
6395 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6396
6397 +#ifdef CONFIG_PAX_ASLR
6398 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6399 +
6400 +#define PAX_DELTA_MMAP_LEN 16
6401 +#define PAX_DELTA_STACK_LEN 16
6402 +#endif
6403 +
6404 /* This yields a mask that user programs can use to figure out what
6405 instruction set this cpu supports. This can NOT be done in userspace
6406 on Sparc. */
6407 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6408 index 370ca1e..d4f4a98 100644
6409 --- a/arch/sparc/include/asm/elf_64.h
6410 +++ b/arch/sparc/include/asm/elf_64.h
6411 @@ -189,6 +189,13 @@ typedef struct {
6412 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6413 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6414
6415 +#ifdef CONFIG_PAX_ASLR
6416 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6417 +
6418 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6419 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6420 +#endif
6421 +
6422 extern unsigned long sparc64_elf_hwcap;
6423 #define ELF_HWCAP sparc64_elf_hwcap
6424
6425 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6426 index 9b1c36d..209298b 100644
6427 --- a/arch/sparc/include/asm/pgalloc_32.h
6428 +++ b/arch/sparc/include/asm/pgalloc_32.h
6429 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6430 }
6431
6432 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6433 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6434
6435 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6436 unsigned long address)
6437 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6438 index bcfe063..b333142 100644
6439 --- a/arch/sparc/include/asm/pgalloc_64.h
6440 +++ b/arch/sparc/include/asm/pgalloc_64.h
6441 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6442 }
6443
6444 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6445 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6446
6447 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6448 {
6449 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6450 index 6fc1348..390c50a 100644
6451 --- a/arch/sparc/include/asm/pgtable_32.h
6452 +++ b/arch/sparc/include/asm/pgtable_32.h
6453 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6454 #define PAGE_SHARED SRMMU_PAGE_SHARED
6455 #define PAGE_COPY SRMMU_PAGE_COPY
6456 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6457 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6458 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6459 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6460 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6461
6462 /* Top-level page directory - dummy used by init-mm.
6463 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6464
6465 /* xwr */
6466 #define __P000 PAGE_NONE
6467 -#define __P001 PAGE_READONLY
6468 -#define __P010 PAGE_COPY
6469 -#define __P011 PAGE_COPY
6470 +#define __P001 PAGE_READONLY_NOEXEC
6471 +#define __P010 PAGE_COPY_NOEXEC
6472 +#define __P011 PAGE_COPY_NOEXEC
6473 #define __P100 PAGE_READONLY
6474 #define __P101 PAGE_READONLY
6475 #define __P110 PAGE_COPY
6476 #define __P111 PAGE_COPY
6477
6478 #define __S000 PAGE_NONE
6479 -#define __S001 PAGE_READONLY
6480 -#define __S010 PAGE_SHARED
6481 -#define __S011 PAGE_SHARED
6482 +#define __S001 PAGE_READONLY_NOEXEC
6483 +#define __S010 PAGE_SHARED_NOEXEC
6484 +#define __S011 PAGE_SHARED_NOEXEC
6485 #define __S100 PAGE_READONLY
6486 #define __S101 PAGE_READONLY
6487 #define __S110 PAGE_SHARED
6488 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6489 index 79da178..c2eede8 100644
6490 --- a/arch/sparc/include/asm/pgtsrmmu.h
6491 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6492 @@ -115,6 +115,11 @@
6493 SRMMU_EXEC | SRMMU_REF)
6494 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6495 SRMMU_EXEC | SRMMU_REF)
6496 +
6497 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6498 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6499 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6500 +
6501 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6502 SRMMU_DIRTY | SRMMU_REF)
6503
6504 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6505 index 9689176..63c18ea 100644
6506 --- a/arch/sparc/include/asm/spinlock_64.h
6507 +++ b/arch/sparc/include/asm/spinlock_64.h
6508 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6509
6510 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6511
6512 -static void inline arch_read_lock(arch_rwlock_t *lock)
6513 +static inline void arch_read_lock(arch_rwlock_t *lock)
6514 {
6515 unsigned long tmp1, tmp2;
6516
6517 __asm__ __volatile__ (
6518 "1: ldsw [%2], %0\n"
6519 " brlz,pn %0, 2f\n"
6520 -"4: add %0, 1, %1\n"
6521 +"4: addcc %0, 1, %1\n"
6522 +
6523 +#ifdef CONFIG_PAX_REFCOUNT
6524 +" tvs %%icc, 6\n"
6525 +#endif
6526 +
6527 " cas [%2], %0, %1\n"
6528 " cmp %0, %1\n"
6529 " bne,pn %%icc, 1b\n"
6530 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6531 " .previous"
6532 : "=&r" (tmp1), "=&r" (tmp2)
6533 : "r" (lock)
6534 - : "memory");
6535 + : "memory", "cc");
6536 }
6537
6538 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6539 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6540 {
6541 int tmp1, tmp2;
6542
6543 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6544 "1: ldsw [%2], %0\n"
6545 " brlz,a,pn %0, 2f\n"
6546 " mov 0, %0\n"
6547 -" add %0, 1, %1\n"
6548 +" addcc %0, 1, %1\n"
6549 +
6550 +#ifdef CONFIG_PAX_REFCOUNT
6551 +" tvs %%icc, 6\n"
6552 +#endif
6553 +
6554 " cas [%2], %0, %1\n"
6555 " cmp %0, %1\n"
6556 " bne,pn %%icc, 1b\n"
6557 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6558 return tmp1;
6559 }
6560
6561 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6562 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6563 {
6564 unsigned long tmp1, tmp2;
6565
6566 __asm__ __volatile__(
6567 "1: lduw [%2], %0\n"
6568 -" sub %0, 1, %1\n"
6569 +" subcc %0, 1, %1\n"
6570 +
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 +" tvs %%icc, 6\n"
6573 +#endif
6574 +
6575 " cas [%2], %0, %1\n"
6576 " cmp %0, %1\n"
6577 " bne,pn %%xcc, 1b\n"
6578 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6579 : "memory");
6580 }
6581
6582 -static void inline arch_write_lock(arch_rwlock_t *lock)
6583 +static inline void arch_write_lock(arch_rwlock_t *lock)
6584 {
6585 unsigned long mask, tmp1, tmp2;
6586
6587 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6588 : "memory");
6589 }
6590
6591 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6592 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6593 {
6594 __asm__ __volatile__(
6595 " stw %%g0, [%0]"
6596 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6597 : "memory");
6598 }
6599
6600 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6601 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6602 {
6603 unsigned long mask, tmp1, tmp2, result;
6604
6605 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6606 index 25849ae..924c54b 100644
6607 --- a/arch/sparc/include/asm/thread_info_32.h
6608 +++ b/arch/sparc/include/asm/thread_info_32.h
6609 @@ -49,6 +49,8 @@ struct thread_info {
6610 unsigned long w_saved;
6611
6612 struct restart_block restart_block;
6613 +
6614 + unsigned long lowest_stack;
6615 };
6616
6617 /*
6618 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6619 index a3fe4dc..cae132a 100644
6620 --- a/arch/sparc/include/asm/thread_info_64.h
6621 +++ b/arch/sparc/include/asm/thread_info_64.h
6622 @@ -63,6 +63,8 @@ struct thread_info {
6623 struct pt_regs *kern_una_regs;
6624 unsigned int kern_una_insn;
6625
6626 + unsigned long lowest_stack;
6627 +
6628 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6629 };
6630
6631 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6632 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6633 /* flag bit 6 is available */
6634 #define TIF_32BIT 7 /* 32-bit binary */
6635 -/* flag bit 8 is available */
6636 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6637 #define TIF_SECCOMP 9 /* secure computing */
6638 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6639 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6640 +
6641 /* NOTE: Thread flags >= 12 should be ones we have no interest
6642 * in using in assembly, else we can't use the mask as
6643 * an immediate value in instructions such as andcc.
6644 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6645 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6646 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6647 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6648 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6649
6650 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6651 _TIF_DO_NOTIFY_RESUME_MASK | \
6652 _TIF_NEED_RESCHED)
6653 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6654
6655 +#define _TIF_WORK_SYSCALL \
6656 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6657 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6658 +
6659 +
6660 /*
6661 * Thread-synchronous status.
6662 *
6663 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6664 index 0167d26..9acd8ed 100644
6665 --- a/arch/sparc/include/asm/uaccess.h
6666 +++ b/arch/sparc/include/asm/uaccess.h
6667 @@ -1,5 +1,13 @@
6668 #ifndef ___ASM_SPARC_UACCESS_H
6669 #define ___ASM_SPARC_UACCESS_H
6670 +
6671 +#ifdef __KERNEL__
6672 +#ifndef __ASSEMBLY__
6673 +#include <linux/types.h>
6674 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6675 +#endif
6676 +#endif
6677 +
6678 #if defined(__sparc__) && defined(__arch64__)
6679 #include <asm/uaccess_64.h>
6680 #else
6681 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6682 index 53a28dd..50c38c3 100644
6683 --- a/arch/sparc/include/asm/uaccess_32.h
6684 +++ b/arch/sparc/include/asm/uaccess_32.h
6685 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6686
6687 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 {
6689 - if (n && __access_ok((unsigned long) to, n))
6690 + if ((long)n < 0)
6691 + return n;
6692 +
6693 + if (n && __access_ok((unsigned long) to, n)) {
6694 + if (!__builtin_constant_p(n))
6695 + check_object_size(from, n, true);
6696 return __copy_user(to, (__force void __user *) from, n);
6697 - else
6698 + } else
6699 return n;
6700 }
6701
6702 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6703 {
6704 + if ((long)n < 0)
6705 + return n;
6706 +
6707 + if (!__builtin_constant_p(n))
6708 + check_object_size(from, n, true);
6709 +
6710 return __copy_user(to, (__force void __user *) from, n);
6711 }
6712
6713 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6714 {
6715 - if (n && __access_ok((unsigned long) from, n))
6716 + if ((long)n < 0)
6717 + return n;
6718 +
6719 + if (n && __access_ok((unsigned long) from, n)) {
6720 + if (!__builtin_constant_p(n))
6721 + check_object_size(to, n, false);
6722 return __copy_user((__force void __user *) to, from, n);
6723 - else
6724 + } else
6725 return n;
6726 }
6727
6728 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6729 {
6730 + if ((long)n < 0)
6731 + return n;
6732 +
6733 return __copy_user((__force void __user *) to, from, n);
6734 }
6735
6736 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6737 index 73083e1..2bc62a6 100644
6738 --- a/arch/sparc/include/asm/uaccess_64.h
6739 +++ b/arch/sparc/include/asm/uaccess_64.h
6740 @@ -10,6 +10,7 @@
6741 #include <linux/compiler.h>
6742 #include <linux/string.h>
6743 #include <linux/thread_info.h>
6744 +#include <linux/kernel.h>
6745 #include <asm/asi.h>
6746 #include <asm/spitfire.h>
6747 #include <asm-generic/uaccess-unaligned.h>
6748 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6749 static inline unsigned long __must_check
6750 copy_from_user(void *to, const void __user *from, unsigned long size)
6751 {
6752 - unsigned long ret = ___copy_from_user(to, from, size);
6753 + unsigned long ret;
6754
6755 + if ((long)size < 0 || size > INT_MAX)
6756 + return size;
6757 +
6758 + if (!__builtin_constant_p(size))
6759 + check_object_size(to, size, false);
6760 +
6761 + ret = ___copy_from_user(to, from, size);
6762 if (unlikely(ret))
6763 ret = copy_from_user_fixup(to, from, size);
6764
6765 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6766 static inline unsigned long __must_check
6767 copy_to_user(void __user *to, const void *from, unsigned long size)
6768 {
6769 - unsigned long ret = ___copy_to_user(to, from, size);
6770 + unsigned long ret;
6771
6772 + if ((long)size < 0 || size > INT_MAX)
6773 + return size;
6774 +
6775 + if (!__builtin_constant_p(size))
6776 + check_object_size(from, size, true);
6777 +
6778 + ret = ___copy_to_user(to, from, size);
6779 if (unlikely(ret))
6780 ret = copy_to_user_fixup(to, from, size);
6781 return ret;
6782 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6783 index 6cf591b..b49e65a 100644
6784 --- a/arch/sparc/kernel/Makefile
6785 +++ b/arch/sparc/kernel/Makefile
6786 @@ -3,7 +3,7 @@
6787 #
6788
6789 asflags-y := -ansi
6790 -ccflags-y := -Werror
6791 +#ccflags-y := -Werror
6792
6793 extra-y := head_$(BITS).o
6794
6795 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6796 index 487bffb..955a925 100644
6797 --- a/arch/sparc/kernel/process_32.c
6798 +++ b/arch/sparc/kernel/process_32.c
6799 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6800
6801 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6802 r->psr, r->pc, r->npc, r->y, print_tainted());
6803 - printk("PC: <%pS>\n", (void *) r->pc);
6804 + printk("PC: <%pA>\n", (void *) r->pc);
6805 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6806 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6807 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6808 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6809 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6810 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6811 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6812 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6813
6814 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6815 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6816 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6817 rw = (struct reg_window32 *) fp;
6818 pc = rw->ins[7];
6819 printk("[%08lx : ", pc);
6820 - printk("%pS ] ", (void *) pc);
6821 + printk("%pA ] ", (void *) pc);
6822 fp = rw->ins[6];
6823 } while (++count < 16);
6824 printk("\n");
6825 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6826 index c6e0c29..052832b 100644
6827 --- a/arch/sparc/kernel/process_64.c
6828 +++ b/arch/sparc/kernel/process_64.c
6829 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6830 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6831 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6832 if (regs->tstate & TSTATE_PRIV)
6833 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6834 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6835 }
6836
6837 void show_regs(struct pt_regs *regs)
6838 {
6839 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6840 regs->tpc, regs->tnpc, regs->y, print_tainted());
6841 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6842 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6843 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6844 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6845 regs->u_regs[3]);
6846 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6847 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6848 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6849 regs->u_regs[15]);
6850 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6851 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6852 show_regwindow(regs);
6853 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6854 }
6855 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6856 ((tp && tp->task) ? tp->task->pid : -1));
6857
6858 if (gp->tstate & TSTATE_PRIV) {
6859 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6860 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6861 (void *) gp->tpc,
6862 (void *) gp->o7,
6863 (void *) gp->i7,
6864 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6865 index 7ff45e4..a58f271 100644
6866 --- a/arch/sparc/kernel/ptrace_64.c
6867 +++ b/arch/sparc/kernel/ptrace_64.c
6868 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6869 return ret;
6870 }
6871
6872 +#ifdef CONFIG_GRKERNSEC_SETXID
6873 +extern void gr_delayed_cred_worker(void);
6874 +#endif
6875 +
6876 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6877 {
6878 int ret = 0;
6879 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6880 /* do the secure computing check first */
6881 secure_computing_strict(regs->u_regs[UREG_G1]);
6882
6883 +#ifdef CONFIG_GRKERNSEC_SETXID
6884 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6885 + gr_delayed_cred_worker();
6886 +#endif
6887 +
6888 if (test_thread_flag(TIF_SYSCALL_TRACE))
6889 ret = tracehook_report_syscall_entry(regs);
6890
6891 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6892
6893 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6894 {
6895 +#ifdef CONFIG_GRKERNSEC_SETXID
6896 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6897 + gr_delayed_cred_worker();
6898 +#endif
6899 +
6900 audit_syscall_exit(regs);
6901
6902 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6903 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6904 index 0c9b31b..55a8ba6 100644
6905 --- a/arch/sparc/kernel/sys_sparc_32.c
6906 +++ b/arch/sparc/kernel/sys_sparc_32.c
6907 @@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6908 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6909 {
6910 struct vm_area_struct * vmm;
6911 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6912
6913 if (flags & MAP_FIXED) {
6914 /* We do not accept a shared mapping if it would violate
6915 @@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6916 if (len > TASK_SIZE - PAGE_SIZE)
6917 return -ENOMEM;
6918 if (!addr)
6919 - addr = TASK_UNMAPPED_BASE;
6920 + addr = current->mm->mmap_base;
6921
6922 if (flags & MAP_SHARED)
6923 addr = COLOUR_ALIGN(addr);
6924 @@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6925 /* At this point: (!vmm || addr < vmm->vm_end). */
6926 if (TASK_SIZE - PAGE_SIZE - len < addr)
6927 return -ENOMEM;
6928 - if (!vmm || addr + len <= vmm->vm_start)
6929 + if (check_heap_stack_gap(vmm, addr, len, offset))
6930 return addr;
6931 addr = vmm->vm_end;
6932 if (flags & MAP_SHARED)
6933 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6934 index 878ef3d..f100719 100644
6935 --- a/arch/sparc/kernel/sys_sparc_64.c
6936 +++ b/arch/sparc/kernel/sys_sparc_64.c
6937 @@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6938 unsigned long task_size = TASK_SIZE;
6939 unsigned long start_addr;
6940 int do_color_align;
6941 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6942
6943 if (flags & MAP_FIXED) {
6944 /* We do not accept a shared mapping if it would violate
6945 * cache aliasing constraints.
6946 */
6947 - if ((flags & MAP_SHARED) &&
6948 + if ((filp || (flags & MAP_SHARED)) &&
6949 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6950 return -EINVAL;
6951 return addr;
6952 @@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6953 if (filp || (flags & MAP_SHARED))
6954 do_color_align = 1;
6955
6956 +#ifdef CONFIG_PAX_RANDMMAP
6957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958 +#endif
6959 +
6960 if (addr) {
6961 if (do_color_align)
6962 addr = COLOUR_ALIGN(addr, pgoff);
6963 @@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6964 addr = PAGE_ALIGN(addr);
6965
6966 vma = find_vma(mm, addr);
6967 - if (task_size - len >= addr &&
6968 - (!vma || addr + len <= vma->vm_start))
6969 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6970 return addr;
6971 }
6972
6973 if (len > mm->cached_hole_size) {
6974 - start_addr = addr = mm->free_area_cache;
6975 + start_addr = addr = mm->free_area_cache;
6976 } else {
6977 - start_addr = addr = TASK_UNMAPPED_BASE;
6978 + start_addr = addr = mm->mmap_base;
6979 mm->cached_hole_size = 0;
6980 }
6981
6982 @@ -157,14 +161,14 @@ full_search:
6983 vma = find_vma(mm, VA_EXCLUDE_END);
6984 }
6985 if (unlikely(task_size < addr)) {
6986 - if (start_addr != TASK_UNMAPPED_BASE) {
6987 - start_addr = addr = TASK_UNMAPPED_BASE;
6988 + if (start_addr != mm->mmap_base) {
6989 + start_addr = addr = mm->mmap_base;
6990 mm->cached_hole_size = 0;
6991 goto full_search;
6992 }
6993 return -ENOMEM;
6994 }
6995 - if (likely(!vma || addr + len <= vma->vm_start)) {
6996 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6997 /*
6998 * Remember the place where we stopped the search:
6999 */
7000 @@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7001 unsigned long task_size = STACK_TOP32;
7002 unsigned long addr = addr0;
7003 int do_color_align;
7004 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7005
7006 /* This should only ever run for 32-bit processes. */
7007 BUG_ON(!test_thread_flag(TIF_32BIT));
7008 @@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7009 /* We do not accept a shared mapping if it would violate
7010 * cache aliasing constraints.
7011 */
7012 - if ((flags & MAP_SHARED) &&
7013 + if ((filp || (flags & MAP_SHARED)) &&
7014 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
7015 return -EINVAL;
7016 return addr;
7017 @@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7018 addr = PAGE_ALIGN(addr);
7019
7020 vma = find_vma(mm, addr);
7021 - if (task_size - len >= addr &&
7022 - (!vma || addr + len <= vma->vm_start))
7023 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7024 return addr;
7025 }
7026
7027 @@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7028 /* make sure it can fit in the remaining address space */
7029 if (likely(addr > len)) {
7030 vma = find_vma(mm, addr-len);
7031 - if (!vma || addr <= vma->vm_start) {
7032 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
7033 /* remember the address as a hint for next time */
7034 return (mm->free_area_cache = addr-len);
7035 }
7036 @@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7037 if (unlikely(mm->mmap_base < len))
7038 goto bottomup;
7039
7040 - addr = mm->mmap_base-len;
7041 - if (do_color_align)
7042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7043 + addr = mm->mmap_base - len;
7044
7045 do {
7046 + if (do_color_align)
7047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7048 /*
7049 * Lookup failure means no vma is above this address,
7050 * else if new region fits below vma->vm_start,
7051 * return with success:
7052 */
7053 vma = find_vma(mm, addr);
7054 - if (likely(!vma || addr+len <= vma->vm_start)) {
7055 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
7056 /* remember the address as a hint for next time */
7057 return (mm->free_area_cache = addr);
7058 }
7059 @@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7060 mm->cached_hole_size = vma->vm_start - addr;
7061
7062 /* try just below the current vma->vm_start */
7063 - addr = vma->vm_start-len;
7064 - if (do_color_align)
7065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7066 - } while (likely(len < vma->vm_start));
7067 + addr = skip_heap_stack_gap(vma, len, offset);
7068 + } while (!IS_ERR_VALUE(addr));
7069
7070 bottomup:
7071 /*
7072 @@ -348,6 +350,10 @@ static unsigned long mmap_rnd(void)
7073 {
7074 unsigned long rnd = 0UL;
7075
7076 +#ifdef CONFIG_PAX_RANDMMAP
7077 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7078 +#endif
7079 +
7080 if (current->flags & PF_RANDOMIZE) {
7081 unsigned long val = get_random_int();
7082 if (test_thread_flag(TIF_32BIT))
7083 @@ -373,6 +379,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7084 gap == RLIM_INFINITY ||
7085 sysctl_legacy_va_layout) {
7086 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7087 +
7088 +#ifdef CONFIG_PAX_RANDMMAP
7089 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7090 + mm->mmap_base += mm->delta_mmap;
7091 +#endif
7092 +
7093 mm->get_unmapped_area = arch_get_unmapped_area;
7094 mm->unmap_area = arch_unmap_area;
7095 } else {
7096 @@ -385,6 +397,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7097 gap = (task_size / 6 * 5);
7098
7099 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7100 +
7101 +#ifdef CONFIG_PAX_RANDMMAP
7102 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7103 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104 +#endif
7105 +
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 mm->unmap_area = arch_unmap_area_topdown;
7108 }
7109 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7110 index bf23477..b7425a6 100644
7111 --- a/arch/sparc/kernel/syscalls.S
7112 +++ b/arch/sparc/kernel/syscalls.S
7113 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7114 #endif
7115 .align 32
7116 1: ldx [%g6 + TI_FLAGS], %l5
7117 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7118 + andcc %l5, _TIF_WORK_SYSCALL, %g0
7119 be,pt %icc, rtrap
7120 nop
7121 call syscall_trace_leave
7122 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
7123
7124 srl %i5, 0, %o5 ! IEU1
7125 srl %i2, 0, %o2 ! IEU0 Group
7126 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7127 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7128 bne,pn %icc, linux_syscall_trace32 ! CTI
7129 mov %i0, %l5 ! IEU1
7130 call %l7 ! CTI Group brk forced
7131 @@ -212,7 +212,7 @@ linux_sparc_syscall:
7132
7133 mov %i3, %o3 ! IEU1
7134 mov %i4, %o4 ! IEU0 Group
7135 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7136 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7137 bne,pn %icc, linux_syscall_trace ! CTI Group
7138 mov %i0, %l5 ! IEU0
7139 2: call %l7 ! CTI Group brk forced
7140 @@ -228,7 +228,7 @@ ret_sys_call:
7141
7142 cmp %o0, -ERESTART_RESTARTBLOCK
7143 bgeu,pn %xcc, 1f
7144 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7145 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7146 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7147
7148 2:
7149 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7150 index a5785ea..405c5f7 100644
7151 --- a/arch/sparc/kernel/traps_32.c
7152 +++ b/arch/sparc/kernel/traps_32.c
7153 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7154 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7155 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7156
7157 +extern void gr_handle_kernel_exploit(void);
7158 +
7159 void die_if_kernel(char *str, struct pt_regs *regs)
7160 {
7161 static int die_counter;
7162 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7163 count++ < 30 &&
7164 (((unsigned long) rw) >= PAGE_OFFSET) &&
7165 !(((unsigned long) rw) & 0x7)) {
7166 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
7167 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
7168 (void *) rw->ins[7]);
7169 rw = (struct reg_window32 *)rw->ins[6];
7170 }
7171 }
7172 printk("Instruction DUMP:");
7173 instruction_dump ((unsigned long *) regs->pc);
7174 - if(regs->psr & PSR_PS)
7175 + if(regs->psr & PSR_PS) {
7176 + gr_handle_kernel_exploit();
7177 do_exit(SIGKILL);
7178 + }
7179 do_exit(SIGSEGV);
7180 }
7181
7182 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7183 index b66a779..8e8d66c 100644
7184 --- a/arch/sparc/kernel/traps_64.c
7185 +++ b/arch/sparc/kernel/traps_64.c
7186 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7187 i + 1,
7188 p->trapstack[i].tstate, p->trapstack[i].tpc,
7189 p->trapstack[i].tnpc, p->trapstack[i].tt);
7190 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7191 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7192 }
7193 }
7194
7195 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7196
7197 lvl -= 0x100;
7198 if (regs->tstate & TSTATE_PRIV) {
7199 +
7200 +#ifdef CONFIG_PAX_REFCOUNT
7201 + if (lvl == 6)
7202 + pax_report_refcount_overflow(regs);
7203 +#endif
7204 +
7205 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7206 die_if_kernel(buffer, regs);
7207 }
7208 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7209 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7210 {
7211 char buffer[32];
7212 -
7213 +
7214 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7215 0, lvl, SIGTRAP) == NOTIFY_STOP)
7216 return;
7217
7218 +#ifdef CONFIG_PAX_REFCOUNT
7219 + if (lvl == 6)
7220 + pax_report_refcount_overflow(regs);
7221 +#endif
7222 +
7223 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7224
7225 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7226 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7227 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7228 printk("%s" "ERROR(%d): ",
7229 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7230 - printk("TPC<%pS>\n", (void *) regs->tpc);
7231 + printk("TPC<%pA>\n", (void *) regs->tpc);
7232 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7233 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7234 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7235 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7236 smp_processor_id(),
7237 (type & 0x1) ? 'I' : 'D',
7238 regs->tpc);
7239 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7240 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7241 panic("Irrecoverable Cheetah+ parity error.");
7242 }
7243
7244 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7245 smp_processor_id(),
7246 (type & 0x1) ? 'I' : 'D',
7247 regs->tpc);
7248 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7249 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7250 }
7251
7252 struct sun4v_error_entry {
7253 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7254
7255 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7256 regs->tpc, tl);
7257 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7258 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7259 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7260 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7261 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7262 (void *) regs->u_regs[UREG_I7]);
7263 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7264 "pte[%lx] error[%lx]\n",
7265 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7266
7267 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7268 regs->tpc, tl);
7269 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7270 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7271 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7272 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7273 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7274 (void *) regs->u_regs[UREG_I7]);
7275 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7276 "pte[%lx] error[%lx]\n",
7277 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7278 fp = (unsigned long)sf->fp + STACK_BIAS;
7279 }
7280
7281 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7282 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7284 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7285 int index = tsk->curr_ret_stack;
7286 if (tsk->ret_stack && index >= graph) {
7287 pc = tsk->ret_stack[index - graph].ret;
7288 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7289 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7290 graph++;
7291 }
7292 }
7293 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7294 return (struct reg_window *) (fp + STACK_BIAS);
7295 }
7296
7297 +extern void gr_handle_kernel_exploit(void);
7298 +
7299 void die_if_kernel(char *str, struct pt_regs *regs)
7300 {
7301 static int die_counter;
7302 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7303 while (rw &&
7304 count++ < 30 &&
7305 kstack_valid(tp, (unsigned long) rw)) {
7306 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
7307 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
7308 (void *) rw->ins[7]);
7309
7310 rw = kernel_stack_up(rw);
7311 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7312 }
7313 user_instruction_dump ((unsigned int __user *) regs->tpc);
7314 }
7315 - if (regs->tstate & TSTATE_PRIV)
7316 + if (regs->tstate & TSTATE_PRIV) {
7317 + gr_handle_kernel_exploit();
7318 do_exit(SIGKILL);
7319 + }
7320 do_exit(SIGSEGV);
7321 }
7322 EXPORT_SYMBOL(die_if_kernel);
7323 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7324 index 8201c25e..072a2a7 100644
7325 --- a/arch/sparc/kernel/unaligned_64.c
7326 +++ b/arch/sparc/kernel/unaligned_64.c
7327 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7328 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7329
7330 if (__ratelimit(&ratelimit)) {
7331 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7332 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7333 regs->tpc, (void *) regs->tpc);
7334 }
7335 }
7336 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7337 index 8410065f2..4fd4ca22 100644
7338 --- a/arch/sparc/lib/Makefile
7339 +++ b/arch/sparc/lib/Makefile
7340 @@ -2,7 +2,7 @@
7341 #
7342
7343 asflags-y := -ansi -DST_DIV0=0x02
7344 -ccflags-y := -Werror
7345 +#ccflags-y := -Werror
7346
7347 lib-$(CONFIG_SPARC32) += ashrdi3.o
7348 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7349 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7350 index 85c233d..68500e0 100644
7351 --- a/arch/sparc/lib/atomic_64.S
7352 +++ b/arch/sparc/lib/atomic_64.S
7353 @@ -17,7 +17,12 @@
7354 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7355 BACKOFF_SETUP(%o2)
7356 1: lduw [%o1], %g1
7357 - add %g1, %o0, %g7
7358 + addcc %g1, %o0, %g7
7359 +
7360 +#ifdef CONFIG_PAX_REFCOUNT
7361 + tvs %icc, 6
7362 +#endif
7363 +
7364 cas [%o1], %g1, %g7
7365 cmp %g1, %g7
7366 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7367 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7368 2: BACKOFF_SPIN(%o2, %o3, 1b)
7369 ENDPROC(atomic_add)
7370
7371 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7372 + BACKOFF_SETUP(%o2)
7373 +1: lduw [%o1], %g1
7374 + add %g1, %o0, %g7
7375 + cas [%o1], %g1, %g7
7376 + cmp %g1, %g7
7377 + bne,pn %icc, 2f
7378 + nop
7379 + retl
7380 + nop
7381 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7382 +ENDPROC(atomic_add_unchecked)
7383 +
7384 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7385 BACKOFF_SETUP(%o2)
7386 1: lduw [%o1], %g1
7387 - sub %g1, %o0, %g7
7388 + subcc %g1, %o0, %g7
7389 +
7390 +#ifdef CONFIG_PAX_REFCOUNT
7391 + tvs %icc, 6
7392 +#endif
7393 +
7394 cas [%o1], %g1, %g7
7395 cmp %g1, %g7
7396 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7397 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7398 2: BACKOFF_SPIN(%o2, %o3, 1b)
7399 ENDPROC(atomic_sub)
7400
7401 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7402 + BACKOFF_SETUP(%o2)
7403 +1: lduw [%o1], %g1
7404 + sub %g1, %o0, %g7
7405 + cas [%o1], %g1, %g7
7406 + cmp %g1, %g7
7407 + bne,pn %icc, 2f
7408 + nop
7409 + retl
7410 + nop
7411 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7412 +ENDPROC(atomic_sub_unchecked)
7413 +
7414 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7415 BACKOFF_SETUP(%o2)
7416 1: lduw [%o1], %g1
7417 - add %g1, %o0, %g7
7418 + addcc %g1, %o0, %g7
7419 +
7420 +#ifdef CONFIG_PAX_REFCOUNT
7421 + tvs %icc, 6
7422 +#endif
7423 +
7424 cas [%o1], %g1, %g7
7425 cmp %g1, %g7
7426 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7427 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7428 2: BACKOFF_SPIN(%o2, %o3, 1b)
7429 ENDPROC(atomic_add_ret)
7430
7431 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7432 + BACKOFF_SETUP(%o2)
7433 +1: lduw [%o1], %g1
7434 + addcc %g1, %o0, %g7
7435 + cas [%o1], %g1, %g7
7436 + cmp %g1, %g7
7437 + bne,pn %icc, 2f
7438 + add %g7, %o0, %g7
7439 + sra %g7, 0, %o0
7440 + retl
7441 + nop
7442 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7443 +ENDPROC(atomic_add_ret_unchecked)
7444 +
7445 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7446 BACKOFF_SETUP(%o2)
7447 1: lduw [%o1], %g1
7448 - sub %g1, %o0, %g7
7449 + subcc %g1, %o0, %g7
7450 +
7451 +#ifdef CONFIG_PAX_REFCOUNT
7452 + tvs %icc, 6
7453 +#endif
7454 +
7455 cas [%o1], %g1, %g7
7456 cmp %g1, %g7
7457 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7458 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7459 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7460 BACKOFF_SETUP(%o2)
7461 1: ldx [%o1], %g1
7462 - add %g1, %o0, %g7
7463 + addcc %g1, %o0, %g7
7464 +
7465 +#ifdef CONFIG_PAX_REFCOUNT
7466 + tvs %xcc, 6
7467 +#endif
7468 +
7469 casx [%o1], %g1, %g7
7470 cmp %g1, %g7
7471 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7472 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7473 2: BACKOFF_SPIN(%o2, %o3, 1b)
7474 ENDPROC(atomic64_add)
7475
7476 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7477 + BACKOFF_SETUP(%o2)
7478 +1: ldx [%o1], %g1
7479 + addcc %g1, %o0, %g7
7480 + casx [%o1], %g1, %g7
7481 + cmp %g1, %g7
7482 + bne,pn %xcc, 2f
7483 + nop
7484 + retl
7485 + nop
7486 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7487 +ENDPROC(atomic64_add_unchecked)
7488 +
7489 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7490 BACKOFF_SETUP(%o2)
7491 1: ldx [%o1], %g1
7492 - sub %g1, %o0, %g7
7493 + subcc %g1, %o0, %g7
7494 +
7495 +#ifdef CONFIG_PAX_REFCOUNT
7496 + tvs %xcc, 6
7497 +#endif
7498 +
7499 casx [%o1], %g1, %g7
7500 cmp %g1, %g7
7501 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7502 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7503 2: BACKOFF_SPIN(%o2, %o3, 1b)
7504 ENDPROC(atomic64_sub)
7505
7506 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7507 + BACKOFF_SETUP(%o2)
7508 +1: ldx [%o1], %g1
7509 + subcc %g1, %o0, %g7
7510 + casx [%o1], %g1, %g7
7511 + cmp %g1, %g7
7512 + bne,pn %xcc, 2f
7513 + nop
7514 + retl
7515 + nop
7516 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7517 +ENDPROC(atomic64_sub_unchecked)
7518 +
7519 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7520 BACKOFF_SETUP(%o2)
7521 1: ldx [%o1], %g1
7522 - add %g1, %o0, %g7
7523 + addcc %g1, %o0, %g7
7524 +
7525 +#ifdef CONFIG_PAX_REFCOUNT
7526 + tvs %xcc, 6
7527 +#endif
7528 +
7529 casx [%o1], %g1, %g7
7530 cmp %g1, %g7
7531 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7532 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7533 2: BACKOFF_SPIN(%o2, %o3, 1b)
7534 ENDPROC(atomic64_add_ret)
7535
7536 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7537 + BACKOFF_SETUP(%o2)
7538 +1: ldx [%o1], %g1
7539 + addcc %g1, %o0, %g7
7540 + casx [%o1], %g1, %g7
7541 + cmp %g1, %g7
7542 + bne,pn %xcc, 2f
7543 + add %g7, %o0, %g7
7544 + mov %g7, %o0
7545 + retl
7546 + nop
7547 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7548 +ENDPROC(atomic64_add_ret_unchecked)
7549 +
7550 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7551 BACKOFF_SETUP(%o2)
7552 1: ldx [%o1], %g1
7553 - sub %g1, %o0, %g7
7554 + subcc %g1, %o0, %g7
7555 +
7556 +#ifdef CONFIG_PAX_REFCOUNT
7557 + tvs %xcc, 6
7558 +#endif
7559 +
7560 casx [%o1], %g1, %g7
7561 cmp %g1, %g7
7562 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7563 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7564 index 0c4e35e..745d3e4 100644
7565 --- a/arch/sparc/lib/ksyms.c
7566 +++ b/arch/sparc/lib/ksyms.c
7567 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7568
7569 /* Atomic counter implementation. */
7570 EXPORT_SYMBOL(atomic_add);
7571 +EXPORT_SYMBOL(atomic_add_unchecked);
7572 EXPORT_SYMBOL(atomic_add_ret);
7573 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7574 EXPORT_SYMBOL(atomic_sub);
7575 +EXPORT_SYMBOL(atomic_sub_unchecked);
7576 EXPORT_SYMBOL(atomic_sub_ret);
7577 EXPORT_SYMBOL(atomic64_add);
7578 +EXPORT_SYMBOL(atomic64_add_unchecked);
7579 EXPORT_SYMBOL(atomic64_add_ret);
7580 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7581 EXPORT_SYMBOL(atomic64_sub);
7582 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7583 EXPORT_SYMBOL(atomic64_sub_ret);
7584 EXPORT_SYMBOL(atomic64_dec_if_positive);
7585
7586 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7587 index 30c3ecc..736f015 100644
7588 --- a/arch/sparc/mm/Makefile
7589 +++ b/arch/sparc/mm/Makefile
7590 @@ -2,7 +2,7 @@
7591 #
7592
7593 asflags-y := -ansi
7594 -ccflags-y := -Werror
7595 +#ccflags-y := -Werror
7596
7597 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7598 obj-y += fault_$(BITS).o
7599 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7600 index e98bfda..ea8d221 100644
7601 --- a/arch/sparc/mm/fault_32.c
7602 +++ b/arch/sparc/mm/fault_32.c
7603 @@ -21,6 +21,9 @@
7604 #include <linux/perf_event.h>
7605 #include <linux/interrupt.h>
7606 #include <linux/kdebug.h>
7607 +#include <linux/slab.h>
7608 +#include <linux/pagemap.h>
7609 +#include <linux/compiler.h>
7610
7611 #include <asm/page.h>
7612 #include <asm/pgtable.h>
7613 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7614 return safe_compute_effective_address(regs, insn);
7615 }
7616
7617 +#ifdef CONFIG_PAX_PAGEEXEC
7618 +#ifdef CONFIG_PAX_DLRESOLVE
7619 +static void pax_emuplt_close(struct vm_area_struct *vma)
7620 +{
7621 + vma->vm_mm->call_dl_resolve = 0UL;
7622 +}
7623 +
7624 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7625 +{
7626 + unsigned int *kaddr;
7627 +
7628 + vmf->page = alloc_page(GFP_HIGHUSER);
7629 + if (!vmf->page)
7630 + return VM_FAULT_OOM;
7631 +
7632 + kaddr = kmap(vmf->page);
7633 + memset(kaddr, 0, PAGE_SIZE);
7634 + kaddr[0] = 0x9DE3BFA8U; /* save */
7635 + flush_dcache_page(vmf->page);
7636 + kunmap(vmf->page);
7637 + return VM_FAULT_MAJOR;
7638 +}
7639 +
7640 +static const struct vm_operations_struct pax_vm_ops = {
7641 + .close = pax_emuplt_close,
7642 + .fault = pax_emuplt_fault
7643 +};
7644 +
7645 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7646 +{
7647 + int ret;
7648 +
7649 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7650 + vma->vm_mm = current->mm;
7651 + vma->vm_start = addr;
7652 + vma->vm_end = addr + PAGE_SIZE;
7653 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7654 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7655 + vma->vm_ops = &pax_vm_ops;
7656 +
7657 + ret = insert_vm_struct(current->mm, vma);
7658 + if (ret)
7659 + return ret;
7660 +
7661 + ++current->mm->total_vm;
7662 + return 0;
7663 +}
7664 +#endif
7665 +
7666 +/*
7667 + * PaX: decide what to do with offenders (regs->pc = fault address)
7668 + *
7669 + * returns 1 when task should be killed
7670 + * 2 when patched PLT trampoline was detected
7671 + * 3 when unpatched PLT trampoline was detected
7672 + */
7673 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7674 +{
7675 +
7676 +#ifdef CONFIG_PAX_EMUPLT
7677 + int err;
7678 +
7679 + do { /* PaX: patched PLT emulation #1 */
7680 + unsigned int sethi1, sethi2, jmpl;
7681 +
7682 + err = get_user(sethi1, (unsigned int *)regs->pc);
7683 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7684 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7685 +
7686 + if (err)
7687 + break;
7688 +
7689 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7690 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7691 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7692 + {
7693 + unsigned int addr;
7694 +
7695 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7696 + addr = regs->u_regs[UREG_G1];
7697 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7698 + regs->pc = addr;
7699 + regs->npc = addr+4;
7700 + return 2;
7701 + }
7702 + } while (0);
7703 +
7704 + do { /* PaX: patched PLT emulation #2 */
7705 + unsigned int ba;
7706 +
7707 + err = get_user(ba, (unsigned int *)regs->pc);
7708 +
7709 + if (err)
7710 + break;
7711 +
7712 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7713 + unsigned int addr;
7714 +
7715 + if ((ba & 0xFFC00000U) == 0x30800000U)
7716 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7717 + else
7718 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7719 + regs->pc = addr;
7720 + regs->npc = addr+4;
7721 + return 2;
7722 + }
7723 + } while (0);
7724 +
7725 + do { /* PaX: patched PLT emulation #3 */
7726 + unsigned int sethi, bajmpl, nop;
7727 +
7728 + err = get_user(sethi, (unsigned int *)regs->pc);
7729 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7730 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7731 +
7732 + if (err)
7733 + break;
7734 +
7735 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7736 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7737 + nop == 0x01000000U)
7738 + {
7739 + unsigned int addr;
7740 +
7741 + addr = (sethi & 0x003FFFFFU) << 10;
7742 + regs->u_regs[UREG_G1] = addr;
7743 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7744 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7745 + else
7746 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7747 + regs->pc = addr;
7748 + regs->npc = addr+4;
7749 + return 2;
7750 + }
7751 + } while (0);
7752 +
7753 + do { /* PaX: unpatched PLT emulation step 1 */
7754 + unsigned int sethi, ba, nop;
7755 +
7756 + err = get_user(sethi, (unsigned int *)regs->pc);
7757 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7758 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7759 +
7760 + if (err)
7761 + break;
7762 +
7763 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7764 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7765 + nop == 0x01000000U)
7766 + {
7767 + unsigned int addr, save, call;
7768 +
7769 + if ((ba & 0xFFC00000U) == 0x30800000U)
7770 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7771 + else
7772 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7773 +
7774 + err = get_user(save, (unsigned int *)addr);
7775 + err |= get_user(call, (unsigned int *)(addr+4));
7776 + err |= get_user(nop, (unsigned int *)(addr+8));
7777 + if (err)
7778 + break;
7779 +
7780 +#ifdef CONFIG_PAX_DLRESOLVE
7781 + if (save == 0x9DE3BFA8U &&
7782 + (call & 0xC0000000U) == 0x40000000U &&
7783 + nop == 0x01000000U)
7784 + {
7785 + struct vm_area_struct *vma;
7786 + unsigned long call_dl_resolve;
7787 +
7788 + down_read(&current->mm->mmap_sem);
7789 + call_dl_resolve = current->mm->call_dl_resolve;
7790 + up_read(&current->mm->mmap_sem);
7791 + if (likely(call_dl_resolve))
7792 + goto emulate;
7793 +
7794 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7795 +
7796 + down_write(&current->mm->mmap_sem);
7797 + if (current->mm->call_dl_resolve) {
7798 + call_dl_resolve = current->mm->call_dl_resolve;
7799 + up_write(&current->mm->mmap_sem);
7800 + if (vma)
7801 + kmem_cache_free(vm_area_cachep, vma);
7802 + goto emulate;
7803 + }
7804 +
7805 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7806 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7807 + up_write(&current->mm->mmap_sem);
7808 + if (vma)
7809 + kmem_cache_free(vm_area_cachep, vma);
7810 + return 1;
7811 + }
7812 +
7813 + if (pax_insert_vma(vma, call_dl_resolve)) {
7814 + up_write(&current->mm->mmap_sem);
7815 + kmem_cache_free(vm_area_cachep, vma);
7816 + return 1;
7817 + }
7818 +
7819 + current->mm->call_dl_resolve = call_dl_resolve;
7820 + up_write(&current->mm->mmap_sem);
7821 +
7822 +emulate:
7823 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7824 + regs->pc = call_dl_resolve;
7825 + regs->npc = addr+4;
7826 + return 3;
7827 + }
7828 +#endif
7829 +
7830 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7831 + if ((save & 0xFFC00000U) == 0x05000000U &&
7832 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7833 + nop == 0x01000000U)
7834 + {
7835 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7836 + regs->u_regs[UREG_G2] = addr + 4;
7837 + addr = (save & 0x003FFFFFU) << 10;
7838 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7839 + regs->pc = addr;
7840 + regs->npc = addr+4;
7841 + return 3;
7842 + }
7843 + }
7844 + } while (0);
7845 +
7846 + do { /* PaX: unpatched PLT emulation step 2 */
7847 + unsigned int save, call, nop;
7848 +
7849 + err = get_user(save, (unsigned int *)(regs->pc-4));
7850 + err |= get_user(call, (unsigned int *)regs->pc);
7851 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7852 + if (err)
7853 + break;
7854 +
7855 + if (save == 0x9DE3BFA8U &&
7856 + (call & 0xC0000000U) == 0x40000000U &&
7857 + nop == 0x01000000U)
7858 + {
7859 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7860 +
7861 + regs->u_regs[UREG_RETPC] = regs->pc;
7862 + regs->pc = dl_resolve;
7863 + regs->npc = dl_resolve+4;
7864 + return 3;
7865 + }
7866 + } while (0);
7867 +#endif
7868 +
7869 + return 1;
7870 +}
7871 +
7872 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7873 +{
7874 + unsigned long i;
7875 +
7876 + printk(KERN_ERR "PAX: bytes at PC: ");
7877 + for (i = 0; i < 8; i++) {
7878 + unsigned int c;
7879 + if (get_user(c, (unsigned int *)pc+i))
7880 + printk(KERN_CONT "???????? ");
7881 + else
7882 + printk(KERN_CONT "%08x ", c);
7883 + }
7884 + printk("\n");
7885 +}
7886 +#endif
7887 +
7888 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7889 int text_fault)
7890 {
7891 @@ -230,6 +504,24 @@ good_area:
7892 if (!(vma->vm_flags & VM_WRITE))
7893 goto bad_area;
7894 } else {
7895 +
7896 +#ifdef CONFIG_PAX_PAGEEXEC
7897 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7898 + up_read(&mm->mmap_sem);
7899 + switch (pax_handle_fetch_fault(regs)) {
7900 +
7901 +#ifdef CONFIG_PAX_EMUPLT
7902 + case 2:
7903 + case 3:
7904 + return;
7905 +#endif
7906 +
7907 + }
7908 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7909 + do_group_exit(SIGKILL);
7910 + }
7911 +#endif
7912 +
7913 /* Allow reads even for write-only mappings */
7914 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7915 goto bad_area;
7916 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7917 index 097aee7..5ca6697 100644
7918 --- a/arch/sparc/mm/fault_64.c
7919 +++ b/arch/sparc/mm/fault_64.c
7920 @@ -21,6 +21,9 @@
7921 #include <linux/kprobes.h>
7922 #include <linux/kdebug.h>
7923 #include <linux/percpu.h>
7924 +#include <linux/slab.h>
7925 +#include <linux/pagemap.h>
7926 +#include <linux/compiler.h>
7927
7928 #include <asm/page.h>
7929 #include <asm/pgtable.h>
7930 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7931 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7932 regs->tpc);
7933 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7934 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7935 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7936 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7937 dump_stack();
7938 unhandled_fault(regs->tpc, current, regs);
7939 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7940 show_regs(regs);
7941 }
7942
7943 +#ifdef CONFIG_PAX_PAGEEXEC
7944 +#ifdef CONFIG_PAX_DLRESOLVE
7945 +static void pax_emuplt_close(struct vm_area_struct *vma)
7946 +{
7947 + vma->vm_mm->call_dl_resolve = 0UL;
7948 +}
7949 +
7950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7951 +{
7952 + unsigned int *kaddr;
7953 +
7954 + vmf->page = alloc_page(GFP_HIGHUSER);
7955 + if (!vmf->page)
7956 + return VM_FAULT_OOM;
7957 +
7958 + kaddr = kmap(vmf->page);
7959 + memset(kaddr, 0, PAGE_SIZE);
7960 + kaddr[0] = 0x9DE3BFA8U; /* save */
7961 + flush_dcache_page(vmf->page);
7962 + kunmap(vmf->page);
7963 + return VM_FAULT_MAJOR;
7964 +}
7965 +
7966 +static const struct vm_operations_struct pax_vm_ops = {
7967 + .close = pax_emuplt_close,
7968 + .fault = pax_emuplt_fault
7969 +};
7970 +
7971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7972 +{
7973 + int ret;
7974 +
7975 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7976 + vma->vm_mm = current->mm;
7977 + vma->vm_start = addr;
7978 + vma->vm_end = addr + PAGE_SIZE;
7979 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7980 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7981 + vma->vm_ops = &pax_vm_ops;
7982 +
7983 + ret = insert_vm_struct(current->mm, vma);
7984 + if (ret)
7985 + return ret;
7986 +
7987 + ++current->mm->total_vm;
7988 + return 0;
7989 +}
7990 +#endif
7991 +
7992 +/*
7993 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7994 + *
7995 + * returns 1 when task should be killed
7996 + * 2 when patched PLT trampoline was detected
7997 + * 3 when unpatched PLT trampoline was detected
7998 + */
7999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8000 +{
8001 +
8002 +#ifdef CONFIG_PAX_EMUPLT
8003 + int err;
8004 +
8005 + do { /* PaX: patched PLT emulation #1 */
8006 + unsigned int sethi1, sethi2, jmpl;
8007 +
8008 + err = get_user(sethi1, (unsigned int *)regs->tpc);
8009 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
8010 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
8011 +
8012 + if (err)
8013 + break;
8014 +
8015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8018 + {
8019 + unsigned long addr;
8020 +
8021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8022 + addr = regs->u_regs[UREG_G1];
8023 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8024 +
8025 + if (test_thread_flag(TIF_32BIT))
8026 + addr &= 0xFFFFFFFFUL;
8027 +
8028 + regs->tpc = addr;
8029 + regs->tnpc = addr+4;
8030 + return 2;
8031 + }
8032 + } while (0);
8033 +
8034 + do { /* PaX: patched PLT emulation #2 */
8035 + unsigned int ba;
8036 +
8037 + err = get_user(ba, (unsigned int *)regs->tpc);
8038 +
8039 + if (err)
8040 + break;
8041 +
8042 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8043 + unsigned long addr;
8044 +
8045 + if ((ba & 0xFFC00000U) == 0x30800000U)
8046 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8047 + else
8048 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8049 +
8050 + if (test_thread_flag(TIF_32BIT))
8051 + addr &= 0xFFFFFFFFUL;
8052 +
8053 + regs->tpc = addr;
8054 + regs->tnpc = addr+4;
8055 + return 2;
8056 + }
8057 + } while (0);
8058 +
8059 + do { /* PaX: patched PLT emulation #3 */
8060 + unsigned int sethi, bajmpl, nop;
8061 +
8062 + err = get_user(sethi, (unsigned int *)regs->tpc);
8063 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
8064 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8065 +
8066 + if (err)
8067 + break;
8068 +
8069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8070 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8071 + nop == 0x01000000U)
8072 + {
8073 + unsigned long addr;
8074 +
8075 + addr = (sethi & 0x003FFFFFU) << 10;
8076 + regs->u_regs[UREG_G1] = addr;
8077 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8078 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8079 + else
8080 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8081 +
8082 + if (test_thread_flag(TIF_32BIT))
8083 + addr &= 0xFFFFFFFFUL;
8084 +
8085 + regs->tpc = addr;
8086 + regs->tnpc = addr+4;
8087 + return 2;
8088 + }
8089 + } while (0);
8090 +
8091 + do { /* PaX: patched PLT emulation #4 */
8092 + unsigned int sethi, mov1, call, mov2;
8093 +
8094 + err = get_user(sethi, (unsigned int *)regs->tpc);
8095 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8096 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
8097 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8098 +
8099 + if (err)
8100 + break;
8101 +
8102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8103 + mov1 == 0x8210000FU &&
8104 + (call & 0xC0000000U) == 0x40000000U &&
8105 + mov2 == 0x9E100001U)
8106 + {
8107 + unsigned long addr;
8108 +
8109 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8110 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8111 +
8112 + if (test_thread_flag(TIF_32BIT))
8113 + addr &= 0xFFFFFFFFUL;
8114 +
8115 + regs->tpc = addr;
8116 + regs->tnpc = addr+4;
8117 + return 2;
8118 + }
8119 + } while (0);
8120 +
8121 + do { /* PaX: patched PLT emulation #5 */
8122 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8123 +
8124 + err = get_user(sethi, (unsigned int *)regs->tpc);
8125 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8126 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8127 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8128 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8129 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8130 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8131 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8132 +
8133 + if (err)
8134 + break;
8135 +
8136 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8137 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8138 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8139 + (or1 & 0xFFFFE000U) == 0x82106000U &&
8140 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8141 + sllx == 0x83287020U &&
8142 + jmpl == 0x81C04005U &&
8143 + nop == 0x01000000U)
8144 + {
8145 + unsigned long addr;
8146 +
8147 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8148 + regs->u_regs[UREG_G1] <<= 32;
8149 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8150 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8151 + regs->tpc = addr;
8152 + regs->tnpc = addr+4;
8153 + return 2;
8154 + }
8155 + } while (0);
8156 +
8157 + do { /* PaX: patched PLT emulation #6 */
8158 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8159 +
8160 + err = get_user(sethi, (unsigned int *)regs->tpc);
8161 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8162 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8163 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8164 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
8165 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8166 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8167 +
8168 + if (err)
8169 + break;
8170 +
8171 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8172 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8173 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8174 + sllx == 0x83287020U &&
8175 + (or & 0xFFFFE000U) == 0x8A116000U &&
8176 + jmpl == 0x81C04005U &&
8177 + nop == 0x01000000U)
8178 + {
8179 + unsigned long addr;
8180 +
8181 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8182 + regs->u_regs[UREG_G1] <<= 32;
8183 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8184 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8185 + regs->tpc = addr;
8186 + regs->tnpc = addr+4;
8187 + return 2;
8188 + }
8189 + } while (0);
8190 +
8191 + do { /* PaX: unpatched PLT emulation step 1 */
8192 + unsigned int sethi, ba, nop;
8193 +
8194 + err = get_user(sethi, (unsigned int *)regs->tpc);
8195 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8196 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8197 +
8198 + if (err)
8199 + break;
8200 +
8201 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8202 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8203 + nop == 0x01000000U)
8204 + {
8205 + unsigned long addr;
8206 + unsigned int save, call;
8207 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8208 +
8209 + if ((ba & 0xFFC00000U) == 0x30800000U)
8210 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8211 + else
8212 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8213 +
8214 + if (test_thread_flag(TIF_32BIT))
8215 + addr &= 0xFFFFFFFFUL;
8216 +
8217 + err = get_user(save, (unsigned int *)addr);
8218 + err |= get_user(call, (unsigned int *)(addr+4));
8219 + err |= get_user(nop, (unsigned int *)(addr+8));
8220 + if (err)
8221 + break;
8222 +
8223 +#ifdef CONFIG_PAX_DLRESOLVE
8224 + if (save == 0x9DE3BFA8U &&
8225 + (call & 0xC0000000U) == 0x40000000U &&
8226 + nop == 0x01000000U)
8227 + {
8228 + struct vm_area_struct *vma;
8229 + unsigned long call_dl_resolve;
8230 +
8231 + down_read(&current->mm->mmap_sem);
8232 + call_dl_resolve = current->mm->call_dl_resolve;
8233 + up_read(&current->mm->mmap_sem);
8234 + if (likely(call_dl_resolve))
8235 + goto emulate;
8236 +
8237 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8238 +
8239 + down_write(&current->mm->mmap_sem);
8240 + if (current->mm->call_dl_resolve) {
8241 + call_dl_resolve = current->mm->call_dl_resolve;
8242 + up_write(&current->mm->mmap_sem);
8243 + if (vma)
8244 + kmem_cache_free(vm_area_cachep, vma);
8245 + goto emulate;
8246 + }
8247 +
8248 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8249 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8250 + up_write(&current->mm->mmap_sem);
8251 + if (vma)
8252 + kmem_cache_free(vm_area_cachep, vma);
8253 + return 1;
8254 + }
8255 +
8256 + if (pax_insert_vma(vma, call_dl_resolve)) {
8257 + up_write(&current->mm->mmap_sem);
8258 + kmem_cache_free(vm_area_cachep, vma);
8259 + return 1;
8260 + }
8261 +
8262 + current->mm->call_dl_resolve = call_dl_resolve;
8263 + up_write(&current->mm->mmap_sem);
8264 +
8265 +emulate:
8266 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8267 + regs->tpc = call_dl_resolve;
8268 + regs->tnpc = addr+4;
8269 + return 3;
8270 + }
8271 +#endif
8272 +
8273 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8274 + if ((save & 0xFFC00000U) == 0x05000000U &&
8275 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8276 + nop == 0x01000000U)
8277 + {
8278 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8279 + regs->u_regs[UREG_G2] = addr + 4;
8280 + addr = (save & 0x003FFFFFU) << 10;
8281 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8282 +
8283 + if (test_thread_flag(TIF_32BIT))
8284 + addr &= 0xFFFFFFFFUL;
8285 +
8286 + regs->tpc = addr;
8287 + regs->tnpc = addr+4;
8288 + return 3;
8289 + }
8290 +
8291 + /* PaX: 64-bit PLT stub */
8292 + err = get_user(sethi1, (unsigned int *)addr);
8293 + err |= get_user(sethi2, (unsigned int *)(addr+4));
8294 + err |= get_user(or1, (unsigned int *)(addr+8));
8295 + err |= get_user(or2, (unsigned int *)(addr+12));
8296 + err |= get_user(sllx, (unsigned int *)(addr+16));
8297 + err |= get_user(add, (unsigned int *)(addr+20));
8298 + err |= get_user(jmpl, (unsigned int *)(addr+24));
8299 + err |= get_user(nop, (unsigned int *)(addr+28));
8300 + if (err)
8301 + break;
8302 +
8303 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8304 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8305 + (or1 & 0xFFFFE000U) == 0x88112000U &&
8306 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8307 + sllx == 0x89293020U &&
8308 + add == 0x8A010005U &&
8309 + jmpl == 0x89C14000U &&
8310 + nop == 0x01000000U)
8311 + {
8312 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8313 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8314 + regs->u_regs[UREG_G4] <<= 32;
8315 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8316 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8317 + regs->u_regs[UREG_G4] = addr + 24;
8318 + addr = regs->u_regs[UREG_G5];
8319 + regs->tpc = addr;
8320 + regs->tnpc = addr+4;
8321 + return 3;
8322 + }
8323 + }
8324 + } while (0);
8325 +
8326 +#ifdef CONFIG_PAX_DLRESOLVE
8327 + do { /* PaX: unpatched PLT emulation step 2 */
8328 + unsigned int save, call, nop;
8329 +
8330 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8331 + err |= get_user(call, (unsigned int *)regs->tpc);
8332 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8333 + if (err)
8334 + break;
8335 +
8336 + if (save == 0x9DE3BFA8U &&
8337 + (call & 0xC0000000U) == 0x40000000U &&
8338 + nop == 0x01000000U)
8339 + {
8340 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8341 +
8342 + if (test_thread_flag(TIF_32BIT))
8343 + dl_resolve &= 0xFFFFFFFFUL;
8344 +
8345 + regs->u_regs[UREG_RETPC] = regs->tpc;
8346 + regs->tpc = dl_resolve;
8347 + regs->tnpc = dl_resolve+4;
8348 + return 3;
8349 + }
8350 + } while (0);
8351 +#endif
8352 +
8353 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8354 + unsigned int sethi, ba, nop;
8355 +
8356 + err = get_user(sethi, (unsigned int *)regs->tpc);
8357 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8358 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8359 +
8360 + if (err)
8361 + break;
8362 +
8363 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8364 + (ba & 0xFFF00000U) == 0x30600000U &&
8365 + nop == 0x01000000U)
8366 + {
8367 + unsigned long addr;
8368 +
8369 + addr = (sethi & 0x003FFFFFU) << 10;
8370 + regs->u_regs[UREG_G1] = addr;
8371 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8372 +
8373 + if (test_thread_flag(TIF_32BIT))
8374 + addr &= 0xFFFFFFFFUL;
8375 +
8376 + regs->tpc = addr;
8377 + regs->tnpc = addr+4;
8378 + return 2;
8379 + }
8380 + } while (0);
8381 +
8382 +#endif
8383 +
8384 + return 1;
8385 +}
8386 +
8387 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8388 +{
8389 + unsigned long i;
8390 +
8391 + printk(KERN_ERR "PAX: bytes at PC: ");
8392 + for (i = 0; i < 8; i++) {
8393 + unsigned int c;
8394 + if (get_user(c, (unsigned int *)pc+i))
8395 + printk(KERN_CONT "???????? ");
8396 + else
8397 + printk(KERN_CONT "%08x ", c);
8398 + }
8399 + printk("\n");
8400 +}
8401 +#endif
8402 +
8403 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8404 {
8405 struct mm_struct *mm = current->mm;
8406 @@ -341,6 +804,29 @@ retry:
8407 if (!vma)
8408 goto bad_area;
8409
8410 +#ifdef CONFIG_PAX_PAGEEXEC
8411 + /* PaX: detect ITLB misses on non-exec pages */
8412 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8413 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8414 + {
8415 + if (address != regs->tpc)
8416 + goto good_area;
8417 +
8418 + up_read(&mm->mmap_sem);
8419 + switch (pax_handle_fetch_fault(regs)) {
8420 +
8421 +#ifdef CONFIG_PAX_EMUPLT
8422 + case 2:
8423 + case 3:
8424 + return;
8425 +#endif
8426 +
8427 + }
8428 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8429 + do_group_exit(SIGKILL);
8430 + }
8431 +#endif
8432 +
8433 /* Pure DTLB misses do not tell us whether the fault causing
8434 * load/store/atomic was a write or not, it only says that there
8435 * was no match. So in such a case we (carefully) read the
8436 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8437 index f76f83d..ee0d859 100644
8438 --- a/arch/sparc/mm/hugetlbpage.c
8439 +++ b/arch/sparc/mm/hugetlbpage.c
8440 @@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8441 struct vm_area_struct * vma;
8442 unsigned long task_size = TASK_SIZE;
8443 unsigned long start_addr;
8444 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8445
8446 if (test_thread_flag(TIF_32BIT))
8447 task_size = STACK_TOP32;
8448 @@ -67,7 +68,7 @@ full_search:
8449 }
8450 return -ENOMEM;
8451 }
8452 - if (likely(!vma || addr + len <= vma->vm_start)) {
8453 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8454 /*
8455 * Remember the place where we stopped the search:
8456 */
8457 @@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8458 struct vm_area_struct *vma;
8459 struct mm_struct *mm = current->mm;
8460 unsigned long addr = addr0;
8461 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8462
8463 /* This should only ever run for 32-bit processes. */
8464 BUG_ON(!test_thread_flag(TIF_32BIT));
8465 @@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 /* make sure it can fit in the remaining address space */
8467 if (likely(addr > len)) {
8468 vma = find_vma(mm, addr-len);
8469 - if (!vma || addr <= vma->vm_start) {
8470 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8471 /* remember the address as a hint for next time */
8472 return (mm->free_area_cache = addr-len);
8473 }
8474 @@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 if (unlikely(mm->mmap_base < len))
8476 goto bottomup;
8477
8478 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8479 + addr = mm->mmap_base - len;
8480
8481 do {
8482 + addr &= HPAGE_MASK;
8483 /*
8484 * Lookup failure means no vma is above this address,
8485 * else if new region fits below vma->vm_start,
8486 * return with success:
8487 */
8488 vma = find_vma(mm, addr);
8489 - if (likely(!vma || addr+len <= vma->vm_start)) {
8490 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8491 /* remember the address as a hint for next time */
8492 return (mm->free_area_cache = addr);
8493 }
8494 @@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 mm->cached_hole_size = vma->vm_start - addr;
8496
8497 /* try just below the current vma->vm_start */
8498 - addr = (vma->vm_start-len) & HPAGE_MASK;
8499 - } while (likely(len < vma->vm_start));
8500 + addr = skip_heap_stack_gap(vma, len, offset);
8501 + } while (!IS_ERR_VALUE(addr));
8502
8503 bottomup:
8504 /*
8505 @@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8506 struct mm_struct *mm = current->mm;
8507 struct vm_area_struct *vma;
8508 unsigned long task_size = TASK_SIZE;
8509 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8510
8511 if (test_thread_flag(TIF_32BIT))
8512 task_size = STACK_TOP32;
8513 @@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8514 if (addr) {
8515 addr = ALIGN(addr, HPAGE_SIZE);
8516 vma = find_vma(mm, addr);
8517 - if (task_size - len >= addr &&
8518 - (!vma || addr + len <= vma->vm_start))
8519 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8520 return addr;
8521 }
8522 if (mm->get_unmapped_area == arch_get_unmapped_area)
8523 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8524 index f4500c6..889656c 100644
8525 --- a/arch/tile/include/asm/atomic_64.h
8526 +++ b/arch/tile/include/asm/atomic_64.h
8527 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8528
8529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8530
8531 +#define atomic64_read_unchecked(v) atomic64_read(v)
8532 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8533 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8534 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8535 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8536 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8537 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8538 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8539 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8540 +
8541 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8542 #define smp_mb__before_atomic_dec() smp_mb()
8543 #define smp_mb__after_atomic_dec() smp_mb()
8544 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8545 index a9a5299..0fce79e 100644
8546 --- a/arch/tile/include/asm/cache.h
8547 +++ b/arch/tile/include/asm/cache.h
8548 @@ -15,11 +15,12 @@
8549 #ifndef _ASM_TILE_CACHE_H
8550 #define _ASM_TILE_CACHE_H
8551
8552 +#include <linux/const.h>
8553 #include <arch/chip.h>
8554
8555 /* bytes per L1 data cache line */
8556 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8557 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8558 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8559
8560 /* bytes per L2 cache line */
8561 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8562 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8563 index 9ab078a..d6635c2 100644
8564 --- a/arch/tile/include/asm/uaccess.h
8565 +++ b/arch/tile/include/asm/uaccess.h
8566 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8567 const void __user *from,
8568 unsigned long n)
8569 {
8570 - int sz = __compiletime_object_size(to);
8571 + size_t sz = __compiletime_object_size(to);
8572
8573 - if (likely(sz == -1 || sz >= n))
8574 + if (likely(sz == (size_t)-1 || sz >= n))
8575 n = _copy_from_user(to, from, n);
8576 else
8577 copy_from_user_overflow();
8578 diff --git a/arch/um/Makefile b/arch/um/Makefile
8579 index 133f7de..1d6f2f1 100644
8580 --- a/arch/um/Makefile
8581 +++ b/arch/um/Makefile
8582 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8583 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8584 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8585
8586 +ifdef CONSTIFY_PLUGIN
8587 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8588 +endif
8589 +
8590 #This will adjust *FLAGS accordingly to the platform.
8591 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8592
8593 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8594 index 19e1bdd..3665b77 100644
8595 --- a/arch/um/include/asm/cache.h
8596 +++ b/arch/um/include/asm/cache.h
8597 @@ -1,6 +1,7 @@
8598 #ifndef __UM_CACHE_H
8599 #define __UM_CACHE_H
8600
8601 +#include <linux/const.h>
8602
8603 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8604 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8605 @@ -12,6 +13,6 @@
8606 # define L1_CACHE_SHIFT 5
8607 #endif
8608
8609 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8610 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8611
8612 #endif
8613 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8614 index 2e0a6b1..a64d0f5 100644
8615 --- a/arch/um/include/asm/kmap_types.h
8616 +++ b/arch/um/include/asm/kmap_types.h
8617 @@ -8,6 +8,6 @@
8618
8619 /* No more #include "asm/arch/kmap_types.h" ! */
8620
8621 -#define KM_TYPE_NR 14
8622 +#define KM_TYPE_NR 15
8623
8624 #endif
8625 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8626 index 5ff53d9..5850cdf 100644
8627 --- a/arch/um/include/asm/page.h
8628 +++ b/arch/um/include/asm/page.h
8629 @@ -14,6 +14,9 @@
8630 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8631 #define PAGE_MASK (~(PAGE_SIZE-1))
8632
8633 +#define ktla_ktva(addr) (addr)
8634 +#define ktva_ktla(addr) (addr)
8635 +
8636 #ifndef __ASSEMBLY__
8637
8638 struct page;
8639 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8640 index 0032f92..cd151e0 100644
8641 --- a/arch/um/include/asm/pgtable-3level.h
8642 +++ b/arch/um/include/asm/pgtable-3level.h
8643 @@ -58,6 +58,7 @@
8644 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8645 #define pud_populate(mm, pud, pmd) \
8646 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8647 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8648
8649 #ifdef CONFIG_64BIT
8650 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8651 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8652 index b6d699c..df7ac1d 100644
8653 --- a/arch/um/kernel/process.c
8654 +++ b/arch/um/kernel/process.c
8655 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8656 return 2;
8657 }
8658
8659 -/*
8660 - * Only x86 and x86_64 have an arch_align_stack().
8661 - * All other arches have "#define arch_align_stack(x) (x)"
8662 - * in their asm/system.h
8663 - * As this is included in UML from asm-um/system-generic.h,
8664 - * we can use it to behave as the subarch does.
8665 - */
8666 -#ifndef arch_align_stack
8667 -unsigned long arch_align_stack(unsigned long sp)
8668 -{
8669 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8670 - sp -= get_random_int() % 8192;
8671 - return sp & ~0xf;
8672 -}
8673 -#endif
8674 -
8675 unsigned long get_wchan(struct task_struct *p)
8676 {
8677 unsigned long stack_page, sp, ip;
8678 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8679 index ad8f795..2c7eec6 100644
8680 --- a/arch/unicore32/include/asm/cache.h
8681 +++ b/arch/unicore32/include/asm/cache.h
8682 @@ -12,8 +12,10 @@
8683 #ifndef __UNICORE_CACHE_H__
8684 #define __UNICORE_CACHE_H__
8685
8686 -#define L1_CACHE_SHIFT (5)
8687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8688 +#include <linux/const.h>
8689 +
8690 +#define L1_CACHE_SHIFT 5
8691 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8692
8693 /*
8694 * Memory returned by kmalloc() may be used for DMA, so we must make
8695 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8696 index 46c3bff..b82f26b 100644
8697 --- a/arch/x86/Kconfig
8698 +++ b/arch/x86/Kconfig
8699 @@ -241,7 +241,7 @@ config X86_HT
8700
8701 config X86_32_LAZY_GS
8702 def_bool y
8703 - depends on X86_32 && !CC_STACKPROTECTOR
8704 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8705
8706 config ARCH_HWEIGHT_CFLAGS
8707 string
8708 @@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8709
8710 config X86_MSR
8711 tristate "/dev/cpu/*/msr - Model-specific register support"
8712 + depends on !GRKERNSEC_KMEM
8713 ---help---
8714 This device gives privileged processes access to the x86
8715 Model-Specific Registers (MSRs). It is a character device with
8716 @@ -1056,7 +1057,7 @@ choice
8717
8718 config NOHIGHMEM
8719 bool "off"
8720 - depends on !X86_NUMAQ
8721 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8722 ---help---
8723 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8724 However, the address space of 32-bit x86 processors is only 4
8725 @@ -1093,7 +1094,7 @@ config NOHIGHMEM
8726
8727 config HIGHMEM4G
8728 bool "4GB"
8729 - depends on !X86_NUMAQ
8730 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8731 ---help---
8732 Select this if you have a 32-bit processor and between 1 and 4
8733 gigabytes of physical RAM.
8734 @@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8735 hex
8736 default 0xB0000000 if VMSPLIT_3G_OPT
8737 default 0x80000000 if VMSPLIT_2G
8738 - default 0x78000000 if VMSPLIT_2G_OPT
8739 + default 0x70000000 if VMSPLIT_2G_OPT
8740 default 0x40000000 if VMSPLIT_1G
8741 default 0xC0000000
8742 depends on X86_32
8743 @@ -1548,6 +1549,7 @@ config SECCOMP
8744
8745 config CC_STACKPROTECTOR
8746 bool "Enable -fstack-protector buffer overflow detection"
8747 + depends on X86_64 || !PAX_MEMORY_UDEREF
8748 ---help---
8749 This option turns on the -fstack-protector GCC feature. This
8750 feature puts, at the beginning of functions, a canary value on
8751 @@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8752 config PHYSICAL_START
8753 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8754 default "0x1000000"
8755 + range 0x400000 0x40000000
8756 ---help---
8757 This gives the physical address where the kernel is loaded.
8758
8759 @@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8760 config PHYSICAL_ALIGN
8761 hex "Alignment value to which kernel should be aligned" if X86_32
8762 default "0x1000000"
8763 + range 0x400000 0x1000000 if PAX_KERNEXEC
8764 range 0x2000 0x1000000
8765 ---help---
8766 This value puts the alignment restrictions on physical address
8767 @@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8768 Say N if you want to disable CPU hotplug.
8769
8770 config COMPAT_VDSO
8771 - def_bool y
8772 + def_bool n
8773 prompt "Compat VDSO support"
8774 depends on X86_32 || IA32_EMULATION
8775 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8776 ---help---
8777 Map the 32-bit VDSO to the predictable old-style address too.
8778
8779 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8780 index f3b86d0..17fd30f 100644
8781 --- a/arch/x86/Kconfig.cpu
8782 +++ b/arch/x86/Kconfig.cpu
8783 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8784
8785 config X86_F00F_BUG
8786 def_bool y
8787 - depends on M586MMX || M586TSC || M586 || M486 || M386
8788 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8789
8790 config X86_INVD_BUG
8791 def_bool y
8792 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8793
8794 config X86_ALIGNMENT_16
8795 def_bool y
8796 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8797 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8798
8799 config X86_INTEL_USERCOPY
8800 def_bool y
8801 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8802 # generates cmov.
8803 config X86_CMOV
8804 def_bool y
8805 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8806 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8807
8808 config X86_MINIMUM_CPU_FAMILY
8809 int
8810 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8811 index b322f12..652d0d9 100644
8812 --- a/arch/x86/Kconfig.debug
8813 +++ b/arch/x86/Kconfig.debug
8814 @@ -84,7 +84,7 @@ config X86_PTDUMP
8815 config DEBUG_RODATA
8816 bool "Write protect kernel read-only data structures"
8817 default y
8818 - depends on DEBUG_KERNEL
8819 + depends on DEBUG_KERNEL && BROKEN
8820 ---help---
8821 Mark the kernel read-only data as write-protected in the pagetables,
8822 in order to catch accidental (and incorrect) writes to such const
8823 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8824
8825 config DEBUG_SET_MODULE_RONX
8826 bool "Set loadable kernel module data as NX and text as RO"
8827 - depends on MODULES
8828 + depends on MODULES && BROKEN
8829 ---help---
8830 This option helps catch unintended modifications to loadable
8831 kernel module's text and read-only data. It also prevents execution
8832 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8833
8834 config DEBUG_STRICT_USER_COPY_CHECKS
8835 bool "Strict copy size checks"
8836 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8837 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8838 ---help---
8839 Enabling this option turns a certain set of sanity checks for user
8840 copy operations into compile time failures.
8841 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8842 index 05afcca..b6ecb51 100644
8843 --- a/arch/x86/Makefile
8844 +++ b/arch/x86/Makefile
8845 @@ -50,6 +50,7 @@ else
8846 UTS_MACHINE := x86_64
8847 CHECKFLAGS += -D__x86_64__ -m64
8848
8849 + biarch := $(call cc-option,-m64)
8850 KBUILD_AFLAGS += -m64
8851 KBUILD_CFLAGS += -m64
8852
8853 @@ -229,3 +230,12 @@ define archhelp
8854 echo ' FDARGS="..." arguments for the booted kernel'
8855 echo ' FDINITRD=file initrd for the booted kernel'
8856 endef
8857 +
8858 +define OLD_LD
8859 +
8860 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8861 +*** Please upgrade your binutils to 2.18 or newer
8862 +endef
8863 +
8864 +archprepare:
8865 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8866 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8867 index ccce0ed..fd9da25 100644
8868 --- a/arch/x86/boot/Makefile
8869 +++ b/arch/x86/boot/Makefile
8870 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8871 $(call cc-option, -fno-stack-protector) \
8872 $(call cc-option, -mpreferred-stack-boundary=2)
8873 KBUILD_CFLAGS += $(call cc-option, -m32)
8874 +ifdef CONSTIFY_PLUGIN
8875 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8876 +endif
8877 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8878 GCOV_PROFILE := n
8879
8880 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8881 index 878e4b9..20537ab 100644
8882 --- a/arch/x86/boot/bitops.h
8883 +++ b/arch/x86/boot/bitops.h
8884 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8885 u8 v;
8886 const u32 *p = (const u32 *)addr;
8887
8888 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8889 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8890 return v;
8891 }
8892
8893 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8894
8895 static inline void set_bit(int nr, void *addr)
8896 {
8897 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8898 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8899 }
8900
8901 #endif /* BOOT_BITOPS_H */
8902 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8903 index 18997e5..83d9c67 100644
8904 --- a/arch/x86/boot/boot.h
8905 +++ b/arch/x86/boot/boot.h
8906 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8907 static inline u16 ds(void)
8908 {
8909 u16 seg;
8910 - asm("movw %%ds,%0" : "=rm" (seg));
8911 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8912 return seg;
8913 }
8914
8915 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8916 static inline int memcmp(const void *s1, const void *s2, size_t len)
8917 {
8918 u8 diff;
8919 - asm("repe; cmpsb; setnz %0"
8920 + asm volatile("repe; cmpsb; setnz %0"
8921 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8922 return diff;
8923 }
8924 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8925 index 8a84501..b2d165f 100644
8926 --- a/arch/x86/boot/compressed/Makefile
8927 +++ b/arch/x86/boot/compressed/Makefile
8928 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8929 KBUILD_CFLAGS += $(cflags-y)
8930 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8931 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8932 +ifdef CONSTIFY_PLUGIN
8933 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8934 +endif
8935
8936 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8937 GCOV_PROFILE := n
8938 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8939 index ccae7e2..8ac70be 100644
8940 --- a/arch/x86/boot/compressed/eboot.c
8941 +++ b/arch/x86/boot/compressed/eboot.c
8942 @@ -144,7 +144,6 @@ again:
8943 *addr = max_addr;
8944 }
8945
8946 -free_pool:
8947 efi_call_phys1(sys_table->boottime->free_pool, map);
8948
8949 fail:
8950 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8951 if (i == map_size / desc_size)
8952 status = EFI_NOT_FOUND;
8953
8954 -free_pool:
8955 efi_call_phys1(sys_table->boottime->free_pool, map);
8956 fail:
8957 return status;
8958 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8959 index ccb2f4a..e49b20e 100644
8960 --- a/arch/x86/boot/compressed/head_32.S
8961 +++ b/arch/x86/boot/compressed/head_32.S
8962 @@ -118,7 +118,7 @@ preferred_addr:
8963 notl %eax
8964 andl %eax, %ebx
8965 #else
8966 - movl $LOAD_PHYSICAL_ADDR, %ebx
8967 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8968 #endif
8969
8970 /* Target address to relocate to for decompression */
8971 @@ -204,7 +204,7 @@ relocated:
8972 * and where it was actually loaded.
8973 */
8974 movl %ebp, %ebx
8975 - subl $LOAD_PHYSICAL_ADDR, %ebx
8976 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8977 jz 2f /* Nothing to be done if loaded at compiled addr. */
8978 /*
8979 * Process relocations.
8980 @@ -212,8 +212,7 @@ relocated:
8981
8982 1: subl $4, %edi
8983 movl (%edi), %ecx
8984 - testl %ecx, %ecx
8985 - jz 2f
8986 + jecxz 2f
8987 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8988 jmp 1b
8989 2:
8990 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8991 index 2c4b171..e1fa5b1 100644
8992 --- a/arch/x86/boot/compressed/head_64.S
8993 +++ b/arch/x86/boot/compressed/head_64.S
8994 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8995 notl %eax
8996 andl %eax, %ebx
8997 #else
8998 - movl $LOAD_PHYSICAL_ADDR, %ebx
8999 + movl $____LOAD_PHYSICAL_ADDR, %ebx
9000 #endif
9001
9002 /* Target address to relocate to for decompression */
9003 @@ -273,7 +273,7 @@ preferred_addr:
9004 notq %rax
9005 andq %rax, %rbp
9006 #else
9007 - movq $LOAD_PHYSICAL_ADDR, %rbp
9008 + movq $____LOAD_PHYSICAL_ADDR, %rbp
9009 #endif
9010
9011 /* Target address to relocate to for decompression */
9012 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
9013 index 88f7ff6..ed695dd 100644
9014 --- a/arch/x86/boot/compressed/misc.c
9015 +++ b/arch/x86/boot/compressed/misc.c
9016 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
9017 case PT_LOAD:
9018 #ifdef CONFIG_RELOCATABLE
9019 dest = output;
9020 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
9021 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
9022 #else
9023 dest = (void *)(phdr->p_paddr);
9024 #endif
9025 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
9026 error("Destination address too large");
9027 #endif
9028 #ifndef CONFIG_RELOCATABLE
9029 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
9030 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
9031 error("Wrong destination address");
9032 #endif
9033
9034 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
9035 index 4d3ff03..e4972ff 100644
9036 --- a/arch/x86/boot/cpucheck.c
9037 +++ b/arch/x86/boot/cpucheck.c
9038 @@ -74,7 +74,7 @@ static int has_fpu(void)
9039 u16 fcw = -1, fsw = -1;
9040 u32 cr0;
9041
9042 - asm("movl %%cr0,%0" : "=r" (cr0));
9043 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
9044 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
9045 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
9046 asm volatile("movl %0,%%cr0" : : "r" (cr0));
9047 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
9048 {
9049 u32 f0, f1;
9050
9051 - asm("pushfl ; "
9052 + asm volatile("pushfl ; "
9053 "pushfl ; "
9054 "popl %0 ; "
9055 "movl %0,%1 ; "
9056 @@ -115,7 +115,7 @@ static void get_flags(void)
9057 set_bit(X86_FEATURE_FPU, cpu.flags);
9058
9059 if (has_eflag(X86_EFLAGS_ID)) {
9060 - asm("cpuid"
9061 + asm volatile("cpuid"
9062 : "=a" (max_intel_level),
9063 "=b" (cpu_vendor[0]),
9064 "=d" (cpu_vendor[1]),
9065 @@ -124,7 +124,7 @@ static void get_flags(void)
9066
9067 if (max_intel_level >= 0x00000001 &&
9068 max_intel_level <= 0x0000ffff) {
9069 - asm("cpuid"
9070 + asm volatile("cpuid"
9071 : "=a" (tfms),
9072 "=c" (cpu.flags[4]),
9073 "=d" (cpu.flags[0])
9074 @@ -136,7 +136,7 @@ static void get_flags(void)
9075 cpu.model += ((tfms >> 16) & 0xf) << 4;
9076 }
9077
9078 - asm("cpuid"
9079 + asm volatile("cpuid"
9080 : "=a" (max_amd_level)
9081 : "a" (0x80000000)
9082 : "ebx", "ecx", "edx");
9083 @@ -144,7 +144,7 @@ static void get_flags(void)
9084 if (max_amd_level >= 0x80000001 &&
9085 max_amd_level <= 0x8000ffff) {
9086 u32 eax = 0x80000001;
9087 - asm("cpuid"
9088 + asm volatile("cpuid"
9089 : "+a" (eax),
9090 "=c" (cpu.flags[6]),
9091 "=d" (cpu.flags[1])
9092 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9093 u32 ecx = MSR_K7_HWCR;
9094 u32 eax, edx;
9095
9096 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9097 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9098 eax &= ~(1 << 15);
9099 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9100 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9101
9102 get_flags(); /* Make sure it really did something */
9103 err = check_flags();
9104 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9105 u32 ecx = MSR_VIA_FCR;
9106 u32 eax, edx;
9107
9108 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9109 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9110 eax |= (1<<1)|(1<<7);
9111 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9112 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9113
9114 set_bit(X86_FEATURE_CX8, cpu.flags);
9115 err = check_flags();
9116 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9117 u32 eax, edx;
9118 u32 level = 1;
9119
9120 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9121 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9122 - asm("cpuid"
9123 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9124 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9125 + asm volatile("cpuid"
9126 : "+a" (level), "=d" (cpu.flags[0])
9127 : : "ecx", "ebx");
9128 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9129 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9130
9131 err = check_flags();
9132 }
9133 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9134 index 8c132a6..13e5c96 100644
9135 --- a/arch/x86/boot/header.S
9136 +++ b/arch/x86/boot/header.S
9137 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9138 # single linked list of
9139 # struct setup_data
9140
9141 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9142 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9143
9144 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9146 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9147 +#else
9148 #define VO_INIT_SIZE (VO__end - VO__text)
9149 +#endif
9150 #if ZO_INIT_SIZE > VO_INIT_SIZE
9151 #define INIT_SIZE ZO_INIT_SIZE
9152 #else
9153 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9154 index db75d07..8e6d0af 100644
9155 --- a/arch/x86/boot/memory.c
9156 +++ b/arch/x86/boot/memory.c
9157 @@ -19,7 +19,7 @@
9158
9159 static int detect_memory_e820(void)
9160 {
9161 - int count = 0;
9162 + unsigned int count = 0;
9163 struct biosregs ireg, oreg;
9164 struct e820entry *desc = boot_params.e820_map;
9165 static struct e820entry buf; /* static so it is zeroed */
9166 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9167 index 11e8c6e..fdbb1ed 100644
9168 --- a/arch/x86/boot/video-vesa.c
9169 +++ b/arch/x86/boot/video-vesa.c
9170 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9171
9172 boot_params.screen_info.vesapm_seg = oreg.es;
9173 boot_params.screen_info.vesapm_off = oreg.di;
9174 + boot_params.screen_info.vesapm_size = oreg.cx;
9175 }
9176
9177 /*
9178 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9179 index 43eda28..5ab5fdb 100644
9180 --- a/arch/x86/boot/video.c
9181 +++ b/arch/x86/boot/video.c
9182 @@ -96,7 +96,7 @@ static void store_mode_params(void)
9183 static unsigned int get_entry(void)
9184 {
9185 char entry_buf[4];
9186 - int i, len = 0;
9187 + unsigned int i, len = 0;
9188 int key;
9189 unsigned int v;
9190
9191 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9192 index 5b577d5..3c1fed4 100644
9193 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
9194 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9195 @@ -8,6 +8,8 @@
9196 * including this sentence is retained in full.
9197 */
9198
9199 +#include <asm/alternative-asm.h>
9200 +
9201 .extern crypto_ft_tab
9202 .extern crypto_it_tab
9203 .extern crypto_fl_tab
9204 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9205 je B192; \
9206 leaq 32(r9),r9;
9207
9208 +#define ret pax_force_retaddr 0, 1; ret
9209 +
9210 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9211 movq r1,r2; \
9212 movq r3,r4; \
9213 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9214 index 3470624..201259d 100644
9215 --- a/arch/x86/crypto/aesni-intel_asm.S
9216 +++ b/arch/x86/crypto/aesni-intel_asm.S
9217 @@ -31,6 +31,7 @@
9218
9219 #include <linux/linkage.h>
9220 #include <asm/inst.h>
9221 +#include <asm/alternative-asm.h>
9222
9223 #ifdef __x86_64__
9224 .data
9225 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9226 pop %r14
9227 pop %r13
9228 pop %r12
9229 + pax_force_retaddr 0, 1
9230 ret
9231 +ENDPROC(aesni_gcm_dec)
9232
9233
9234 /*****************************************************************************
9235 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9236 pop %r14
9237 pop %r13
9238 pop %r12
9239 + pax_force_retaddr 0, 1
9240 ret
9241 +ENDPROC(aesni_gcm_enc)
9242
9243 #endif
9244
9245 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
9246 pxor %xmm1, %xmm0
9247 movaps %xmm0, (TKEYP)
9248 add $0x10, TKEYP
9249 + pax_force_retaddr_bts
9250 ret
9251
9252 .align 4
9253 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
9254 shufps $0b01001110, %xmm2, %xmm1
9255 movaps %xmm1, 0x10(TKEYP)
9256 add $0x20, TKEYP
9257 + pax_force_retaddr_bts
9258 ret
9259
9260 .align 4
9261 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
9262
9263 movaps %xmm0, (TKEYP)
9264 add $0x10, TKEYP
9265 + pax_force_retaddr_bts
9266 ret
9267
9268 .align 4
9269 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
9270 pxor %xmm1, %xmm2
9271 movaps %xmm2, (TKEYP)
9272 add $0x10, TKEYP
9273 + pax_force_retaddr_bts
9274 ret
9275
9276 /*
9277 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9278 #ifndef __x86_64__
9279 popl KEYP
9280 #endif
9281 + pax_force_retaddr 0, 1
9282 ret
9283 +ENDPROC(aesni_set_key)
9284
9285 /*
9286 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9287 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9288 popl KLEN
9289 popl KEYP
9290 #endif
9291 + pax_force_retaddr 0, 1
9292 ret
9293 +ENDPROC(aesni_enc)
9294
9295 /*
9296 * _aesni_enc1: internal ABI
9297 @@ -1959,6 +1972,7 @@ _aesni_enc1:
9298 AESENC KEY STATE
9299 movaps 0x70(TKEYP), KEY
9300 AESENCLAST KEY STATE
9301 + pax_force_retaddr_bts
9302 ret
9303
9304 /*
9305 @@ -2067,6 +2081,7 @@ _aesni_enc4:
9306 AESENCLAST KEY STATE2
9307 AESENCLAST KEY STATE3
9308 AESENCLAST KEY STATE4
9309 + pax_force_retaddr_bts
9310 ret
9311
9312 /*
9313 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9314 popl KLEN
9315 popl KEYP
9316 #endif
9317 + pax_force_retaddr 0, 1
9318 ret
9319 +ENDPROC(aesni_dec)
9320
9321 /*
9322 * _aesni_dec1: internal ABI
9323 @@ -2146,6 +2163,7 @@ _aesni_dec1:
9324 AESDEC KEY STATE
9325 movaps 0x70(TKEYP), KEY
9326 AESDECLAST KEY STATE
9327 + pax_force_retaddr_bts
9328 ret
9329
9330 /*
9331 @@ -2254,6 +2272,7 @@ _aesni_dec4:
9332 AESDECLAST KEY STATE2
9333 AESDECLAST KEY STATE3
9334 AESDECLAST KEY STATE4
9335 + pax_force_retaddr_bts
9336 ret
9337
9338 /*
9339 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9340 popl KEYP
9341 popl LEN
9342 #endif
9343 + pax_force_retaddr 0, 1
9344 ret
9345 +ENDPROC(aesni_ecb_enc)
9346
9347 /*
9348 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9349 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9350 popl KEYP
9351 popl LEN
9352 #endif
9353 + pax_force_retaddr 0, 1
9354 ret
9355 +ENDPROC(aesni_ecb_dec)
9356
9357 /*
9358 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9359 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9360 popl LEN
9361 popl IVP
9362 #endif
9363 + pax_force_retaddr 0, 1
9364 ret
9365 +ENDPROC(aesni_cbc_enc)
9366
9367 /*
9368 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9369 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9370 popl LEN
9371 popl IVP
9372 #endif
9373 + pax_force_retaddr 0, 1
9374 ret
9375 +ENDPROC(aesni_cbc_dec)
9376
9377 #ifdef __x86_64__
9378 .align 16
9379 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9380 mov $1, TCTR_LOW
9381 MOVQ_R64_XMM TCTR_LOW INC
9382 MOVQ_R64_XMM CTR TCTR_LOW
9383 + pax_force_retaddr_bts
9384 ret
9385
9386 /*
9387 @@ -2554,6 +2582,7 @@ _aesni_inc:
9388 .Linc_low:
9389 movaps CTR, IV
9390 PSHUFB_XMM BSWAP_MASK IV
9391 + pax_force_retaddr_bts
9392 ret
9393
9394 /*
9395 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9396 .Lctr_enc_ret:
9397 movups IV, (IVP)
9398 .Lctr_enc_just_ret:
9399 + pax_force_retaddr 0, 1
9400 ret
9401 +ENDPROC(aesni_ctr_enc)
9402 #endif
9403 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9404 index 391d245..67f35c2 100644
9405 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9406 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9407 @@ -20,6 +20,8 @@
9408 *
9409 */
9410
9411 +#include <asm/alternative-asm.h>
9412 +
9413 .file "blowfish-x86_64-asm.S"
9414 .text
9415
9416 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9417 jnz __enc_xor;
9418
9419 write_block();
9420 + pax_force_retaddr 0, 1
9421 ret;
9422 __enc_xor:
9423 xor_block();
9424 + pax_force_retaddr 0, 1
9425 ret;
9426
9427 .align 8
9428 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9429
9430 movq %r11, %rbp;
9431
9432 + pax_force_retaddr 0, 1
9433 ret;
9434
9435 /**********************************************************************
9436 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9437
9438 popq %rbx;
9439 popq %rbp;
9440 + pax_force_retaddr 0, 1
9441 ret;
9442
9443 __enc_xor4:
9444 @@ -349,6 +355,7 @@ __enc_xor4:
9445
9446 popq %rbx;
9447 popq %rbp;
9448 + pax_force_retaddr 0, 1
9449 ret;
9450
9451 .align 8
9452 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9453 popq %rbx;
9454 popq %rbp;
9455
9456 + pax_force_retaddr 0, 1
9457 ret;
9458
9459 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9460 index 0b33743..7a56206 100644
9461 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9462 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9463 @@ -20,6 +20,8 @@
9464 *
9465 */
9466
9467 +#include <asm/alternative-asm.h>
9468 +
9469 .file "camellia-x86_64-asm_64.S"
9470 .text
9471
9472 @@ -229,12 +231,14 @@ __enc_done:
9473 enc_outunpack(mov, RT1);
9474
9475 movq RRBP, %rbp;
9476 + pax_force_retaddr 0, 1
9477 ret;
9478
9479 __enc_xor:
9480 enc_outunpack(xor, RT1);
9481
9482 movq RRBP, %rbp;
9483 + pax_force_retaddr 0, 1
9484 ret;
9485
9486 .global camellia_dec_blk;
9487 @@ -275,6 +279,7 @@ __dec_rounds16:
9488 dec_outunpack();
9489
9490 movq RRBP, %rbp;
9491 + pax_force_retaddr 0, 1
9492 ret;
9493
9494 /**********************************************************************
9495 @@ -468,6 +473,7 @@ __enc2_done:
9496
9497 movq RRBP, %rbp;
9498 popq %rbx;
9499 + pax_force_retaddr 0, 1
9500 ret;
9501
9502 __enc2_xor:
9503 @@ -475,6 +481,7 @@ __enc2_xor:
9504
9505 movq RRBP, %rbp;
9506 popq %rbx;
9507 + pax_force_retaddr 0, 1
9508 ret;
9509
9510 .global camellia_dec_blk_2way;
9511 @@ -517,4 +524,5 @@ __dec2_rounds16:
9512
9513 movq RRBP, %rbp;
9514 movq RXOR, %rbx;
9515 + pax_force_retaddr 0, 1
9516 ret;
9517 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9518 index a41a3aa..bdf5753 100644
9519 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9520 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9521 @@ -23,6 +23,8 @@
9522 *
9523 */
9524
9525 +#include <asm/alternative-asm.h>
9526 +
9527 .file "cast5-avx-x86_64-asm_64.S"
9528
9529 .extern cast5_s1
9530 @@ -293,6 +295,7 @@ __skip_enc:
9531 leaq 3*(2*4*4)(%r11), %rax;
9532 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9533
9534 + pax_force_retaddr 0, 1
9535 ret;
9536
9537 __enc_xor16:
9538 @@ -303,6 +306,7 @@ __enc_xor16:
9539 leaq 3*(2*4*4)(%r11), %rax;
9540 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9541
9542 + pax_force_retaddr 0, 1
9543 ret;
9544
9545 .align 16
9546 @@ -369,6 +373,7 @@ __dec_tail:
9547 leaq 3*(2*4*4)(%r11), %rax;
9548 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9549
9550 + pax_force_retaddr 0, 1
9551 ret;
9552
9553 __skip_dec:
9554 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9555 index 218d283..819e6da 100644
9556 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9557 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9558 @@ -23,6 +23,8 @@
9559 *
9560 */
9561
9562 +#include <asm/alternative-asm.h>
9563 +
9564 .file "cast6-avx-x86_64-asm_64.S"
9565
9566 .extern cast6_s1
9567 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9568 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9569 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9570
9571 + pax_force_retaddr 0, 1
9572 ret;
9573
9574 __enc_xor8:
9575 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9576 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9577
9578 + pax_force_retaddr 0, 1
9579 ret;
9580
9581 .align 16
9582 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9583 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9584 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9585
9586 + pax_force_retaddr 0, 1
9587 ret;
9588 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9589 index 6214a9b..1f4fc9a 100644
9590 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9591 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9592 @@ -1,3 +1,5 @@
9593 +#include <asm/alternative-asm.h>
9594 +
9595 # enter ECRYPT_encrypt_bytes
9596 .text
9597 .p2align 5
9598 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9599 add %r11,%rsp
9600 mov %rdi,%rax
9601 mov %rsi,%rdx
9602 + pax_force_retaddr 0, 1
9603 ret
9604 # bytesatleast65:
9605 ._bytesatleast65:
9606 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9607 add %r11,%rsp
9608 mov %rdi,%rax
9609 mov %rsi,%rdx
9610 + pax_force_retaddr
9611 ret
9612 # enter ECRYPT_ivsetup
9613 .text
9614 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9615 add %r11,%rsp
9616 mov %rdi,%rax
9617 mov %rsi,%rdx
9618 + pax_force_retaddr
9619 ret
9620 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9621 index 504106b..4e50951 100644
9622 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9623 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9624 @@ -24,6 +24,8 @@
9625 *
9626 */
9627
9628 +#include <asm/alternative-asm.h>
9629 +
9630 .file "serpent-avx-x86_64-asm_64.S"
9631 .text
9632
9633 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9634 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9635 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9636
9637 + pax_force_retaddr
9638 ret;
9639
9640 __enc_xor8:
9641 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9642 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9643
9644 + pax_force_retaddr
9645 ret;
9646
9647 .align 8
9648 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9649 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9650 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9651
9652 + pax_force_retaddr
9653 ret;
9654 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9655 index 3ee1ff0..cbc568b 100644
9656 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9657 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9658 @@ -24,6 +24,8 @@
9659 *
9660 */
9661
9662 +#include <asm/alternative-asm.h>
9663 +
9664 .file "serpent-sse2-x86_64-asm_64.S"
9665 .text
9666
9667 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9668 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9669 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9670
9671 + pax_force_retaddr
9672 ret;
9673
9674 __enc_xor8:
9675 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9676 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9677
9678 + pax_force_retaddr
9679 ret;
9680
9681 .align 8
9682 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9683 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9684 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9685
9686 + pax_force_retaddr
9687 ret;
9688 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9689 index 49d6987..df66bd4 100644
9690 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9691 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9692 @@ -28,6 +28,8 @@
9693 * (at your option) any later version.
9694 */
9695
9696 +#include <asm/alternative-asm.h>
9697 +
9698 #define CTX %rdi // arg1
9699 #define BUF %rsi // arg2
9700 #define CNT %rdx // arg3
9701 @@ -104,6 +106,7 @@
9702 pop %r12
9703 pop %rbp
9704 pop %rbx
9705 + pax_force_retaddr 0, 1
9706 ret
9707
9708 .size \name, .-\name
9709 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9710 index 1585abb..1ff9d9b 100644
9711 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9712 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9713 @@ -23,6 +23,8 @@
9714 *
9715 */
9716
9717 +#include <asm/alternative-asm.h>
9718 +
9719 .file "twofish-avx-x86_64-asm_64.S"
9720 .text
9721
9722 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9723 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9724 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9725
9726 + pax_force_retaddr 0, 1
9727 ret;
9728
9729 __enc_xor8:
9730 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9731 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9732
9733 + pax_force_retaddr 0, 1
9734 ret;
9735
9736 .align 8
9737 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9738 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9739 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9740
9741 + pax_force_retaddr 0, 1
9742 ret;
9743 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9744 index 5b012a2..36d5364 100644
9745 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9746 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9747 @@ -20,6 +20,8 @@
9748 *
9749 */
9750
9751 +#include <asm/alternative-asm.h>
9752 +
9753 .file "twofish-x86_64-asm-3way.S"
9754 .text
9755
9756 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9757 popq %r13;
9758 popq %r14;
9759 popq %r15;
9760 + pax_force_retaddr 0, 1
9761 ret;
9762
9763 __enc_xor3:
9764 @@ -271,6 +274,7 @@ __enc_xor3:
9765 popq %r13;
9766 popq %r14;
9767 popq %r15;
9768 + pax_force_retaddr 0, 1
9769 ret;
9770
9771 .global twofish_dec_blk_3way
9772 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9773 popq %r13;
9774 popq %r14;
9775 popq %r15;
9776 + pax_force_retaddr 0, 1
9777 ret;
9778
9779 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9780 index 7bcf3fc..f53832f 100644
9781 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9782 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9783 @@ -21,6 +21,7 @@
9784 .text
9785
9786 #include <asm/asm-offsets.h>
9787 +#include <asm/alternative-asm.h>
9788
9789 #define a_offset 0
9790 #define b_offset 4
9791 @@ -268,6 +269,7 @@ twofish_enc_blk:
9792
9793 popq R1
9794 movq $1,%rax
9795 + pax_force_retaddr 0, 1
9796 ret
9797
9798 twofish_dec_blk:
9799 @@ -319,4 +321,5 @@ twofish_dec_blk:
9800
9801 popq R1
9802 movq $1,%rax
9803 + pax_force_retaddr 0, 1
9804 ret
9805 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9806 index 07b3a68..bd2a388 100644
9807 --- a/arch/x86/ia32/ia32_aout.c
9808 +++ b/arch/x86/ia32/ia32_aout.c
9809 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9810 unsigned long dump_start, dump_size;
9811 struct user32 dump;
9812
9813 + memset(&dump, 0, sizeof(dump));
9814 +
9815 fs = get_fs();
9816 set_fs(KERNEL_DS);
9817 has_dumped = 1;
9818 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9819 index efc6a95..95abfe2 100644
9820 --- a/arch/x86/ia32/ia32_signal.c
9821 +++ b/arch/x86/ia32/ia32_signal.c
9822 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9823 }
9824 seg = get_fs();
9825 set_fs(KERNEL_DS);
9826 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9827 - (stack_t __force __user *) &uoss, regs->sp);
9828 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9829 + (stack_t __force_user *) &uoss, regs->sp);
9830 set_fs(seg);
9831 if (ret >= 0 && uoss_ptr) {
9832 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9833 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9834 sp -= frame_size;
9835 /* Align the stack pointer according to the i386 ABI,
9836 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9837 - sp = ((sp + 4) & -16ul) - 4;
9838 + sp = ((sp - 12) & -16ul) - 4;
9839 return (void __user *) sp;
9840 }
9841
9842 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9843 * These are actually not used anymore, but left because some
9844 * gdb versions depend on them as a marker.
9845 */
9846 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9847 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9848 } put_user_catch(err);
9849
9850 if (err)
9851 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9852 0xb8,
9853 __NR_ia32_rt_sigreturn,
9854 0x80cd,
9855 - 0,
9856 + 0
9857 };
9858
9859 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9860 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9861
9862 if (ka->sa.sa_flags & SA_RESTORER)
9863 restorer = ka->sa.sa_restorer;
9864 + else if (current->mm->context.vdso)
9865 + /* Return stub is in 32bit vsyscall page */
9866 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9867 else
9868 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9869 - rt_sigreturn);
9870 + restorer = &frame->retcode;
9871 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9872
9873 /*
9874 * Not actually used anymore, but left because some gdb
9875 * versions need it.
9876 */
9877 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9878 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9879 } put_user_catch(err);
9880
9881 err |= copy_siginfo_to_user32(&frame->info, info);
9882 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9883 index e7fa545..9e6fe1a 100644
9884 --- a/arch/x86/ia32/ia32entry.S
9885 +++ b/arch/x86/ia32/ia32entry.S
9886 @@ -15,8 +15,10 @@
9887 #include <asm/irqflags.h>
9888 #include <asm/asm.h>
9889 #include <asm/smap.h>
9890 +#include <asm/pgtable.h>
9891 #include <linux/linkage.h>
9892 #include <linux/err.h>
9893 +#include <asm/alternative-asm.h>
9894
9895 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9896 #include <linux/elf-em.h>
9897 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9898 ENDPROC(native_irq_enable_sysexit)
9899 #endif
9900
9901 + .macro pax_enter_kernel_user
9902 + pax_set_fptr_mask
9903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9904 + call pax_enter_kernel_user
9905 +#endif
9906 + .endm
9907 +
9908 + .macro pax_exit_kernel_user
9909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9910 + call pax_exit_kernel_user
9911 +#endif
9912 +#ifdef CONFIG_PAX_RANDKSTACK
9913 + pushq %rax
9914 + pushq %r11
9915 + call pax_randomize_kstack
9916 + popq %r11
9917 + popq %rax
9918 +#endif
9919 + .endm
9920 +
9921 +.macro pax_erase_kstack
9922 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9923 + call pax_erase_kstack
9924 +#endif
9925 +.endm
9926 +
9927 /*
9928 * 32bit SYSENTER instruction entry.
9929 *
9930 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9931 CFI_REGISTER rsp,rbp
9932 SWAPGS_UNSAFE_STACK
9933 movq PER_CPU_VAR(kernel_stack), %rsp
9934 - addq $(KERNEL_STACK_OFFSET),%rsp
9935 - /*
9936 - * No need to follow this irqs on/off section: the syscall
9937 - * disabled irqs, here we enable it straight after entry:
9938 - */
9939 - ENABLE_INTERRUPTS(CLBR_NONE)
9940 movl %ebp,%ebp /* zero extension */
9941 pushq_cfi $__USER32_DS
9942 /*CFI_REL_OFFSET ss,0*/
9943 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9944 CFI_REL_OFFSET rsp,0
9945 pushfq_cfi
9946 /*CFI_REL_OFFSET rflags,0*/
9947 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9948 - CFI_REGISTER rip,r10
9949 + orl $X86_EFLAGS_IF,(%rsp)
9950 + GET_THREAD_INFO(%r11)
9951 + movl TI_sysenter_return(%r11), %r11d
9952 + CFI_REGISTER rip,r11
9953 pushq_cfi $__USER32_CS
9954 /*CFI_REL_OFFSET cs,0*/
9955 movl %eax, %eax
9956 - pushq_cfi %r10
9957 + pushq_cfi %r11
9958 CFI_REL_OFFSET rip,0
9959 pushq_cfi %rax
9960 cld
9961 SAVE_ARGS 0,1,0
9962 + pax_enter_kernel_user
9963 +
9964 +#ifdef CONFIG_PAX_RANDKSTACK
9965 + pax_erase_kstack
9966 +#endif
9967 +
9968 + /*
9969 + * No need to follow this irqs on/off section: the syscall
9970 + * disabled irqs, here we enable it straight after entry:
9971 + */
9972 + ENABLE_INTERRUPTS(CLBR_NONE)
9973 /* no need to do an access_ok check here because rbp has been
9974 32bit zero extended */
9975 +
9976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9977 + mov $PAX_USER_SHADOW_BASE,%r11
9978 + add %r11,%rbp
9979 +#endif
9980 +
9981 ASM_STAC
9982 1: movl (%rbp),%ebp
9983 _ASM_EXTABLE(1b,ia32_badarg)
9984 ASM_CLAC
9985 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9986 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9987 + GET_THREAD_INFO(%r11)
9988 + orl $TS_COMPAT,TI_status(%r11)
9989 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9990 CFI_REMEMBER_STATE
9991 jnz sysenter_tracesys
9992 cmpq $(IA32_NR_syscalls-1),%rax
9993 @@ -162,12 +204,15 @@ sysenter_do_call:
9994 sysenter_dispatch:
9995 call *ia32_sys_call_table(,%rax,8)
9996 movq %rax,RAX-ARGOFFSET(%rsp)
9997 + GET_THREAD_INFO(%r11)
9998 DISABLE_INTERRUPTS(CLBR_NONE)
9999 TRACE_IRQS_OFF
10000 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10001 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10002 jnz sysexit_audit
10003 sysexit_from_sys_call:
10004 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10005 + pax_exit_kernel_user
10006 + pax_erase_kstack
10007 + andl $~TS_COMPAT,TI_status(%r11)
10008 /* clear IF, that popfq doesn't enable interrupts early */
10009 andl $~0x200,EFLAGS-R11(%rsp)
10010 movl RIP-R11(%rsp),%edx /* User %eip */
10011 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
10012 movl %eax,%esi /* 2nd arg: syscall number */
10013 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
10014 call __audit_syscall_entry
10015 +
10016 + pax_erase_kstack
10017 +
10018 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
10019 cmpq $(IA32_NR_syscalls-1),%rax
10020 ja ia32_badsys
10021 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
10022 .endm
10023
10024 .macro auditsys_exit exit
10025 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10027 jnz ia32_ret_from_sys_call
10028 TRACE_IRQS_ON
10029 ENABLE_INTERRUPTS(CLBR_NONE)
10030 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
10031 1: setbe %al /* 1 if error, 0 if not */
10032 movzbl %al,%edi /* zero-extend that into %edi */
10033 call __audit_syscall_exit
10034 + GET_THREAD_INFO(%r11)
10035 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
10036 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
10037 DISABLE_INTERRUPTS(CLBR_NONE)
10038 TRACE_IRQS_OFF
10039 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10040 + testl %edi,TI_flags(%r11)
10041 jz \exit
10042 CLEAR_RREGS -ARGOFFSET
10043 jmp int_with_check
10044 @@ -237,7 +286,7 @@ sysexit_audit:
10045
10046 sysenter_tracesys:
10047 #ifdef CONFIG_AUDITSYSCALL
10048 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10049 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10050 jz sysenter_auditsys
10051 #endif
10052 SAVE_REST
10053 @@ -249,6 +298,9 @@ sysenter_tracesys:
10054 RESTORE_REST
10055 cmpq $(IA32_NR_syscalls-1),%rax
10056 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
10057 +
10058 + pax_erase_kstack
10059 +
10060 jmp sysenter_do_call
10061 CFI_ENDPROC
10062 ENDPROC(ia32_sysenter_target)
10063 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
10064 ENTRY(ia32_cstar_target)
10065 CFI_STARTPROC32 simple
10066 CFI_SIGNAL_FRAME
10067 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
10068 + CFI_DEF_CFA rsp,0
10069 CFI_REGISTER rip,rcx
10070 /*CFI_REGISTER rflags,r11*/
10071 SWAPGS_UNSAFE_STACK
10072 movl %esp,%r8d
10073 CFI_REGISTER rsp,r8
10074 movq PER_CPU_VAR(kernel_stack),%rsp
10075 + SAVE_ARGS 8*6,0,0
10076 + pax_enter_kernel_user
10077 +
10078 +#ifdef CONFIG_PAX_RANDKSTACK
10079 + pax_erase_kstack
10080 +#endif
10081 +
10082 /*
10083 * No need to follow this irqs on/off section: the syscall
10084 * disabled irqs and here we enable it straight after entry:
10085 */
10086 ENABLE_INTERRUPTS(CLBR_NONE)
10087 - SAVE_ARGS 8,0,0
10088 movl %eax,%eax /* zero extension */
10089 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10090 movq %rcx,RIP-ARGOFFSET(%rsp)
10091 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10092 /* no need to do an access_ok check here because r8 has been
10093 32bit zero extended */
10094 /* hardware stack frame is complete now */
10095 +
10096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10097 + mov $PAX_USER_SHADOW_BASE,%r11
10098 + add %r11,%r8
10099 +#endif
10100 +
10101 ASM_STAC
10102 1: movl (%r8),%r9d
10103 _ASM_EXTABLE(1b,ia32_badarg)
10104 ASM_CLAC
10105 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10106 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10107 + GET_THREAD_INFO(%r11)
10108 + orl $TS_COMPAT,TI_status(%r11)
10109 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10110 CFI_REMEMBER_STATE
10111 jnz cstar_tracesys
10112 cmpq $IA32_NR_syscalls-1,%rax
10113 @@ -319,12 +384,15 @@ cstar_do_call:
10114 cstar_dispatch:
10115 call *ia32_sys_call_table(,%rax,8)
10116 movq %rax,RAX-ARGOFFSET(%rsp)
10117 + GET_THREAD_INFO(%r11)
10118 DISABLE_INTERRUPTS(CLBR_NONE)
10119 TRACE_IRQS_OFF
10120 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10121 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10122 jnz sysretl_audit
10123 sysretl_from_sys_call:
10124 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10125 + pax_exit_kernel_user
10126 + pax_erase_kstack
10127 + andl $~TS_COMPAT,TI_status(%r11)
10128 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10129 movl RIP-ARGOFFSET(%rsp),%ecx
10130 CFI_REGISTER rip,rcx
10131 @@ -352,7 +420,7 @@ sysretl_audit:
10132
10133 cstar_tracesys:
10134 #ifdef CONFIG_AUDITSYSCALL
10135 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10136 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10137 jz cstar_auditsys
10138 #endif
10139 xchgl %r9d,%ebp
10140 @@ -366,6 +434,9 @@ cstar_tracesys:
10141 xchgl %ebp,%r9d
10142 cmpq $(IA32_NR_syscalls-1),%rax
10143 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10144 +
10145 + pax_erase_kstack
10146 +
10147 jmp cstar_do_call
10148 END(ia32_cstar_target)
10149
10150 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10151 CFI_REL_OFFSET rip,RIP-RIP
10152 PARAVIRT_ADJUST_EXCEPTION_FRAME
10153 SWAPGS
10154 - /*
10155 - * No need to follow this irqs on/off section: the syscall
10156 - * disabled irqs and here we enable it straight after entry:
10157 - */
10158 - ENABLE_INTERRUPTS(CLBR_NONE)
10159 movl %eax,%eax
10160 pushq_cfi %rax
10161 cld
10162 /* note the registers are not zero extended to the sf.
10163 this could be a problem. */
10164 SAVE_ARGS 0,1,0
10165 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10166 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10167 + pax_enter_kernel_user
10168 +
10169 +#ifdef CONFIG_PAX_RANDKSTACK
10170 + pax_erase_kstack
10171 +#endif
10172 +
10173 + /*
10174 + * No need to follow this irqs on/off section: the syscall
10175 + * disabled irqs and here we enable it straight after entry:
10176 + */
10177 + ENABLE_INTERRUPTS(CLBR_NONE)
10178 + GET_THREAD_INFO(%r11)
10179 + orl $TS_COMPAT,TI_status(%r11)
10180 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10181 jnz ia32_tracesys
10182 cmpq $(IA32_NR_syscalls-1),%rax
10183 ja ia32_badsys
10184 @@ -442,6 +520,9 @@ ia32_tracesys:
10185 RESTORE_REST
10186 cmpq $(IA32_NR_syscalls-1),%rax
10187 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10188 +
10189 + pax_erase_kstack
10190 +
10191 jmp ia32_do_call
10192 END(ia32_syscall)
10193
10194 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10195 index 86d68d1..f9960fe 100644
10196 --- a/arch/x86/ia32/sys_ia32.c
10197 +++ b/arch/x86/ia32/sys_ia32.c
10198 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10199 */
10200 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10201 {
10202 - typeof(ubuf->st_uid) uid = 0;
10203 - typeof(ubuf->st_gid) gid = 0;
10204 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
10205 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
10206 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10207 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10208 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10209 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10210 mm_segment_t old_fs = get_fs();
10211
10212 set_fs(KERNEL_DS);
10213 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10214 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10215 set_fs(old_fs);
10216 if (put_compat_timespec(&t, interval))
10217 return -EFAULT;
10218 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10219 mm_segment_t old_fs = get_fs();
10220
10221 set_fs(KERNEL_DS);
10222 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10223 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10224 set_fs(old_fs);
10225 if (!ret) {
10226 switch (_NSIG_WORDS) {
10227 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10228 if (copy_siginfo_from_user32(&info, uinfo))
10229 return -EFAULT;
10230 set_fs(KERNEL_DS);
10231 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10232 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10233 set_fs(old_fs);
10234 return ret;
10235 }
10236 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10237 return -EFAULT;
10238
10239 set_fs(KERNEL_DS);
10240 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10241 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10242 count);
10243 set_fs(old_fs);
10244
10245 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10246 index 372231c..a5aa1a1 100644
10247 --- a/arch/x86/include/asm/alternative-asm.h
10248 +++ b/arch/x86/include/asm/alternative-asm.h
10249 @@ -18,6 +18,45 @@
10250 .endm
10251 #endif
10252
10253 +#ifdef KERNEXEC_PLUGIN
10254 + .macro pax_force_retaddr_bts rip=0
10255 + btsq $63,\rip(%rsp)
10256 + .endm
10257 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10258 + .macro pax_force_retaddr rip=0, reload=0
10259 + btsq $63,\rip(%rsp)
10260 + .endm
10261 + .macro pax_force_fptr ptr
10262 + btsq $63,\ptr
10263 + .endm
10264 + .macro pax_set_fptr_mask
10265 + .endm
10266 +#endif
10267 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10268 + .macro pax_force_retaddr rip=0, reload=0
10269 + .if \reload
10270 + pax_set_fptr_mask
10271 + .endif
10272 + orq %r10,\rip(%rsp)
10273 + .endm
10274 + .macro pax_force_fptr ptr
10275 + orq %r10,\ptr
10276 + .endm
10277 + .macro pax_set_fptr_mask
10278 + movabs $0x8000000000000000,%r10
10279 + .endm
10280 +#endif
10281 +#else
10282 + .macro pax_force_retaddr rip=0, reload=0
10283 + .endm
10284 + .macro pax_force_fptr ptr
10285 + .endm
10286 + .macro pax_force_retaddr_bts rip=0
10287 + .endm
10288 + .macro pax_set_fptr_mask
10289 + .endm
10290 +#endif
10291 +
10292 .macro altinstruction_entry orig alt feature orig_len alt_len
10293 .long \orig - .
10294 .long \alt - .
10295 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10296 index 58ed6d9..f1cbe58 100644
10297 --- a/arch/x86/include/asm/alternative.h
10298 +++ b/arch/x86/include/asm/alternative.h
10299 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10300 ".pushsection .discard,\"aw\",@progbits\n" \
10301 DISCARD_ENTRY(1) \
10302 ".popsection\n" \
10303 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10304 + ".pushsection .altinstr_replacement, \"a\"\n" \
10305 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10306 ".popsection"
10307
10308 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10309 DISCARD_ENTRY(1) \
10310 DISCARD_ENTRY(2) \
10311 ".popsection\n" \
10312 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10313 + ".pushsection .altinstr_replacement, \"a\"\n" \
10314 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10315 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10316 ".popsection"
10317 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10318 index 3388034..050f0b9 100644
10319 --- a/arch/x86/include/asm/apic.h
10320 +++ b/arch/x86/include/asm/apic.h
10321 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10322
10323 #ifdef CONFIG_X86_LOCAL_APIC
10324
10325 -extern unsigned int apic_verbosity;
10326 +extern int apic_verbosity;
10327 extern int local_apic_timer_c2_ok;
10328
10329 extern int disable_apic;
10330 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10331 index 20370c6..a2eb9b0 100644
10332 --- a/arch/x86/include/asm/apm.h
10333 +++ b/arch/x86/include/asm/apm.h
10334 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10335 __asm__ __volatile__(APM_DO_ZERO_SEGS
10336 "pushl %%edi\n\t"
10337 "pushl %%ebp\n\t"
10338 - "lcall *%%cs:apm_bios_entry\n\t"
10339 + "lcall *%%ss:apm_bios_entry\n\t"
10340 "setc %%al\n\t"
10341 "popl %%ebp\n\t"
10342 "popl %%edi\n\t"
10343 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10344 __asm__ __volatile__(APM_DO_ZERO_SEGS
10345 "pushl %%edi\n\t"
10346 "pushl %%ebp\n\t"
10347 - "lcall *%%cs:apm_bios_entry\n\t"
10348 + "lcall *%%ss:apm_bios_entry\n\t"
10349 "setc %%bl\n\t"
10350 "popl %%ebp\n\t"
10351 "popl %%edi\n\t"
10352 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10353 index b6c3b82..b4c077a 100644
10354 --- a/arch/x86/include/asm/atomic.h
10355 +++ b/arch/x86/include/asm/atomic.h
10356 @@ -22,7 +22,18 @@
10357 */
10358 static inline int atomic_read(const atomic_t *v)
10359 {
10360 - return (*(volatile int *)&(v)->counter);
10361 + return (*(volatile const int *)&(v)->counter);
10362 +}
10363 +
10364 +/**
10365 + * atomic_read_unchecked - read atomic variable
10366 + * @v: pointer of type atomic_unchecked_t
10367 + *
10368 + * Atomically reads the value of @v.
10369 + */
10370 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10371 +{
10372 + return (*(volatile const int *)&(v)->counter);
10373 }
10374
10375 /**
10376 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10377 }
10378
10379 /**
10380 + * atomic_set_unchecked - set atomic variable
10381 + * @v: pointer of type atomic_unchecked_t
10382 + * @i: required value
10383 + *
10384 + * Atomically sets the value of @v to @i.
10385 + */
10386 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10387 +{
10388 + v->counter = i;
10389 +}
10390 +
10391 +/**
10392 * atomic_add - add integer to atomic variable
10393 * @i: integer value to add
10394 * @v: pointer of type atomic_t
10395 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10396 */
10397 static inline void atomic_add(int i, atomic_t *v)
10398 {
10399 - asm volatile(LOCK_PREFIX "addl %1,%0"
10400 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10401 +
10402 +#ifdef CONFIG_PAX_REFCOUNT
10403 + "jno 0f\n"
10404 + LOCK_PREFIX "subl %1,%0\n"
10405 + "int $4\n0:\n"
10406 + _ASM_EXTABLE(0b, 0b)
10407 +#endif
10408 +
10409 + : "+m" (v->counter)
10410 + : "ir" (i));
10411 +}
10412 +
10413 +/**
10414 + * atomic_add_unchecked - add integer to atomic variable
10415 + * @i: integer value to add
10416 + * @v: pointer of type atomic_unchecked_t
10417 + *
10418 + * Atomically adds @i to @v.
10419 + */
10420 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10421 +{
10422 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10423 : "+m" (v->counter)
10424 : "ir" (i));
10425 }
10426 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10427 */
10428 static inline void atomic_sub(int i, atomic_t *v)
10429 {
10430 - asm volatile(LOCK_PREFIX "subl %1,%0"
10431 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10432 +
10433 +#ifdef CONFIG_PAX_REFCOUNT
10434 + "jno 0f\n"
10435 + LOCK_PREFIX "addl %1,%0\n"
10436 + "int $4\n0:\n"
10437 + _ASM_EXTABLE(0b, 0b)
10438 +#endif
10439 +
10440 + : "+m" (v->counter)
10441 + : "ir" (i));
10442 +}
10443 +
10444 +/**
10445 + * atomic_sub_unchecked - subtract integer from atomic variable
10446 + * @i: integer value to subtract
10447 + * @v: pointer of type atomic_unchecked_t
10448 + *
10449 + * Atomically subtracts @i from @v.
10450 + */
10451 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10452 +{
10453 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10454 : "+m" (v->counter)
10455 : "ir" (i));
10456 }
10457 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10458 {
10459 unsigned char c;
10460
10461 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10462 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10463 +
10464 +#ifdef CONFIG_PAX_REFCOUNT
10465 + "jno 0f\n"
10466 + LOCK_PREFIX "addl %2,%0\n"
10467 + "int $4\n0:\n"
10468 + _ASM_EXTABLE(0b, 0b)
10469 +#endif
10470 +
10471 + "sete %1\n"
10472 : "+m" (v->counter), "=qm" (c)
10473 : "ir" (i) : "memory");
10474 return c;
10475 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10476 */
10477 static inline void atomic_inc(atomic_t *v)
10478 {
10479 - asm volatile(LOCK_PREFIX "incl %0"
10480 + asm volatile(LOCK_PREFIX "incl %0\n"
10481 +
10482 +#ifdef CONFIG_PAX_REFCOUNT
10483 + "jno 0f\n"
10484 + LOCK_PREFIX "decl %0\n"
10485 + "int $4\n0:\n"
10486 + _ASM_EXTABLE(0b, 0b)
10487 +#endif
10488 +
10489 + : "+m" (v->counter));
10490 +}
10491 +
10492 +/**
10493 + * atomic_inc_unchecked - increment atomic variable
10494 + * @v: pointer of type atomic_unchecked_t
10495 + *
10496 + * Atomically increments @v by 1.
10497 + */
10498 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10499 +{
10500 + asm volatile(LOCK_PREFIX "incl %0\n"
10501 : "+m" (v->counter));
10502 }
10503
10504 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10505 */
10506 static inline void atomic_dec(atomic_t *v)
10507 {
10508 - asm volatile(LOCK_PREFIX "decl %0"
10509 + asm volatile(LOCK_PREFIX "decl %0\n"
10510 +
10511 +#ifdef CONFIG_PAX_REFCOUNT
10512 + "jno 0f\n"
10513 + LOCK_PREFIX "incl %0\n"
10514 + "int $4\n0:\n"
10515 + _ASM_EXTABLE(0b, 0b)
10516 +#endif
10517 +
10518 + : "+m" (v->counter));
10519 +}
10520 +
10521 +/**
10522 + * atomic_dec_unchecked - decrement atomic variable
10523 + * @v: pointer of type atomic_unchecked_t
10524 + *
10525 + * Atomically decrements @v by 1.
10526 + */
10527 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10528 +{
10529 + asm volatile(LOCK_PREFIX "decl %0\n"
10530 : "+m" (v->counter));
10531 }
10532
10533 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10534 {
10535 unsigned char c;
10536
10537 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10538 + asm volatile(LOCK_PREFIX "decl %0\n"
10539 +
10540 +#ifdef CONFIG_PAX_REFCOUNT
10541 + "jno 0f\n"
10542 + LOCK_PREFIX "incl %0\n"
10543 + "int $4\n0:\n"
10544 + _ASM_EXTABLE(0b, 0b)
10545 +#endif
10546 +
10547 + "sete %1\n"
10548 : "+m" (v->counter), "=qm" (c)
10549 : : "memory");
10550 return c != 0;
10551 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10552 {
10553 unsigned char c;
10554
10555 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10556 + asm volatile(LOCK_PREFIX "incl %0\n"
10557 +
10558 +#ifdef CONFIG_PAX_REFCOUNT
10559 + "jno 0f\n"
10560 + LOCK_PREFIX "decl %0\n"
10561 + "int $4\n0:\n"
10562 + _ASM_EXTABLE(0b, 0b)
10563 +#endif
10564 +
10565 + "sete %1\n"
10566 + : "+m" (v->counter), "=qm" (c)
10567 + : : "memory");
10568 + return c != 0;
10569 +}
10570 +
10571 +/**
10572 + * atomic_inc_and_test_unchecked - increment and test
10573 + * @v: pointer of type atomic_unchecked_t
10574 + *
10575 + * Atomically increments @v by 1
10576 + * and returns true if the result is zero, or false for all
10577 + * other cases.
10578 + */
10579 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10580 +{
10581 + unsigned char c;
10582 +
10583 + asm volatile(LOCK_PREFIX "incl %0\n"
10584 + "sete %1\n"
10585 : "+m" (v->counter), "=qm" (c)
10586 : : "memory");
10587 return c != 0;
10588 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10589 {
10590 unsigned char c;
10591
10592 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10593 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10594 +
10595 +#ifdef CONFIG_PAX_REFCOUNT
10596 + "jno 0f\n"
10597 + LOCK_PREFIX "subl %2,%0\n"
10598 + "int $4\n0:\n"
10599 + _ASM_EXTABLE(0b, 0b)
10600 +#endif
10601 +
10602 + "sets %1\n"
10603 : "+m" (v->counter), "=qm" (c)
10604 : "ir" (i) : "memory");
10605 return c;
10606 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10607 goto no_xadd;
10608 #endif
10609 /* Modern 486+ processor */
10610 - return i + xadd(&v->counter, i);
10611 + return i + xadd_check_overflow(&v->counter, i);
10612
10613 #ifdef CONFIG_M386
10614 no_xadd: /* Legacy 386 processor */
10615 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10616 }
10617
10618 /**
10619 + * atomic_add_return_unchecked - add integer and return
10620 + * @i: integer value to add
10621 + * @v: pointer of type atomic_unchecked_t
10622 + *
10623 + * Atomically adds @i to @v and returns @i + @v
10624 + */
10625 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10626 +{
10627 +#ifdef CONFIG_M386
10628 + int __i;
10629 + unsigned long flags;
10630 + if (unlikely(boot_cpu_data.x86 <= 3))
10631 + goto no_xadd;
10632 +#endif
10633 + /* Modern 486+ processor */
10634 + return i + xadd(&v->counter, i);
10635 +
10636 +#ifdef CONFIG_M386
10637 +no_xadd: /* Legacy 386 processor */
10638 + raw_local_irq_save(flags);
10639 + __i = atomic_read_unchecked(v);
10640 + atomic_set_unchecked(v, i + __i);
10641 + raw_local_irq_restore(flags);
10642 + return i + __i;
10643 +#endif
10644 +}
10645 +
10646 +/**
10647 * atomic_sub_return - subtract integer and return
10648 * @v: pointer of type atomic_t
10649 * @i: integer value to subtract
10650 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10651 }
10652
10653 #define atomic_inc_return(v) (atomic_add_return(1, v))
10654 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10655 +{
10656 + return atomic_add_return_unchecked(1, v);
10657 +}
10658 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10659
10660 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10661 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10662 return cmpxchg(&v->counter, old, new);
10663 }
10664
10665 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10666 +{
10667 + return cmpxchg(&v->counter, old, new);
10668 +}
10669 +
10670 static inline int atomic_xchg(atomic_t *v, int new)
10671 {
10672 return xchg(&v->counter, new);
10673 }
10674
10675 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10676 +{
10677 + return xchg(&v->counter, new);
10678 +}
10679 +
10680 /**
10681 * __atomic_add_unless - add unless the number is already a given value
10682 * @v: pointer of type atomic_t
10683 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10684 */
10685 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10686 {
10687 - int c, old;
10688 + int c, old, new;
10689 c = atomic_read(v);
10690 for (;;) {
10691 - if (unlikely(c == (u)))
10692 + if (unlikely(c == u))
10693 break;
10694 - old = atomic_cmpxchg((v), c, c + (a));
10695 +
10696 + asm volatile("addl %2,%0\n"
10697 +
10698 +#ifdef CONFIG_PAX_REFCOUNT
10699 + "jno 0f\n"
10700 + "subl %2,%0\n"
10701 + "int $4\n0:\n"
10702 + _ASM_EXTABLE(0b, 0b)
10703 +#endif
10704 +
10705 + : "=r" (new)
10706 + : "0" (c), "ir" (a));
10707 +
10708 + old = atomic_cmpxchg(v, c, new);
10709 if (likely(old == c))
10710 break;
10711 c = old;
10712 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10713 }
10714
10715 /**
10716 + * atomic_inc_not_zero_hint - increment if not null
10717 + * @v: pointer of type atomic_t
10718 + * @hint: probable value of the atomic before the increment
10719 + *
10720 + * This version of atomic_inc_not_zero() gives a hint of probable
10721 + * value of the atomic. This helps processor to not read the memory
10722 + * before doing the atomic read/modify/write cycle, lowering
10723 + * number of bus transactions on some arches.
10724 + *
10725 + * Returns: 0 if increment was not done, 1 otherwise.
10726 + */
10727 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10728 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10729 +{
10730 + int val, c = hint, new;
10731 +
10732 + /* sanity test, should be removed by compiler if hint is a constant */
10733 + if (!hint)
10734 + return __atomic_add_unless(v, 1, 0);
10735 +
10736 + do {
10737 + asm volatile("incl %0\n"
10738 +
10739 +#ifdef CONFIG_PAX_REFCOUNT
10740 + "jno 0f\n"
10741 + "decl %0\n"
10742 + "int $4\n0:\n"
10743 + _ASM_EXTABLE(0b, 0b)
10744 +#endif
10745 +
10746 + : "=r" (new)
10747 + : "0" (c));
10748 +
10749 + val = atomic_cmpxchg(v, c, new);
10750 + if (val == c)
10751 + return 1;
10752 + c = val;
10753 + } while (c);
10754 +
10755 + return 0;
10756 +}
10757 +
10758 +/**
10759 * atomic_inc_short - increment of a short integer
10760 * @v: pointer to type int
10761 *
10762 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10763 #endif
10764
10765 /* These are x86-specific, used by some header files */
10766 -#define atomic_clear_mask(mask, addr) \
10767 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10768 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10769 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10770 +{
10771 + asm volatile(LOCK_PREFIX "andl %1,%0"
10772 + : "+m" (v->counter)
10773 + : "r" (~(mask))
10774 + : "memory");
10775 +}
10776
10777 -#define atomic_set_mask(mask, addr) \
10778 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10779 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10780 - : "memory")
10781 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10782 +{
10783 + asm volatile(LOCK_PREFIX "andl %1,%0"
10784 + : "+m" (v->counter)
10785 + : "r" (~(mask))
10786 + : "memory");
10787 +}
10788 +
10789 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10790 +{
10791 + asm volatile(LOCK_PREFIX "orl %1,%0"
10792 + : "+m" (v->counter)
10793 + : "r" (mask)
10794 + : "memory");
10795 +}
10796 +
10797 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10798 +{
10799 + asm volatile(LOCK_PREFIX "orl %1,%0"
10800 + : "+m" (v->counter)
10801 + : "r" (mask)
10802 + : "memory");
10803 +}
10804
10805 /* Atomic operations are already serializing on x86 */
10806 #define smp_mb__before_atomic_dec() barrier()
10807 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10808 index b154de7..aadebd8 100644
10809 --- a/arch/x86/include/asm/atomic64_32.h
10810 +++ b/arch/x86/include/asm/atomic64_32.h
10811 @@ -12,6 +12,14 @@ typedef struct {
10812 u64 __aligned(8) counter;
10813 } atomic64_t;
10814
10815 +#ifdef CONFIG_PAX_REFCOUNT
10816 +typedef struct {
10817 + u64 __aligned(8) counter;
10818 +} atomic64_unchecked_t;
10819 +#else
10820 +typedef atomic64_t atomic64_unchecked_t;
10821 +#endif
10822 +
10823 #define ATOMIC64_INIT(val) { (val) }
10824
10825 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10826 @@ -37,21 +45,31 @@ typedef struct {
10827 ATOMIC64_DECL_ONE(sym##_386)
10828
10829 ATOMIC64_DECL_ONE(add_386);
10830 +ATOMIC64_DECL_ONE(add_unchecked_386);
10831 ATOMIC64_DECL_ONE(sub_386);
10832 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10833 ATOMIC64_DECL_ONE(inc_386);
10834 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10835 ATOMIC64_DECL_ONE(dec_386);
10836 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10837 #endif
10838
10839 #define alternative_atomic64(f, out, in...) \
10840 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10841
10842 ATOMIC64_DECL(read);
10843 +ATOMIC64_DECL(read_unchecked);
10844 ATOMIC64_DECL(set);
10845 +ATOMIC64_DECL(set_unchecked);
10846 ATOMIC64_DECL(xchg);
10847 ATOMIC64_DECL(add_return);
10848 +ATOMIC64_DECL(add_return_unchecked);
10849 ATOMIC64_DECL(sub_return);
10850 +ATOMIC64_DECL(sub_return_unchecked);
10851 ATOMIC64_DECL(inc_return);
10852 +ATOMIC64_DECL(inc_return_unchecked);
10853 ATOMIC64_DECL(dec_return);
10854 +ATOMIC64_DECL(dec_return_unchecked);
10855 ATOMIC64_DECL(dec_if_positive);
10856 ATOMIC64_DECL(inc_not_zero);
10857 ATOMIC64_DECL(add_unless);
10858 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10859 }
10860
10861 /**
10862 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10863 + * @p: pointer to type atomic64_unchecked_t
10864 + * @o: expected value
10865 + * @n: new value
10866 + *
10867 + * Atomically sets @v to @n if it was equal to @o and returns
10868 + * the old value.
10869 + */
10870 +
10871 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10872 +{
10873 + return cmpxchg64(&v->counter, o, n);
10874 +}
10875 +
10876 +/**
10877 * atomic64_xchg - xchg atomic64 variable
10878 * @v: pointer to type atomic64_t
10879 * @n: value to assign
10880 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10881 }
10882
10883 /**
10884 + * atomic64_set_unchecked - set atomic64 variable
10885 + * @v: pointer to type atomic64_unchecked_t
10886 + * @n: value to assign
10887 + *
10888 + * Atomically sets the value of @v to @n.
10889 + */
10890 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10891 +{
10892 + unsigned high = (unsigned)(i >> 32);
10893 + unsigned low = (unsigned)i;
10894 + alternative_atomic64(set, /* no output */,
10895 + "S" (v), "b" (low), "c" (high)
10896 + : "eax", "edx", "memory");
10897 +}
10898 +
10899 +/**
10900 * atomic64_read - read atomic64 variable
10901 * @v: pointer to type atomic64_t
10902 *
10903 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10904 }
10905
10906 /**
10907 + * atomic64_read_unchecked - read atomic64 variable
10908 + * @v: pointer to type atomic64_unchecked_t
10909 + *
10910 + * Atomically reads the value of @v and returns it.
10911 + */
10912 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10913 +{
10914 + long long r;
10915 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10916 + return r;
10917 + }
10918 +
10919 +/**
10920 * atomic64_add_return - add and return
10921 * @i: integer value to add
10922 * @v: pointer to type atomic64_t
10923 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10924 return i;
10925 }
10926
10927 +/**
10928 + * atomic64_add_return_unchecked - add and return
10929 + * @i: integer value to add
10930 + * @v: pointer to type atomic64_unchecked_t
10931 + *
10932 + * Atomically adds @i to @v and returns @i + *@v
10933 + */
10934 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10935 +{
10936 + alternative_atomic64(add_return_unchecked,
10937 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10938 + ASM_NO_INPUT_CLOBBER("memory"));
10939 + return i;
10940 +}
10941 +
10942 /*
10943 * Other variants with different arithmetic operators:
10944 */
10945 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10946 return a;
10947 }
10948
10949 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10950 +{
10951 + long long a;
10952 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10953 + "S" (v) : "memory", "ecx");
10954 + return a;
10955 +}
10956 +
10957 static inline long long atomic64_dec_return(atomic64_t *v)
10958 {
10959 long long a;
10960 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10961 }
10962
10963 /**
10964 + * atomic64_add_unchecked - add integer to atomic64 variable
10965 + * @i: integer value to add
10966 + * @v: pointer to type atomic64_unchecked_t
10967 + *
10968 + * Atomically adds @i to @v.
10969 + */
10970 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10971 +{
10972 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10973 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10974 + ASM_NO_INPUT_CLOBBER("memory"));
10975 + return i;
10976 +}
10977 +
10978 +/**
10979 * atomic64_sub - subtract the atomic64 variable
10980 * @i: integer value to subtract
10981 * @v: pointer to type atomic64_t
10982 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10983 index 0e1cbfc..5623683 100644
10984 --- a/arch/x86/include/asm/atomic64_64.h
10985 +++ b/arch/x86/include/asm/atomic64_64.h
10986 @@ -18,7 +18,19 @@
10987 */
10988 static inline long atomic64_read(const atomic64_t *v)
10989 {
10990 - return (*(volatile long *)&(v)->counter);
10991 + return (*(volatile const long *)&(v)->counter);
10992 +}
10993 +
10994 +/**
10995 + * atomic64_read_unchecked - read atomic64 variable
10996 + * @v: pointer of type atomic64_unchecked_t
10997 + *
10998 + * Atomically reads the value of @v.
10999 + * Doesn't imply a read memory barrier.
11000 + */
11001 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
11002 +{
11003 + return (*(volatile const long *)&(v)->counter);
11004 }
11005
11006 /**
11007 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
11008 }
11009
11010 /**
11011 + * atomic64_set_unchecked - set atomic64 variable
11012 + * @v: pointer to type atomic64_unchecked_t
11013 + * @i: required value
11014 + *
11015 + * Atomically sets the value of @v to @i.
11016 + */
11017 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
11018 +{
11019 + v->counter = i;
11020 +}
11021 +
11022 +/**
11023 * atomic64_add - add integer to atomic64 variable
11024 * @i: integer value to add
11025 * @v: pointer to type atomic64_t
11026 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
11027 */
11028 static inline void atomic64_add(long i, atomic64_t *v)
11029 {
11030 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
11031 +
11032 +#ifdef CONFIG_PAX_REFCOUNT
11033 + "jno 0f\n"
11034 + LOCK_PREFIX "subq %1,%0\n"
11035 + "int $4\n0:\n"
11036 + _ASM_EXTABLE(0b, 0b)
11037 +#endif
11038 +
11039 + : "=m" (v->counter)
11040 + : "er" (i), "m" (v->counter));
11041 +}
11042 +
11043 +/**
11044 + * atomic64_add_unchecked - add integer to atomic64 variable
11045 + * @i: integer value to add
11046 + * @v: pointer to type atomic64_unchecked_t
11047 + *
11048 + * Atomically adds @i to @v.
11049 + */
11050 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
11051 +{
11052 asm volatile(LOCK_PREFIX "addq %1,%0"
11053 : "=m" (v->counter)
11054 : "er" (i), "m" (v->counter));
11055 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
11056 */
11057 static inline void atomic64_sub(long i, atomic64_t *v)
11058 {
11059 - asm volatile(LOCK_PREFIX "subq %1,%0"
11060 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11061 +
11062 +#ifdef CONFIG_PAX_REFCOUNT
11063 + "jno 0f\n"
11064 + LOCK_PREFIX "addq %1,%0\n"
11065 + "int $4\n0:\n"
11066 + _ASM_EXTABLE(0b, 0b)
11067 +#endif
11068 +
11069 + : "=m" (v->counter)
11070 + : "er" (i), "m" (v->counter));
11071 +}
11072 +
11073 +/**
11074 + * atomic64_sub_unchecked - subtract the atomic64 variable
11075 + * @i: integer value to subtract
11076 + * @v: pointer to type atomic64_unchecked_t
11077 + *
11078 + * Atomically subtracts @i from @v.
11079 + */
11080 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11081 +{
11082 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11083 : "=m" (v->counter)
11084 : "er" (i), "m" (v->counter));
11085 }
11086 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11087 {
11088 unsigned char c;
11089
11090 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11091 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
11092 +
11093 +#ifdef CONFIG_PAX_REFCOUNT
11094 + "jno 0f\n"
11095 + LOCK_PREFIX "addq %2,%0\n"
11096 + "int $4\n0:\n"
11097 + _ASM_EXTABLE(0b, 0b)
11098 +#endif
11099 +
11100 + "sete %1\n"
11101 : "=m" (v->counter), "=qm" (c)
11102 : "er" (i), "m" (v->counter) : "memory");
11103 return c;
11104 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11105 */
11106 static inline void atomic64_inc(atomic64_t *v)
11107 {
11108 + asm volatile(LOCK_PREFIX "incq %0\n"
11109 +
11110 +#ifdef CONFIG_PAX_REFCOUNT
11111 + "jno 0f\n"
11112 + LOCK_PREFIX "decq %0\n"
11113 + "int $4\n0:\n"
11114 + _ASM_EXTABLE(0b, 0b)
11115 +#endif
11116 +
11117 + : "=m" (v->counter)
11118 + : "m" (v->counter));
11119 +}
11120 +
11121 +/**
11122 + * atomic64_inc_unchecked - increment atomic64 variable
11123 + * @v: pointer to type atomic64_unchecked_t
11124 + *
11125 + * Atomically increments @v by 1.
11126 + */
11127 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11128 +{
11129 asm volatile(LOCK_PREFIX "incq %0"
11130 : "=m" (v->counter)
11131 : "m" (v->counter));
11132 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11133 */
11134 static inline void atomic64_dec(atomic64_t *v)
11135 {
11136 - asm volatile(LOCK_PREFIX "decq %0"
11137 + asm volatile(LOCK_PREFIX "decq %0\n"
11138 +
11139 +#ifdef CONFIG_PAX_REFCOUNT
11140 + "jno 0f\n"
11141 + LOCK_PREFIX "incq %0\n"
11142 + "int $4\n0:\n"
11143 + _ASM_EXTABLE(0b, 0b)
11144 +#endif
11145 +
11146 + : "=m" (v->counter)
11147 + : "m" (v->counter));
11148 +}
11149 +
11150 +/**
11151 + * atomic64_dec_unchecked - decrement atomic64 variable
11152 + * @v: pointer to type atomic64_t
11153 + *
11154 + * Atomically decrements @v by 1.
11155 + */
11156 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11157 +{
11158 + asm volatile(LOCK_PREFIX "decq %0\n"
11159 : "=m" (v->counter)
11160 : "m" (v->counter));
11161 }
11162 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11163 {
11164 unsigned char c;
11165
11166 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
11167 + asm volatile(LOCK_PREFIX "decq %0\n"
11168 +
11169 +#ifdef CONFIG_PAX_REFCOUNT
11170 + "jno 0f\n"
11171 + LOCK_PREFIX "incq %0\n"
11172 + "int $4\n0:\n"
11173 + _ASM_EXTABLE(0b, 0b)
11174 +#endif
11175 +
11176 + "sete %1\n"
11177 : "=m" (v->counter), "=qm" (c)
11178 : "m" (v->counter) : "memory");
11179 return c != 0;
11180 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11181 {
11182 unsigned char c;
11183
11184 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
11185 + asm volatile(LOCK_PREFIX "incq %0\n"
11186 +
11187 +#ifdef CONFIG_PAX_REFCOUNT
11188 + "jno 0f\n"
11189 + LOCK_PREFIX "decq %0\n"
11190 + "int $4\n0:\n"
11191 + _ASM_EXTABLE(0b, 0b)
11192 +#endif
11193 +
11194 + "sete %1\n"
11195 : "=m" (v->counter), "=qm" (c)
11196 : "m" (v->counter) : "memory");
11197 return c != 0;
11198 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11199 {
11200 unsigned char c;
11201
11202 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11203 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
11204 +
11205 +#ifdef CONFIG_PAX_REFCOUNT
11206 + "jno 0f\n"
11207 + LOCK_PREFIX "subq %2,%0\n"
11208 + "int $4\n0:\n"
11209 + _ASM_EXTABLE(0b, 0b)
11210 +#endif
11211 +
11212 + "sets %1\n"
11213 : "=m" (v->counter), "=qm" (c)
11214 : "er" (i), "m" (v->counter) : "memory");
11215 return c;
11216 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11217 */
11218 static inline long atomic64_add_return(long i, atomic64_t *v)
11219 {
11220 + return i + xadd_check_overflow(&v->counter, i);
11221 +}
11222 +
11223 +/**
11224 + * atomic64_add_return_unchecked - add and return
11225 + * @i: integer value to add
11226 + * @v: pointer to type atomic64_unchecked_t
11227 + *
11228 + * Atomically adds @i to @v and returns @i + @v
11229 + */
11230 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11231 +{
11232 return i + xadd(&v->counter, i);
11233 }
11234
11235 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11236 }
11237
11238 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11239 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11240 +{
11241 + return atomic64_add_return_unchecked(1, v);
11242 +}
11243 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11244
11245 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11246 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11247 return cmpxchg(&v->counter, old, new);
11248 }
11249
11250 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11251 +{
11252 + return cmpxchg(&v->counter, old, new);
11253 +}
11254 +
11255 static inline long atomic64_xchg(atomic64_t *v, long new)
11256 {
11257 return xchg(&v->counter, new);
11258 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11259 */
11260 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11261 {
11262 - long c, old;
11263 + long c, old, new;
11264 c = atomic64_read(v);
11265 for (;;) {
11266 - if (unlikely(c == (u)))
11267 + if (unlikely(c == u))
11268 break;
11269 - old = atomic64_cmpxchg((v), c, c + (a));
11270 +
11271 + asm volatile("add %2,%0\n"
11272 +
11273 +#ifdef CONFIG_PAX_REFCOUNT
11274 + "jno 0f\n"
11275 + "sub %2,%0\n"
11276 + "int $4\n0:\n"
11277 + _ASM_EXTABLE(0b, 0b)
11278 +#endif
11279 +
11280 + : "=r" (new)
11281 + : "0" (c), "ir" (a));
11282 +
11283 + old = atomic64_cmpxchg(v, c, new);
11284 if (likely(old == c))
11285 break;
11286 c = old;
11287 }
11288 - return c != (u);
11289 + return c != u;
11290 }
11291
11292 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11293 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11294 index 6dfd019..0c6699f 100644
11295 --- a/arch/x86/include/asm/bitops.h
11296 +++ b/arch/x86/include/asm/bitops.h
11297 @@ -40,7 +40,7 @@
11298 * a mask operation on a byte.
11299 */
11300 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11301 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11302 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11303 #define CONST_MASK(nr) (1 << ((nr) & 7))
11304
11305 /**
11306 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11307 index b13fe63..0dab13a 100644
11308 --- a/arch/x86/include/asm/boot.h
11309 +++ b/arch/x86/include/asm/boot.h
11310 @@ -11,10 +11,15 @@
11311 #include <asm/pgtable_types.h>
11312
11313 /* Physical address where kernel should be loaded. */
11314 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11315 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11316 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11317 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11318
11319 +#ifndef __ASSEMBLY__
11320 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
11321 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11322 +#endif
11323 +
11324 /* Minimum kernel alignment, as a power of two */
11325 #ifdef CONFIG_X86_64
11326 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11327 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11328 index 48f99f1..d78ebf9 100644
11329 --- a/arch/x86/include/asm/cache.h
11330 +++ b/arch/x86/include/asm/cache.h
11331 @@ -5,12 +5,13 @@
11332
11333 /* L1 cache line size */
11334 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11335 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11336 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11337
11338 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11339 +#define __read_only __attribute__((__section__(".data..read_only")))
11340
11341 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11342 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11343 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11344
11345 #ifdef CONFIG_X86_VSMP
11346 #ifdef CONFIG_SMP
11347 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11348 index 9863ee3..4a1f8e1 100644
11349 --- a/arch/x86/include/asm/cacheflush.h
11350 +++ b/arch/x86/include/asm/cacheflush.h
11351 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11352 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11353
11354 if (pg_flags == _PGMT_DEFAULT)
11355 - return -1;
11356 + return ~0UL;
11357 else if (pg_flags == _PGMT_WC)
11358 return _PAGE_CACHE_WC;
11359 else if (pg_flags == _PGMT_UC_MINUS)
11360 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11361 index 46fc474..b02b0f9 100644
11362 --- a/arch/x86/include/asm/checksum_32.h
11363 +++ b/arch/x86/include/asm/checksum_32.h
11364 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11365 int len, __wsum sum,
11366 int *src_err_ptr, int *dst_err_ptr);
11367
11368 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11369 + int len, __wsum sum,
11370 + int *src_err_ptr, int *dst_err_ptr);
11371 +
11372 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11373 + int len, __wsum sum,
11374 + int *src_err_ptr, int *dst_err_ptr);
11375 +
11376 /*
11377 * Note: when you get a NULL pointer exception here this means someone
11378 * passed in an incorrect kernel address to one of these functions.
11379 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11380 int *err_ptr)
11381 {
11382 might_sleep();
11383 - return csum_partial_copy_generic((__force void *)src, dst,
11384 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11385 len, sum, err_ptr, NULL);
11386 }
11387
11388 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11389 {
11390 might_sleep();
11391 if (access_ok(VERIFY_WRITE, dst, len))
11392 - return csum_partial_copy_generic(src, (__force void *)dst,
11393 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11394 len, sum, NULL, err_ptr);
11395
11396 if (len)
11397 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11398 index 8d871ea..c1a0dc9 100644
11399 --- a/arch/x86/include/asm/cmpxchg.h
11400 +++ b/arch/x86/include/asm/cmpxchg.h
11401 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11402 __compiletime_error("Bad argument size for cmpxchg");
11403 extern void __xadd_wrong_size(void)
11404 __compiletime_error("Bad argument size for xadd");
11405 +extern void __xadd_check_overflow_wrong_size(void)
11406 + __compiletime_error("Bad argument size for xadd_check_overflow");
11407 extern void __add_wrong_size(void)
11408 __compiletime_error("Bad argument size for add");
11409 +extern void __add_check_overflow_wrong_size(void)
11410 + __compiletime_error("Bad argument size for add_check_overflow");
11411
11412 /*
11413 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11414 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11415 __ret; \
11416 })
11417
11418 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11419 + ({ \
11420 + __typeof__ (*(ptr)) __ret = (arg); \
11421 + switch (sizeof(*(ptr))) { \
11422 + case __X86_CASE_L: \
11423 + asm volatile (lock #op "l %0, %1\n" \
11424 + "jno 0f\n" \
11425 + "mov %0,%1\n" \
11426 + "int $4\n0:\n" \
11427 + _ASM_EXTABLE(0b, 0b) \
11428 + : "+r" (__ret), "+m" (*(ptr)) \
11429 + : : "memory", "cc"); \
11430 + break; \
11431 + case __X86_CASE_Q: \
11432 + asm volatile (lock #op "q %q0, %1\n" \
11433 + "jno 0f\n" \
11434 + "mov %0,%1\n" \
11435 + "int $4\n0:\n" \
11436 + _ASM_EXTABLE(0b, 0b) \
11437 + : "+r" (__ret), "+m" (*(ptr)) \
11438 + : : "memory", "cc"); \
11439 + break; \
11440 + default: \
11441 + __ ## op ## _check_overflow_wrong_size(); \
11442 + } \
11443 + __ret; \
11444 + })
11445 +
11446 /*
11447 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11448 * Since this is generally used to protect other memory information, we
11449 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11450 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11451 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11452
11453 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11454 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11455 +
11456 #define __add(ptr, inc, lock) \
11457 ({ \
11458 __typeof__ (*(ptr)) __ret = (inc); \
11459 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11460 index 8c297aa..7a90f03 100644
11461 --- a/arch/x86/include/asm/cpufeature.h
11462 +++ b/arch/x86/include/asm/cpufeature.h
11463 @@ -205,7 +205,7 @@
11464 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11465 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11466 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11467 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11468 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11469 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11470 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11471 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11472 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11473 ".section .discard,\"aw\",@progbits\n"
11474 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11475 ".previous\n"
11476 - ".section .altinstr_replacement,\"ax\"\n"
11477 + ".section .altinstr_replacement,\"a\"\n"
11478 "3: movb $1,%0\n"
11479 "4:\n"
11480 ".previous\n"
11481 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11482 index 8bf1c06..f723dfd 100644
11483 --- a/arch/x86/include/asm/desc.h
11484 +++ b/arch/x86/include/asm/desc.h
11485 @@ -4,6 +4,7 @@
11486 #include <asm/desc_defs.h>
11487 #include <asm/ldt.h>
11488 #include <asm/mmu.h>
11489 +#include <asm/pgtable.h>
11490
11491 #include <linux/smp.h>
11492 #include <linux/percpu.h>
11493 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11494
11495 desc->type = (info->read_exec_only ^ 1) << 1;
11496 desc->type |= info->contents << 2;
11497 + desc->type |= info->seg_not_present ^ 1;
11498
11499 desc->s = 1;
11500 desc->dpl = 0x3;
11501 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11502 }
11503
11504 extern struct desc_ptr idt_descr;
11505 -extern gate_desc idt_table[];
11506 extern struct desc_ptr nmi_idt_descr;
11507 -extern gate_desc nmi_idt_table[];
11508 -
11509 -struct gdt_page {
11510 - struct desc_struct gdt[GDT_ENTRIES];
11511 -} __attribute__((aligned(PAGE_SIZE)));
11512 -
11513 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11514 +extern gate_desc idt_table[256];
11515 +extern gate_desc nmi_idt_table[256];
11516
11517 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11518 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11519 {
11520 - return per_cpu(gdt_page, cpu).gdt;
11521 + return cpu_gdt_table[cpu];
11522 }
11523
11524 #ifdef CONFIG_X86_64
11525 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11526 unsigned long base, unsigned dpl, unsigned flags,
11527 unsigned short seg)
11528 {
11529 - gate->a = (seg << 16) | (base & 0xffff);
11530 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11531 + gate->gate.offset_low = base;
11532 + gate->gate.seg = seg;
11533 + gate->gate.reserved = 0;
11534 + gate->gate.type = type;
11535 + gate->gate.s = 0;
11536 + gate->gate.dpl = dpl;
11537 + gate->gate.p = 1;
11538 + gate->gate.offset_high = base >> 16;
11539 }
11540
11541 #endif
11542 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11543
11544 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11545 {
11546 + pax_open_kernel();
11547 memcpy(&idt[entry], gate, sizeof(*gate));
11548 + pax_close_kernel();
11549 }
11550
11551 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11552 {
11553 + pax_open_kernel();
11554 memcpy(&ldt[entry], desc, 8);
11555 + pax_close_kernel();
11556 }
11557
11558 static inline void
11559 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11560 default: size = sizeof(*gdt); break;
11561 }
11562
11563 + pax_open_kernel();
11564 memcpy(&gdt[entry], desc, size);
11565 + pax_close_kernel();
11566 }
11567
11568 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11569 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11570
11571 static inline void native_load_tr_desc(void)
11572 {
11573 + pax_open_kernel();
11574 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11575 + pax_close_kernel();
11576 }
11577
11578 static inline void native_load_gdt(const struct desc_ptr *dtr)
11579 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11580 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11581 unsigned int i;
11582
11583 + pax_open_kernel();
11584 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11585 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11586 + pax_close_kernel();
11587 }
11588
11589 #define _LDT_empty(info) \
11590 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11591 }
11592
11593 #ifdef CONFIG_X86_64
11594 -static inline void set_nmi_gate(int gate, void *addr)
11595 +static inline void set_nmi_gate(int gate, const void *addr)
11596 {
11597 gate_desc s;
11598
11599 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11600 }
11601 #endif
11602
11603 -static inline void _set_gate(int gate, unsigned type, void *addr,
11604 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11605 unsigned dpl, unsigned ist, unsigned seg)
11606 {
11607 gate_desc s;
11608 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11609 * Pentium F0 0F bugfix can have resulted in the mapped
11610 * IDT being write-protected.
11611 */
11612 -static inline void set_intr_gate(unsigned int n, void *addr)
11613 +static inline void set_intr_gate(unsigned int n, const void *addr)
11614 {
11615 BUG_ON((unsigned)n > 0xFF);
11616 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11617 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11618 /*
11619 * This routine sets up an interrupt gate at directory privilege level 3.
11620 */
11621 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11622 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11623 {
11624 BUG_ON((unsigned)n > 0xFF);
11625 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11626 }
11627
11628 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11629 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11630 {
11631 BUG_ON((unsigned)n > 0xFF);
11632 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11633 }
11634
11635 -static inline void set_trap_gate(unsigned int n, void *addr)
11636 +static inline void set_trap_gate(unsigned int n, const void *addr)
11637 {
11638 BUG_ON((unsigned)n > 0xFF);
11639 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11640 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11641 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11642 {
11643 BUG_ON((unsigned)n > 0xFF);
11644 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11645 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11646 }
11647
11648 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11649 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11650 {
11651 BUG_ON((unsigned)n > 0xFF);
11652 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11653 }
11654
11655 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11656 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11657 {
11658 BUG_ON((unsigned)n > 0xFF);
11659 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11660 }
11661
11662 +#ifdef CONFIG_X86_32
11663 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11664 +{
11665 + struct desc_struct d;
11666 +
11667 + if (likely(limit))
11668 + limit = (limit - 1UL) >> PAGE_SHIFT;
11669 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11670 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11671 +}
11672 +#endif
11673 +
11674 #endif /* _ASM_X86_DESC_H */
11675 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11676 index 278441f..b95a174 100644
11677 --- a/arch/x86/include/asm/desc_defs.h
11678 +++ b/arch/x86/include/asm/desc_defs.h
11679 @@ -31,6 +31,12 @@ struct desc_struct {
11680 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11681 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11682 };
11683 + struct {
11684 + u16 offset_low;
11685 + u16 seg;
11686 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11687 + unsigned offset_high: 16;
11688 + } gate;
11689 };
11690 } __attribute__((packed));
11691
11692 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11693 index 3778256..c5d4fce 100644
11694 --- a/arch/x86/include/asm/e820.h
11695 +++ b/arch/x86/include/asm/e820.h
11696 @@ -69,7 +69,7 @@ struct e820map {
11697 #define ISA_START_ADDRESS 0xa0000
11698 #define ISA_END_ADDRESS 0x100000
11699
11700 -#define BIOS_BEGIN 0x000a0000
11701 +#define BIOS_BEGIN 0x000c0000
11702 #define BIOS_END 0x00100000
11703
11704 #define BIOS_ROM_BASE 0xffe00000
11705 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11706 index 5939f44..f8845f6 100644
11707 --- a/arch/x86/include/asm/elf.h
11708 +++ b/arch/x86/include/asm/elf.h
11709 @@ -243,7 +243,25 @@ extern int force_personality32;
11710 the loader. We need to make sure that it is out of the way of the program
11711 that it will "exec", and that there is sufficient room for the brk. */
11712
11713 +#ifdef CONFIG_PAX_SEGMEXEC
11714 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11715 +#else
11716 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11717 +#endif
11718 +
11719 +#ifdef CONFIG_PAX_ASLR
11720 +#ifdef CONFIG_X86_32
11721 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11722 +
11723 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11724 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11725 +#else
11726 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11727 +
11728 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11729 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11730 +#endif
11731 +#endif
11732
11733 /* This yields a mask that user programs can use to figure out what
11734 instruction set this CPU supports. This could be done in user space,
11735 @@ -296,16 +314,12 @@ do { \
11736
11737 #define ARCH_DLINFO \
11738 do { \
11739 - if (vdso_enabled) \
11740 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11741 - (unsigned long)current->mm->context.vdso); \
11742 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11743 } while (0)
11744
11745 #define ARCH_DLINFO_X32 \
11746 do { \
11747 - if (vdso_enabled) \
11748 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11749 - (unsigned long)current->mm->context.vdso); \
11750 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11751 } while (0)
11752
11753 #define AT_SYSINFO 32
11754 @@ -320,7 +334,7 @@ else \
11755
11756 #endif /* !CONFIG_X86_32 */
11757
11758 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11759 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11760
11761 #define VDSO_ENTRY \
11762 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11763 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11764 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11765 #define compat_arch_setup_additional_pages syscall32_setup_pages
11766
11767 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11768 -#define arch_randomize_brk arch_randomize_brk
11769 -
11770 /*
11771 * True on X86_32 or when emulating IA32 on X86_64
11772 */
11773 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11774 index 75ce3f4..882e801 100644
11775 --- a/arch/x86/include/asm/emergency-restart.h
11776 +++ b/arch/x86/include/asm/emergency-restart.h
11777 @@ -13,6 +13,6 @@ enum reboot_type {
11778
11779 extern enum reboot_type reboot_type;
11780
11781 -extern void machine_emergency_restart(void);
11782 +extern void machine_emergency_restart(void) __noreturn;
11783
11784 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11785 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11786 index 41ab26e..a88c9e6 100644
11787 --- a/arch/x86/include/asm/fpu-internal.h
11788 +++ b/arch/x86/include/asm/fpu-internal.h
11789 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11790 ({ \
11791 int err; \
11792 asm volatile(ASM_STAC "\n" \
11793 - "1:" #insn "\n\t" \
11794 + "1:" \
11795 + __copyuser_seg \
11796 + #insn "\n\t" \
11797 "2: " ASM_CLAC "\n" \
11798 ".section .fixup,\"ax\"\n" \
11799 "3: movl $-1,%[err]\n" \
11800 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11801 "emms\n\t" /* clear stack tags */
11802 "fildl %P[addr]", /* set F?P to defined value */
11803 X86_FEATURE_FXSAVE_LEAK,
11804 - [addr] "m" (tsk->thread.fpu.has_fpu));
11805 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11806
11807 return fpu_restore_checking(&tsk->thread.fpu);
11808 }
11809 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11810 index f373046..02653e2 100644
11811 --- a/arch/x86/include/asm/futex.h
11812 +++ b/arch/x86/include/asm/futex.h
11813 @@ -12,6 +12,7 @@
11814 #include <asm/smap.h>
11815
11816 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11817 + typecheck(u32 __user *, uaddr); \
11818 asm volatile("\t" ASM_STAC "\n" \
11819 "1:\t" insn "\n" \
11820 "2:\t" ASM_CLAC "\n" \
11821 @@ -20,15 +21,16 @@
11822 "\tjmp\t2b\n" \
11823 "\t.previous\n" \
11824 _ASM_EXTABLE(1b, 3b) \
11825 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11826 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11827 : "i" (-EFAULT), "0" (oparg), "1" (0))
11828
11829 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11830 + typecheck(u32 __user *, uaddr); \
11831 asm volatile("\t" ASM_STAC "\n" \
11832 "1:\tmovl %2, %0\n" \
11833 "\tmovl\t%0, %3\n" \
11834 "\t" insn "\n" \
11835 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11836 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11837 "\tjnz\t1b\n" \
11838 "3:\t" ASM_CLAC "\n" \
11839 "\t.section .fixup,\"ax\"\n" \
11840 @@ -38,7 +40,7 @@
11841 _ASM_EXTABLE(1b, 4b) \
11842 _ASM_EXTABLE(2b, 4b) \
11843 : "=&a" (oldval), "=&r" (ret), \
11844 - "+m" (*uaddr), "=&r" (tem) \
11845 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11846 : "r" (oparg), "i" (-EFAULT), "1" (0))
11847
11848 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11849 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11850
11851 switch (op) {
11852 case FUTEX_OP_SET:
11853 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11854 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11855 break;
11856 case FUTEX_OP_ADD:
11857 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11858 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11859 uaddr, oparg);
11860 break;
11861 case FUTEX_OP_OR:
11862 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11863 return -EFAULT;
11864
11865 asm volatile("\t" ASM_STAC "\n"
11866 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11867 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11868 "2:\t" ASM_CLAC "\n"
11869 "\t.section .fixup, \"ax\"\n"
11870 "3:\tmov %3, %0\n"
11871 "\tjmp 2b\n"
11872 "\t.previous\n"
11873 _ASM_EXTABLE(1b, 3b)
11874 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11875 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11876 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11877 : "memory"
11878 );
11879 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11880 index eb92a6e..b98b2f4 100644
11881 --- a/arch/x86/include/asm/hw_irq.h
11882 +++ b/arch/x86/include/asm/hw_irq.h
11883 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11884 extern void enable_IO_APIC(void);
11885
11886 /* Statistics */
11887 -extern atomic_t irq_err_count;
11888 -extern atomic_t irq_mis_count;
11889 +extern atomic_unchecked_t irq_err_count;
11890 +extern atomic_unchecked_t irq_mis_count;
11891
11892 /* EISA */
11893 extern void eisa_set_level_irq(unsigned int irq);
11894 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11895 index d8e8eef..15b1179 100644
11896 --- a/arch/x86/include/asm/io.h
11897 +++ b/arch/x86/include/asm/io.h
11898 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11899 return ioremap_nocache(offset, size);
11900 }
11901
11902 -extern void iounmap(volatile void __iomem *addr);
11903 +extern void iounmap(const volatile void __iomem *addr);
11904
11905 extern void set_iounmap_nonlazy(void);
11906
11907 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11908
11909 #include <linux/vmalloc.h>
11910
11911 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11912 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11913 +{
11914 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11915 +}
11916 +
11917 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11918 +{
11919 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11920 +}
11921 +
11922 /*
11923 * Convert a virtual cached pointer to an uncached pointer
11924 */
11925 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11926 index bba3cf8..06bc8da 100644
11927 --- a/arch/x86/include/asm/irqflags.h
11928 +++ b/arch/x86/include/asm/irqflags.h
11929 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11930 sti; \
11931 sysexit
11932
11933 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11934 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11935 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11936 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11937 +
11938 #else
11939 #define INTERRUPT_RETURN iret
11940 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11941 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11942 index d3ddd17..c9fb0cc 100644
11943 --- a/arch/x86/include/asm/kprobes.h
11944 +++ b/arch/x86/include/asm/kprobes.h
11945 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11946 #define RELATIVEJUMP_SIZE 5
11947 #define RELATIVECALL_OPCODE 0xe8
11948 #define RELATIVE_ADDR_SIZE 4
11949 -#define MAX_STACK_SIZE 64
11950 -#define MIN_STACK_SIZE(ADDR) \
11951 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11952 - THREAD_SIZE - (unsigned long)(ADDR))) \
11953 - ? (MAX_STACK_SIZE) \
11954 - : (((unsigned long)current_thread_info()) + \
11955 - THREAD_SIZE - (unsigned long)(ADDR)))
11956 +#define MAX_STACK_SIZE 64UL
11957 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11958
11959 #define flush_insn_slot(p) do { } while (0)
11960
11961 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11962 index c8bed0d..85c03fd 100644
11963 --- a/arch/x86/include/asm/local.h
11964 +++ b/arch/x86/include/asm/local.h
11965 @@ -10,33 +10,97 @@ typedef struct {
11966 atomic_long_t a;
11967 } local_t;
11968
11969 +typedef struct {
11970 + atomic_long_unchecked_t a;
11971 +} local_unchecked_t;
11972 +
11973 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11974
11975 #define local_read(l) atomic_long_read(&(l)->a)
11976 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11977 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11978 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11979
11980 static inline void local_inc(local_t *l)
11981 {
11982 - asm volatile(_ASM_INC "%0"
11983 + asm volatile(_ASM_INC "%0\n"
11984 +
11985 +#ifdef CONFIG_PAX_REFCOUNT
11986 + "jno 0f\n"
11987 + _ASM_DEC "%0\n"
11988 + "int $4\n0:\n"
11989 + _ASM_EXTABLE(0b, 0b)
11990 +#endif
11991 +
11992 + : "+m" (l->a.counter));
11993 +}
11994 +
11995 +static inline void local_inc_unchecked(local_unchecked_t *l)
11996 +{
11997 + asm volatile(_ASM_INC "%0\n"
11998 : "+m" (l->a.counter));
11999 }
12000
12001 static inline void local_dec(local_t *l)
12002 {
12003 - asm volatile(_ASM_DEC "%0"
12004 + asm volatile(_ASM_DEC "%0\n"
12005 +
12006 +#ifdef CONFIG_PAX_REFCOUNT
12007 + "jno 0f\n"
12008 + _ASM_INC "%0\n"
12009 + "int $4\n0:\n"
12010 + _ASM_EXTABLE(0b, 0b)
12011 +#endif
12012 +
12013 + : "+m" (l->a.counter));
12014 +}
12015 +
12016 +static inline void local_dec_unchecked(local_unchecked_t *l)
12017 +{
12018 + asm volatile(_ASM_DEC "%0\n"
12019 : "+m" (l->a.counter));
12020 }
12021
12022 static inline void local_add(long i, local_t *l)
12023 {
12024 - asm volatile(_ASM_ADD "%1,%0"
12025 + asm volatile(_ASM_ADD "%1,%0\n"
12026 +
12027 +#ifdef CONFIG_PAX_REFCOUNT
12028 + "jno 0f\n"
12029 + _ASM_SUB "%1,%0\n"
12030 + "int $4\n0:\n"
12031 + _ASM_EXTABLE(0b, 0b)
12032 +#endif
12033 +
12034 + : "+m" (l->a.counter)
12035 + : "ir" (i));
12036 +}
12037 +
12038 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
12039 +{
12040 + asm volatile(_ASM_ADD "%1,%0\n"
12041 : "+m" (l->a.counter)
12042 : "ir" (i));
12043 }
12044
12045 static inline void local_sub(long i, local_t *l)
12046 {
12047 - asm volatile(_ASM_SUB "%1,%0"
12048 + asm volatile(_ASM_SUB "%1,%0\n"
12049 +
12050 +#ifdef CONFIG_PAX_REFCOUNT
12051 + "jno 0f\n"
12052 + _ASM_ADD "%1,%0\n"
12053 + "int $4\n0:\n"
12054 + _ASM_EXTABLE(0b, 0b)
12055 +#endif
12056 +
12057 + : "+m" (l->a.counter)
12058 + : "ir" (i));
12059 +}
12060 +
12061 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12062 +{
12063 + asm volatile(_ASM_SUB "%1,%0\n"
12064 : "+m" (l->a.counter)
12065 : "ir" (i));
12066 }
12067 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12068 {
12069 unsigned char c;
12070
12071 - asm volatile(_ASM_SUB "%2,%0; sete %1"
12072 + asm volatile(_ASM_SUB "%2,%0\n"
12073 +
12074 +#ifdef CONFIG_PAX_REFCOUNT
12075 + "jno 0f\n"
12076 + _ASM_ADD "%2,%0\n"
12077 + "int $4\n0:\n"
12078 + _ASM_EXTABLE(0b, 0b)
12079 +#endif
12080 +
12081 + "sete %1\n"
12082 : "+m" (l->a.counter), "=qm" (c)
12083 : "ir" (i) : "memory");
12084 return c;
12085 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12086 {
12087 unsigned char c;
12088
12089 - asm volatile(_ASM_DEC "%0; sete %1"
12090 + asm volatile(_ASM_DEC "%0\n"
12091 +
12092 +#ifdef CONFIG_PAX_REFCOUNT
12093 + "jno 0f\n"
12094 + _ASM_INC "%0\n"
12095 + "int $4\n0:\n"
12096 + _ASM_EXTABLE(0b, 0b)
12097 +#endif
12098 +
12099 + "sete %1\n"
12100 : "+m" (l->a.counter), "=qm" (c)
12101 : : "memory");
12102 return c != 0;
12103 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12104 {
12105 unsigned char c;
12106
12107 - asm volatile(_ASM_INC "%0; sete %1"
12108 + asm volatile(_ASM_INC "%0\n"
12109 +
12110 +#ifdef CONFIG_PAX_REFCOUNT
12111 + "jno 0f\n"
12112 + _ASM_DEC "%0\n"
12113 + "int $4\n0:\n"
12114 + _ASM_EXTABLE(0b, 0b)
12115 +#endif
12116 +
12117 + "sete %1\n"
12118 : "+m" (l->a.counter), "=qm" (c)
12119 : : "memory");
12120 return c != 0;
12121 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12122 {
12123 unsigned char c;
12124
12125 - asm volatile(_ASM_ADD "%2,%0; sets %1"
12126 + asm volatile(_ASM_ADD "%2,%0\n"
12127 +
12128 +#ifdef CONFIG_PAX_REFCOUNT
12129 + "jno 0f\n"
12130 + _ASM_SUB "%2,%0\n"
12131 + "int $4\n0:\n"
12132 + _ASM_EXTABLE(0b, 0b)
12133 +#endif
12134 +
12135 + "sets %1\n"
12136 : "+m" (l->a.counter), "=qm" (c)
12137 : "ir" (i) : "memory");
12138 return c;
12139 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12140 #endif
12141 /* Modern 486+ processor */
12142 __i = i;
12143 - asm volatile(_ASM_XADD "%0, %1;"
12144 + asm volatile(_ASM_XADD "%0, %1\n"
12145 +
12146 +#ifdef CONFIG_PAX_REFCOUNT
12147 + "jno 0f\n"
12148 + _ASM_MOV "%0,%1\n"
12149 + "int $4\n0:\n"
12150 + _ASM_EXTABLE(0b, 0b)
12151 +#endif
12152 +
12153 : "+r" (i), "+m" (l->a.counter)
12154 : : "memory");
12155 return i + __i;
12156 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12157 #endif
12158 }
12159
12160 +/**
12161 + * local_add_return_unchecked - add and return
12162 + * @i: integer value to add
12163 + * @l: pointer to type local_unchecked_t
12164 + *
12165 + * Atomically adds @i to @l and returns @i + @l
12166 + */
12167 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12168 +{
12169 + long __i;
12170 +#ifdef CONFIG_M386
12171 + unsigned long flags;
12172 + if (unlikely(boot_cpu_data.x86 <= 3))
12173 + goto no_xadd;
12174 +#endif
12175 + /* Modern 486+ processor */
12176 + __i = i;
12177 + asm volatile(_ASM_XADD "%0, %1\n"
12178 + : "+r" (i), "+m" (l->a.counter)
12179 + : : "memory");
12180 + return i + __i;
12181 +
12182 +#ifdef CONFIG_M386
12183 +no_xadd: /* Legacy 386 processor */
12184 + local_irq_save(flags);
12185 + __i = local_read_unchecked(l);
12186 + local_set_unchecked(l, i + __i);
12187 + local_irq_restore(flags);
12188 + return i + __i;
12189 +#endif
12190 +}
12191 +
12192 static inline long local_sub_return(long i, local_t *l)
12193 {
12194 return local_add_return(-i, l);
12195 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12196
12197 #define local_cmpxchg(l, o, n) \
12198 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12199 +#define local_cmpxchg_unchecked(l, o, n) \
12200 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
12201 /* Always has a lock prefix */
12202 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12203
12204 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12205 index 593e51d..fa69c9a 100644
12206 --- a/arch/x86/include/asm/mman.h
12207 +++ b/arch/x86/include/asm/mman.h
12208 @@ -5,4 +5,14 @@
12209
12210 #include <asm-generic/mman.h>
12211
12212 +#ifdef __KERNEL__
12213 +#ifndef __ASSEMBLY__
12214 +#ifdef CONFIG_X86_32
12215 +#define arch_mmap_check i386_mmap_check
12216 +int i386_mmap_check(unsigned long addr, unsigned long len,
12217 + unsigned long flags);
12218 +#endif
12219 +#endif
12220 +#endif
12221 +
12222 #endif /* _ASM_X86_MMAN_H */
12223 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12224 index 5f55e69..e20bfb1 100644
12225 --- a/arch/x86/include/asm/mmu.h
12226 +++ b/arch/x86/include/asm/mmu.h
12227 @@ -9,7 +9,7 @@
12228 * we put the segment information here.
12229 */
12230 typedef struct {
12231 - void *ldt;
12232 + struct desc_struct *ldt;
12233 int size;
12234
12235 #ifdef CONFIG_X86_64
12236 @@ -18,7 +18,19 @@ typedef struct {
12237 #endif
12238
12239 struct mutex lock;
12240 - void *vdso;
12241 + unsigned long vdso;
12242 +
12243 +#ifdef CONFIG_X86_32
12244 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12245 + unsigned long user_cs_base;
12246 + unsigned long user_cs_limit;
12247 +
12248 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12249 + cpumask_t cpu_user_cs_mask;
12250 +#endif
12251 +
12252 +#endif
12253 +#endif
12254 } mm_context_t;
12255
12256 #ifdef CONFIG_SMP
12257 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12258 index cdbf367..adb37ac 100644
12259 --- a/arch/x86/include/asm/mmu_context.h
12260 +++ b/arch/x86/include/asm/mmu_context.h
12261 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12262
12263 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12264 {
12265 +
12266 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12267 + unsigned int i;
12268 + pgd_t *pgd;
12269 +
12270 + pax_open_kernel();
12271 + pgd = get_cpu_pgd(smp_processor_id());
12272 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12273 + set_pgd_batched(pgd+i, native_make_pgd(0));
12274 + pax_close_kernel();
12275 +#endif
12276 +
12277 #ifdef CONFIG_SMP
12278 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12279 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12280 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12281 struct task_struct *tsk)
12282 {
12283 unsigned cpu = smp_processor_id();
12284 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12285 + int tlbstate = TLBSTATE_OK;
12286 +#endif
12287
12288 if (likely(prev != next)) {
12289 #ifdef CONFIG_SMP
12290 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12291 + tlbstate = this_cpu_read(cpu_tlbstate.state);
12292 +#endif
12293 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12294 this_cpu_write(cpu_tlbstate.active_mm, next);
12295 #endif
12296 cpumask_set_cpu(cpu, mm_cpumask(next));
12297
12298 /* Re-load page tables */
12299 +#ifdef CONFIG_PAX_PER_CPU_PGD
12300 + pax_open_kernel();
12301 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12302 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12303 + pax_close_kernel();
12304 + load_cr3(get_cpu_pgd(cpu));
12305 +#else
12306 load_cr3(next->pgd);
12307 +#endif
12308
12309 /* stop flush ipis for the previous mm */
12310 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12311 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12312 */
12313 if (unlikely(prev->context.ldt != next->context.ldt))
12314 load_LDT_nolock(&next->context);
12315 - }
12316 +
12317 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12318 + if (!(__supported_pte_mask & _PAGE_NX)) {
12319 + smp_mb__before_clear_bit();
12320 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12321 + smp_mb__after_clear_bit();
12322 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12323 + }
12324 +#endif
12325 +
12326 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12327 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12328 + prev->context.user_cs_limit != next->context.user_cs_limit))
12329 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12330 #ifdef CONFIG_SMP
12331 + else if (unlikely(tlbstate != TLBSTATE_OK))
12332 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12333 +#endif
12334 +#endif
12335 +
12336 + }
12337 else {
12338 +
12339 +#ifdef CONFIG_PAX_PER_CPU_PGD
12340 + pax_open_kernel();
12341 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12342 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12343 + pax_close_kernel();
12344 + load_cr3(get_cpu_pgd(cpu));
12345 +#endif
12346 +
12347 +#ifdef CONFIG_SMP
12348 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12349 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12350
12351 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12352 * tlb flush IPI delivery. We must reload CR3
12353 * to make sure to use no freed page tables.
12354 */
12355 +
12356 +#ifndef CONFIG_PAX_PER_CPU_PGD
12357 load_cr3(next->pgd);
12358 +#endif
12359 +
12360 load_LDT_nolock(&next->context);
12361 +
12362 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12363 + if (!(__supported_pte_mask & _PAGE_NX))
12364 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12365 +#endif
12366 +
12367 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12368 +#ifdef CONFIG_PAX_PAGEEXEC
12369 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12370 +#endif
12371 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12372 +#endif
12373 +
12374 }
12375 +#endif
12376 }
12377 -#endif
12378 }
12379
12380 #define activate_mm(prev, next) \
12381 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12382 index 9eae775..c914fea 100644
12383 --- a/arch/x86/include/asm/module.h
12384 +++ b/arch/x86/include/asm/module.h
12385 @@ -5,6 +5,7 @@
12386
12387 #ifdef CONFIG_X86_64
12388 /* X86_64 does not define MODULE_PROC_FAMILY */
12389 +#define MODULE_PROC_FAMILY ""
12390 #elif defined CONFIG_M386
12391 #define MODULE_PROC_FAMILY "386 "
12392 #elif defined CONFIG_M486
12393 @@ -59,8 +60,20 @@
12394 #error unknown processor family
12395 #endif
12396
12397 -#ifdef CONFIG_X86_32
12398 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12399 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12400 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12401 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12402 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12403 +#else
12404 +#define MODULE_PAX_KERNEXEC ""
12405 #endif
12406
12407 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12408 +#define MODULE_PAX_UDEREF "UDEREF "
12409 +#else
12410 +#define MODULE_PAX_UDEREF ""
12411 +#endif
12412 +
12413 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12414 +
12415 #endif /* _ASM_X86_MODULE_H */
12416 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12417 index 320f7bb..e89f8f8 100644
12418 --- a/arch/x86/include/asm/page_64_types.h
12419 +++ b/arch/x86/include/asm/page_64_types.h
12420 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12421
12422 /* duplicated to the one in bootmem.h */
12423 extern unsigned long max_pfn;
12424 -extern unsigned long phys_base;
12425 +extern const unsigned long phys_base;
12426
12427 extern unsigned long __phys_addr(unsigned long);
12428 #define __phys_reloc_hide(x) (x)
12429 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12430 index a0facf3..c017b15 100644
12431 --- a/arch/x86/include/asm/paravirt.h
12432 +++ b/arch/x86/include/asm/paravirt.h
12433 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12434 val);
12435 }
12436
12437 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12438 +{
12439 + pgdval_t val = native_pgd_val(pgd);
12440 +
12441 + if (sizeof(pgdval_t) > sizeof(long))
12442 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12443 + val, (u64)val >> 32);
12444 + else
12445 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12446 + val);
12447 +}
12448 +
12449 static inline void pgd_clear(pgd_t *pgdp)
12450 {
12451 set_pgd(pgdp, __pgd(0));
12452 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12453 pv_mmu_ops.set_fixmap(idx, phys, flags);
12454 }
12455
12456 +#ifdef CONFIG_PAX_KERNEXEC
12457 +static inline unsigned long pax_open_kernel(void)
12458 +{
12459 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12460 +}
12461 +
12462 +static inline unsigned long pax_close_kernel(void)
12463 +{
12464 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12465 +}
12466 +#else
12467 +static inline unsigned long pax_open_kernel(void) { return 0; }
12468 +static inline unsigned long pax_close_kernel(void) { return 0; }
12469 +#endif
12470 +
12471 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12472
12473 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12474 @@ -929,7 +956,7 @@ extern void default_banner(void);
12475
12476 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12477 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12478 -#define PARA_INDIRECT(addr) *%cs:addr
12479 +#define PARA_INDIRECT(addr) *%ss:addr
12480 #endif
12481
12482 #define INTERRUPT_RETURN \
12483 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12484 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12485 CLBR_NONE, \
12486 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12487 +
12488 +#define GET_CR0_INTO_RDI \
12489 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12490 + mov %rax,%rdi
12491 +
12492 +#define SET_RDI_INTO_CR0 \
12493 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12494 +
12495 +#define GET_CR3_INTO_RDI \
12496 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12497 + mov %rax,%rdi
12498 +
12499 +#define SET_RDI_INTO_CR3 \
12500 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12501 +
12502 #endif /* CONFIG_X86_32 */
12503
12504 #endif /* __ASSEMBLY__ */
12505 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12506 index 142236e..5446ffbc 100644
12507 --- a/arch/x86/include/asm/paravirt_types.h
12508 +++ b/arch/x86/include/asm/paravirt_types.h
12509 @@ -84,7 +84,7 @@ struct pv_init_ops {
12510 */
12511 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
12512 unsigned long addr, unsigned len);
12513 -};
12514 +} __no_const;
12515
12516
12517 struct pv_lazy_ops {
12518 @@ -97,7 +97,7 @@ struct pv_time_ops {
12519 unsigned long long (*sched_clock)(void);
12520 unsigned long long (*steal_clock)(int cpu);
12521 unsigned long (*get_tsc_khz)(void);
12522 -};
12523 +} __no_const;
12524
12525 struct pv_cpu_ops {
12526 /* hooks for various privileged instructions */
12527 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
12528
12529 void (*start_context_switch)(struct task_struct *prev);
12530 void (*end_context_switch)(struct task_struct *next);
12531 -};
12532 +} __no_const;
12533
12534 struct pv_irq_ops {
12535 /*
12536 @@ -222,7 +222,7 @@ struct pv_apic_ops {
12537 unsigned long start_eip,
12538 unsigned long start_esp);
12539 #endif
12540 -};
12541 +} __no_const;
12542
12543 struct pv_mmu_ops {
12544 unsigned long (*read_cr2)(void);
12545 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12546 struct paravirt_callee_save make_pud;
12547
12548 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12549 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12550 #endif /* PAGETABLE_LEVELS == 4 */
12551 #endif /* PAGETABLE_LEVELS >= 3 */
12552
12553 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12554 an mfn. We can tell which is which from the index. */
12555 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12556 phys_addr_t phys, pgprot_t flags);
12557 +
12558 +#ifdef CONFIG_PAX_KERNEXEC
12559 + unsigned long (*pax_open_kernel)(void);
12560 + unsigned long (*pax_close_kernel)(void);
12561 +#endif
12562 +
12563 };
12564
12565 struct arch_spinlock;
12566 @@ -333,7 +340,7 @@ struct pv_lock_ops {
12567 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
12568 int (*spin_trylock)(struct arch_spinlock *lock);
12569 void (*spin_unlock)(struct arch_spinlock *lock);
12570 -};
12571 +} __no_const;
12572
12573 /* This contains all the paravirt structures: we get a convenient
12574 * number for each function using the offset which we use to indicate
12575 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12576 index b4389a4..7024269 100644
12577 --- a/arch/x86/include/asm/pgalloc.h
12578 +++ b/arch/x86/include/asm/pgalloc.h
12579 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12580 pmd_t *pmd, pte_t *pte)
12581 {
12582 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12583 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12584 +}
12585 +
12586 +static inline void pmd_populate_user(struct mm_struct *mm,
12587 + pmd_t *pmd, pte_t *pte)
12588 +{
12589 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12590 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12591 }
12592
12593 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12594
12595 #ifdef CONFIG_X86_PAE
12596 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12597 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12598 +{
12599 + pud_populate(mm, pudp, pmd);
12600 +}
12601 #else /* !CONFIG_X86_PAE */
12602 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12603 {
12604 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12605 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12606 }
12607 +
12608 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12609 +{
12610 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12611 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12612 +}
12613 #endif /* CONFIG_X86_PAE */
12614
12615 #if PAGETABLE_LEVELS > 3
12616 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12617 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12618 }
12619
12620 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12621 +{
12622 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12623 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12624 +}
12625 +
12626 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12627 {
12628 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12629 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12630 index f2b489c..4f7e2e5 100644
12631 --- a/arch/x86/include/asm/pgtable-2level.h
12632 +++ b/arch/x86/include/asm/pgtable-2level.h
12633 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12634
12635 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12636 {
12637 + pax_open_kernel();
12638 *pmdp = pmd;
12639 + pax_close_kernel();
12640 }
12641
12642 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12643 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12644 index 4cc9f2b..5fd9226 100644
12645 --- a/arch/x86/include/asm/pgtable-3level.h
12646 +++ b/arch/x86/include/asm/pgtable-3level.h
12647 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12648
12649 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12650 {
12651 + pax_open_kernel();
12652 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12653 + pax_close_kernel();
12654 }
12655
12656 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12657 {
12658 + pax_open_kernel();
12659 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12660 + pax_close_kernel();
12661 }
12662
12663 /*
12664 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12665 index 796ed83..9f6c8dd 100644
12666 --- a/arch/x86/include/asm/pgtable.h
12667 +++ b/arch/x86/include/asm/pgtable.h
12668 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12669
12670 #ifndef __PAGETABLE_PUD_FOLDED
12671 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12672 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12673 #define pgd_clear(pgd) native_pgd_clear(pgd)
12674 #endif
12675
12676 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12677
12678 #define arch_end_context_switch(prev) do {} while(0)
12679
12680 +#define pax_open_kernel() native_pax_open_kernel()
12681 +#define pax_close_kernel() native_pax_close_kernel()
12682 #endif /* CONFIG_PARAVIRT */
12683
12684 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12685 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12686 +
12687 +#ifdef CONFIG_PAX_KERNEXEC
12688 +static inline unsigned long native_pax_open_kernel(void)
12689 +{
12690 + unsigned long cr0;
12691 +
12692 + preempt_disable();
12693 + barrier();
12694 + cr0 = read_cr0() ^ X86_CR0_WP;
12695 + BUG_ON(cr0 & X86_CR0_WP);
12696 + write_cr0(cr0);
12697 + return cr0 ^ X86_CR0_WP;
12698 +}
12699 +
12700 +static inline unsigned long native_pax_close_kernel(void)
12701 +{
12702 + unsigned long cr0;
12703 +
12704 + cr0 = read_cr0() ^ X86_CR0_WP;
12705 + BUG_ON(!(cr0 & X86_CR0_WP));
12706 + write_cr0(cr0);
12707 + barrier();
12708 + preempt_enable_no_resched();
12709 + return cr0 ^ X86_CR0_WP;
12710 +}
12711 +#else
12712 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12713 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12714 +#endif
12715 +
12716 /*
12717 * The following only work if pte_present() is true.
12718 * Undefined behaviour if not..
12719 */
12720 +static inline int pte_user(pte_t pte)
12721 +{
12722 + return pte_val(pte) & _PAGE_USER;
12723 +}
12724 +
12725 static inline int pte_dirty(pte_t pte)
12726 {
12727 return pte_flags(pte) & _PAGE_DIRTY;
12728 @@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12729 return pte_clear_flags(pte, _PAGE_RW);
12730 }
12731
12732 +static inline pte_t pte_mkread(pte_t pte)
12733 +{
12734 + return __pte(pte_val(pte) | _PAGE_USER);
12735 +}
12736 +
12737 static inline pte_t pte_mkexec(pte_t pte)
12738 {
12739 - return pte_clear_flags(pte, _PAGE_NX);
12740 +#ifdef CONFIG_X86_PAE
12741 + if (__supported_pte_mask & _PAGE_NX)
12742 + return pte_clear_flags(pte, _PAGE_NX);
12743 + else
12744 +#endif
12745 + return pte_set_flags(pte, _PAGE_USER);
12746 +}
12747 +
12748 +static inline pte_t pte_exprotect(pte_t pte)
12749 +{
12750 +#ifdef CONFIG_X86_PAE
12751 + if (__supported_pte_mask & _PAGE_NX)
12752 + return pte_set_flags(pte, _PAGE_NX);
12753 + else
12754 +#endif
12755 + return pte_clear_flags(pte, _PAGE_USER);
12756 }
12757
12758 static inline pte_t pte_mkdirty(pte_t pte)
12759 @@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12760 #endif
12761
12762 #ifndef __ASSEMBLY__
12763 +
12764 +#ifdef CONFIG_PAX_PER_CPU_PGD
12765 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12766 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12767 +{
12768 + return cpu_pgd[cpu];
12769 +}
12770 +#endif
12771 +
12772 #include <linux/mm_types.h>
12773
12774 static inline int pte_none(pte_t pte)
12775 @@ -570,7 +639,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12776
12777 static inline int pgd_bad(pgd_t pgd)
12778 {
12779 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12780 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12781 }
12782
12783 static inline int pgd_none(pgd_t pgd)
12784 @@ -593,7 +662,12 @@ static inline int pgd_none(pgd_t pgd)
12785 * pgd_offset() returns a (pgd_t *)
12786 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12787 */
12788 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12789 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12790 +
12791 +#ifdef CONFIG_PAX_PER_CPU_PGD
12792 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12793 +#endif
12794 +
12795 /*
12796 * a shortcut which implies the use of the kernel's pgd, instead
12797 * of a process's
12798 @@ -604,6 +678,20 @@ static inline int pgd_none(pgd_t pgd)
12799 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12800 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12801
12802 +#ifdef CONFIG_X86_32
12803 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12804 +#else
12805 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12806 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12807 +
12808 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12809 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12810 +#else
12811 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12812 +#endif
12813 +
12814 +#endif
12815 +
12816 #ifndef __ASSEMBLY__
12817
12818 extern int direct_gbpages;
12819 @@ -768,11 +856,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12820 * dst and src can be on the same page, but the range must not overlap,
12821 * and must not cross a page boundary.
12822 */
12823 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12824 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12825 {
12826 - memcpy(dst, src, count * sizeof(pgd_t));
12827 + pax_open_kernel();
12828 + while (count--)
12829 + *dst++ = *src++;
12830 + pax_close_kernel();
12831 }
12832
12833 +#ifdef CONFIG_PAX_PER_CPU_PGD
12834 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12835 +#endif
12836 +
12837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12838 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12839 +#else
12840 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12841 +#endif
12842
12843 #include <asm-generic/pgtable.h>
12844 #endif /* __ASSEMBLY__ */
12845 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12846 index 8faa215..a8a17ea 100644
12847 --- a/arch/x86/include/asm/pgtable_32.h
12848 +++ b/arch/x86/include/asm/pgtable_32.h
12849 @@ -25,9 +25,6 @@
12850 struct mm_struct;
12851 struct vm_area_struct;
12852
12853 -extern pgd_t swapper_pg_dir[1024];
12854 -extern pgd_t initial_page_table[1024];
12855 -
12856 static inline void pgtable_cache_init(void) { }
12857 static inline void check_pgt_cache(void) { }
12858 void paging_init(void);
12859 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12860 # include <asm/pgtable-2level.h>
12861 #endif
12862
12863 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12864 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12865 +#ifdef CONFIG_X86_PAE
12866 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12867 +#endif
12868 +
12869 #if defined(CONFIG_HIGHPTE)
12870 #define pte_offset_map(dir, address) \
12871 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12872 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12873 /* Clear a kernel PTE and flush it from the TLB */
12874 #define kpte_clear_flush(ptep, vaddr) \
12875 do { \
12876 + pax_open_kernel(); \
12877 pte_clear(&init_mm, (vaddr), (ptep)); \
12878 + pax_close_kernel(); \
12879 __flush_tlb_one((vaddr)); \
12880 } while (0)
12881
12882 @@ -75,6 +80,9 @@ do { \
12883
12884 #endif /* !__ASSEMBLY__ */
12885
12886 +#define HAVE_ARCH_UNMAPPED_AREA
12887 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12888 +
12889 /*
12890 * kern_addr_valid() is (1) for FLATMEM and (0) for
12891 * SPARSEMEM and DISCONTIGMEM
12892 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12893 index ed5903b..c7fe163 100644
12894 --- a/arch/x86/include/asm/pgtable_32_types.h
12895 +++ b/arch/x86/include/asm/pgtable_32_types.h
12896 @@ -8,7 +8,7 @@
12897 */
12898 #ifdef CONFIG_X86_PAE
12899 # include <asm/pgtable-3level_types.h>
12900 -# define PMD_SIZE (1UL << PMD_SHIFT)
12901 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12902 # define PMD_MASK (~(PMD_SIZE - 1))
12903 #else
12904 # include <asm/pgtable-2level_types.h>
12905 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12906 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12907 #endif
12908
12909 +#ifdef CONFIG_PAX_KERNEXEC
12910 +#ifndef __ASSEMBLY__
12911 +extern unsigned char MODULES_EXEC_VADDR[];
12912 +extern unsigned char MODULES_EXEC_END[];
12913 +#endif
12914 +#include <asm/boot.h>
12915 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12916 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12917 +#else
12918 +#define ktla_ktva(addr) (addr)
12919 +#define ktva_ktla(addr) (addr)
12920 +#endif
12921 +
12922 #define MODULES_VADDR VMALLOC_START
12923 #define MODULES_END VMALLOC_END
12924 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12925 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12926 index 47356f9..deb94a2 100644
12927 --- a/arch/x86/include/asm/pgtable_64.h
12928 +++ b/arch/x86/include/asm/pgtable_64.h
12929 @@ -16,10 +16,14 @@
12930
12931 extern pud_t level3_kernel_pgt[512];
12932 extern pud_t level3_ident_pgt[512];
12933 +extern pud_t level3_vmalloc_start_pgt[512];
12934 +extern pud_t level3_vmalloc_end_pgt[512];
12935 +extern pud_t level3_vmemmap_pgt[512];
12936 +extern pud_t level2_vmemmap_pgt[512];
12937 extern pmd_t level2_kernel_pgt[512];
12938 extern pmd_t level2_fixmap_pgt[512];
12939 -extern pmd_t level2_ident_pgt[512];
12940 -extern pgd_t init_level4_pgt[];
12941 +extern pmd_t level2_ident_pgt[512*2];
12942 +extern pgd_t init_level4_pgt[512];
12943
12944 #define swapper_pg_dir init_level4_pgt
12945
12946 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12947
12948 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12949 {
12950 + pax_open_kernel();
12951 *pmdp = pmd;
12952 + pax_close_kernel();
12953 }
12954
12955 static inline void native_pmd_clear(pmd_t *pmd)
12956 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12957
12958 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12959 {
12960 + pax_open_kernel();
12961 *pudp = pud;
12962 + pax_close_kernel();
12963 }
12964
12965 static inline void native_pud_clear(pud_t *pud)
12966 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12967
12968 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12969 {
12970 + pax_open_kernel();
12971 + *pgdp = pgd;
12972 + pax_close_kernel();
12973 +}
12974 +
12975 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12976 +{
12977 *pgdp = pgd;
12978 }
12979
12980 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12981 index 766ea16..5b96cb3 100644
12982 --- a/arch/x86/include/asm/pgtable_64_types.h
12983 +++ b/arch/x86/include/asm/pgtable_64_types.h
12984 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12985 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12986 #define MODULES_END _AC(0xffffffffff000000, UL)
12987 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12988 +#define MODULES_EXEC_VADDR MODULES_VADDR
12989 +#define MODULES_EXEC_END MODULES_END
12990 +
12991 +#define ktla_ktva(addr) (addr)
12992 +#define ktva_ktla(addr) (addr)
12993
12994 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12995 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12996 index ec8a1fc..7ccb593 100644
12997 --- a/arch/x86/include/asm/pgtable_types.h
12998 +++ b/arch/x86/include/asm/pgtable_types.h
12999 @@ -16,13 +16,12 @@
13000 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
13001 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
13002 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
13003 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
13004 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
13005 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
13006 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
13007 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
13008 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
13009 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
13010 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
13011 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
13012 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
13013 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
13014
13015 /* If _PAGE_BIT_PRESENT is clear, we use these: */
13016 @@ -40,7 +39,6 @@
13017 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
13018 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
13019 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
13020 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
13021 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
13022 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
13023 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
13024 @@ -57,8 +55,10 @@
13025
13026 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
13027 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
13028 -#else
13029 +#elif defined(CONFIG_KMEMCHECK)
13030 #define _PAGE_NX (_AT(pteval_t, 0))
13031 +#else
13032 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
13033 #endif
13034
13035 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
13036 @@ -96,6 +96,9 @@
13037 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
13038 _PAGE_ACCESSED)
13039
13040 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
13041 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
13042 +
13043 #define __PAGE_KERNEL_EXEC \
13044 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
13045 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
13046 @@ -106,7 +109,7 @@
13047 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
13048 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
13049 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
13050 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
13051 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
13052 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
13053 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
13054 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
13055 @@ -168,8 +171,8 @@
13056 * bits are combined, this will alow user to access the high address mapped
13057 * VDSO in the presence of CONFIG_COMPAT_VDSO
13058 */
13059 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
13060 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
13061 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13062 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13063 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
13064 #endif
13065
13066 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
13067 {
13068 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
13069 }
13070 +#endif
13071
13072 +#if PAGETABLE_LEVELS == 3
13073 +#include <asm-generic/pgtable-nopud.h>
13074 +#endif
13075 +
13076 +#if PAGETABLE_LEVELS == 2
13077 +#include <asm-generic/pgtable-nopmd.h>
13078 +#endif
13079 +
13080 +#ifndef __ASSEMBLY__
13081 #if PAGETABLE_LEVELS > 3
13082 typedef struct { pudval_t pud; } pud_t;
13083
13084 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
13085 return pud.pud;
13086 }
13087 #else
13088 -#include <asm-generic/pgtable-nopud.h>
13089 -
13090 static inline pudval_t native_pud_val(pud_t pud)
13091 {
13092 return native_pgd_val(pud.pgd);
13093 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
13094 return pmd.pmd;
13095 }
13096 #else
13097 -#include <asm-generic/pgtable-nopmd.h>
13098 -
13099 static inline pmdval_t native_pmd_val(pmd_t pmd)
13100 {
13101 return native_pgd_val(pmd.pud.pgd);
13102 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13103
13104 extern pteval_t __supported_pte_mask;
13105 extern void set_nx(void);
13106 -extern int nx_enabled;
13107
13108 #define pgprot_writecombine pgprot_writecombine
13109 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13110 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13111 index ad1fc85..0b15fe1 100644
13112 --- a/arch/x86/include/asm/processor.h
13113 +++ b/arch/x86/include/asm/processor.h
13114 @@ -289,7 +289,7 @@ struct tss_struct {
13115
13116 } ____cacheline_aligned;
13117
13118 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13119 +extern struct tss_struct init_tss[NR_CPUS];
13120
13121 /*
13122 * Save the original ist values for checking stack pointers during debugging
13123 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13124 */
13125 #define TASK_SIZE PAGE_OFFSET
13126 #define TASK_SIZE_MAX TASK_SIZE
13127 +
13128 +#ifdef CONFIG_PAX_SEGMEXEC
13129 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13130 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13131 +#else
13132 #define STACK_TOP TASK_SIZE
13133 -#define STACK_TOP_MAX STACK_TOP
13134 +#endif
13135 +
13136 +#define STACK_TOP_MAX TASK_SIZE
13137
13138 #define INIT_THREAD { \
13139 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13140 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13141 .vm86_info = NULL, \
13142 .sysenter_cs = __KERNEL_CS, \
13143 .io_bitmap_ptr = NULL, \
13144 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13145 */
13146 #define INIT_TSS { \
13147 .x86_tss = { \
13148 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13149 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13150 .ss0 = __KERNEL_DS, \
13151 .ss1 = __KERNEL_CS, \
13152 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13153 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13154 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13155
13156 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13157 -#define KSTK_TOP(info) \
13158 -({ \
13159 - unsigned long *__ptr = (unsigned long *)(info); \
13160 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13161 -})
13162 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13163
13164 /*
13165 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13166 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13167 #define task_pt_regs(task) \
13168 ({ \
13169 struct pt_regs *__regs__; \
13170 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13171 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13172 __regs__ - 1; \
13173 })
13174
13175 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13176 /*
13177 * User space process size. 47bits minus one guard page.
13178 */
13179 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13180 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13181
13182 /* This decides where the kernel will search for a free chunk of vm
13183 * space during mmap's.
13184 */
13185 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13186 - 0xc0000000 : 0xFFFFe000)
13187 + 0xc0000000 : 0xFFFFf000)
13188
13189 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13190 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13191 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13192 #define STACK_TOP_MAX TASK_SIZE_MAX
13193
13194 #define INIT_THREAD { \
13195 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13196 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13197 }
13198
13199 #define INIT_TSS { \
13200 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13201 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13202 }
13203
13204 /*
13205 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13206 */
13207 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13208
13209 +#ifdef CONFIG_PAX_SEGMEXEC
13210 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13211 +#endif
13212 +
13213 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13214
13215 /* Get/set a process' ability to use the timestamp counter instruction */
13216 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13217 #define cpu_has_amd_erratum(x) (false)
13218 #endif /* CONFIG_CPU_SUP_AMD */
13219
13220 -extern unsigned long arch_align_stack(unsigned long sp);
13221 +#define arch_align_stack(x) ((x) & ~0xfUL)
13222 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13223
13224 void default_idle(void);
13225 bool set_pm_idle_to_default(void);
13226
13227 -void stop_this_cpu(void *dummy);
13228 +void stop_this_cpu(void *dummy) __noreturn;
13229
13230 #endif /* _ASM_X86_PROCESSOR_H */
13231 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13232 index 19f16eb..b50624b 100644
13233 --- a/arch/x86/include/asm/ptrace.h
13234 +++ b/arch/x86/include/asm/ptrace.h
13235 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13236 }
13237
13238 /*
13239 - * user_mode_vm(regs) determines whether a register set came from user mode.
13240 + * user_mode(regs) determines whether a register set came from user mode.
13241 * This is true if V8086 mode was enabled OR if the register set was from
13242 * protected mode with RPL-3 CS value. This tricky test checks that with
13243 * one comparison. Many places in the kernel can bypass this full check
13244 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13245 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13246 + * be used.
13247 */
13248 -static inline int user_mode(struct pt_regs *regs)
13249 +static inline int user_mode_novm(struct pt_regs *regs)
13250 {
13251 #ifdef CONFIG_X86_32
13252 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13253 #else
13254 - return !!(regs->cs & 3);
13255 + return !!(regs->cs & SEGMENT_RPL_MASK);
13256 #endif
13257 }
13258
13259 -static inline int user_mode_vm(struct pt_regs *regs)
13260 +static inline int user_mode(struct pt_regs *regs)
13261 {
13262 #ifdef CONFIG_X86_32
13263 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13264 USER_RPL;
13265 #else
13266 - return user_mode(regs);
13267 + return user_mode_novm(regs);
13268 #endif
13269 }
13270
13271 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13272 #ifdef CONFIG_X86_64
13273 static inline bool user_64bit_mode(struct pt_regs *regs)
13274 {
13275 + unsigned long cs = regs->cs & 0xffff;
13276 #ifndef CONFIG_PARAVIRT
13277 /*
13278 * On non-paravirt systems, this is the only long mode CPL 3
13279 * selector. We do not allow long mode selectors in the LDT.
13280 */
13281 - return regs->cs == __USER_CS;
13282 + return cs == __USER_CS;
13283 #else
13284 /* Headers are too twisted for this to go in paravirt.h. */
13285 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13286 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13287 #endif
13288 }
13289 #endif
13290 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13291 index fe1ec5b..dc5c3fe 100644
13292 --- a/arch/x86/include/asm/realmode.h
13293 +++ b/arch/x86/include/asm/realmode.h
13294 @@ -22,16 +22,14 @@ struct real_mode_header {
13295 #endif
13296 /* APM/BIOS reboot */
13297 u32 machine_real_restart_asm;
13298 -#ifdef CONFIG_X86_64
13299 u32 machine_real_restart_seg;
13300 -#endif
13301 };
13302
13303 /* This must match data at trampoline_32/64.S */
13304 struct trampoline_header {
13305 #ifdef CONFIG_X86_32
13306 u32 start;
13307 - u16 gdt_pad;
13308 + u16 boot_cs;
13309 u16 gdt_limit;
13310 u32 gdt_base;
13311 #else
13312 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13313 index a82c4f1..ac45053 100644
13314 --- a/arch/x86/include/asm/reboot.h
13315 +++ b/arch/x86/include/asm/reboot.h
13316 @@ -6,13 +6,13 @@
13317 struct pt_regs;
13318
13319 struct machine_ops {
13320 - void (*restart)(char *cmd);
13321 - void (*halt)(void);
13322 - void (*power_off)(void);
13323 + void (* __noreturn restart)(char *cmd);
13324 + void (* __noreturn halt)(void);
13325 + void (* __noreturn power_off)(void);
13326 void (*shutdown)(void);
13327 void (*crash_shutdown)(struct pt_regs *);
13328 - void (*emergency_restart)(void);
13329 -};
13330 + void (* __noreturn emergency_restart)(void);
13331 +} __no_const;
13332
13333 extern struct machine_ops machine_ops;
13334
13335 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13336 index 2dbe4a7..ce1db00 100644
13337 --- a/arch/x86/include/asm/rwsem.h
13338 +++ b/arch/x86/include/asm/rwsem.h
13339 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13340 {
13341 asm volatile("# beginning down_read\n\t"
13342 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13343 +
13344 +#ifdef CONFIG_PAX_REFCOUNT
13345 + "jno 0f\n"
13346 + LOCK_PREFIX _ASM_DEC "(%1)\n"
13347 + "int $4\n0:\n"
13348 + _ASM_EXTABLE(0b, 0b)
13349 +#endif
13350 +
13351 /* adds 0x00000001 */
13352 " jns 1f\n"
13353 " call call_rwsem_down_read_failed\n"
13354 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13355 "1:\n\t"
13356 " mov %1,%2\n\t"
13357 " add %3,%2\n\t"
13358 +
13359 +#ifdef CONFIG_PAX_REFCOUNT
13360 + "jno 0f\n"
13361 + "sub %3,%2\n"
13362 + "int $4\n0:\n"
13363 + _ASM_EXTABLE(0b, 0b)
13364 +#endif
13365 +
13366 " jle 2f\n\t"
13367 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13368 " jnz 1b\n\t"
13369 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13370 long tmp;
13371 asm volatile("# beginning down_write\n\t"
13372 LOCK_PREFIX " xadd %1,(%2)\n\t"
13373 +
13374 +#ifdef CONFIG_PAX_REFCOUNT
13375 + "jno 0f\n"
13376 + "mov %1,(%2)\n"
13377 + "int $4\n0:\n"
13378 + _ASM_EXTABLE(0b, 0b)
13379 +#endif
13380 +
13381 /* adds 0xffff0001, returns the old value */
13382 " test %1,%1\n\t"
13383 /* was the count 0 before? */
13384 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13385 long tmp;
13386 asm volatile("# beginning __up_read\n\t"
13387 LOCK_PREFIX " xadd %1,(%2)\n\t"
13388 +
13389 +#ifdef CONFIG_PAX_REFCOUNT
13390 + "jno 0f\n"
13391 + "mov %1,(%2)\n"
13392 + "int $4\n0:\n"
13393 + _ASM_EXTABLE(0b, 0b)
13394 +#endif
13395 +
13396 /* subtracts 1, returns the old value */
13397 " jns 1f\n\t"
13398 " call call_rwsem_wake\n" /* expects old value in %edx */
13399 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13400 long tmp;
13401 asm volatile("# beginning __up_write\n\t"
13402 LOCK_PREFIX " xadd %1,(%2)\n\t"
13403 +
13404 +#ifdef CONFIG_PAX_REFCOUNT
13405 + "jno 0f\n"
13406 + "mov %1,(%2)\n"
13407 + "int $4\n0:\n"
13408 + _ASM_EXTABLE(0b, 0b)
13409 +#endif
13410 +
13411 /* subtracts 0xffff0001, returns the old value */
13412 " jns 1f\n\t"
13413 " call call_rwsem_wake\n" /* expects old value in %edx */
13414 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13415 {
13416 asm volatile("# beginning __downgrade_write\n\t"
13417 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13418 +
13419 +#ifdef CONFIG_PAX_REFCOUNT
13420 + "jno 0f\n"
13421 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13422 + "int $4\n0:\n"
13423 + _ASM_EXTABLE(0b, 0b)
13424 +#endif
13425 +
13426 /*
13427 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13428 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13429 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13430 */
13431 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13432 {
13433 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13434 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13435 +
13436 +#ifdef CONFIG_PAX_REFCOUNT
13437 + "jno 0f\n"
13438 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13439 + "int $4\n0:\n"
13440 + _ASM_EXTABLE(0b, 0b)
13441 +#endif
13442 +
13443 : "+m" (sem->count)
13444 : "er" (delta));
13445 }
13446 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13447 */
13448 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13449 {
13450 - return delta + xadd(&sem->count, delta);
13451 + return delta + xadd_check_overflow(&sem->count, delta);
13452 }
13453
13454 #endif /* __KERNEL__ */
13455 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13456 index c48a950..c6d7468 100644
13457 --- a/arch/x86/include/asm/segment.h
13458 +++ b/arch/x86/include/asm/segment.h
13459 @@ -64,10 +64,15 @@
13460 * 26 - ESPFIX small SS
13461 * 27 - per-cpu [ offset to per-cpu data area ]
13462 * 28 - stack_canary-20 [ for stack protector ]
13463 - * 29 - unused
13464 - * 30 - unused
13465 + * 29 - PCI BIOS CS
13466 + * 30 - PCI BIOS DS
13467 * 31 - TSS for double fault handler
13468 */
13469 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13470 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13471 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13472 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13473 +
13474 #define GDT_ENTRY_TLS_MIN 6
13475 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13476
13477 @@ -79,6 +84,8 @@
13478
13479 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13480
13481 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13482 +
13483 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13484
13485 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13486 @@ -104,6 +111,12 @@
13487 #define __KERNEL_STACK_CANARY 0
13488 #endif
13489
13490 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13491 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13492 +
13493 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13494 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13495 +
13496 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13497
13498 /*
13499 @@ -141,7 +154,7 @@
13500 */
13501
13502 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13503 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13504 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13505
13506
13507 #else
13508 @@ -165,6 +178,8 @@
13509 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13510 #define __USER32_DS __USER_DS
13511
13512 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13513 +
13514 #define GDT_ENTRY_TSS 8 /* needs two entries */
13515 #define GDT_ENTRY_LDT 10 /* needs two entries */
13516 #define GDT_ENTRY_TLS_MIN 12
13517 @@ -185,6 +200,7 @@
13518 #endif
13519
13520 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13521 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13522 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13523 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13524 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13525 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13526 {
13527 unsigned long __limit;
13528 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13529 - return __limit + 1;
13530 + return __limit;
13531 }
13532
13533 #endif /* !__ASSEMBLY__ */
13534 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13535 index 4f19a15..9e14f27 100644
13536 --- a/arch/x86/include/asm/smp.h
13537 +++ b/arch/x86/include/asm/smp.h
13538 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13539 /* cpus sharing the last level cache: */
13540 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13541 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13542 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13543 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13544
13545 static inline struct cpumask *cpu_sibling_mask(int cpu)
13546 {
13547 @@ -79,7 +79,7 @@ struct smp_ops {
13548
13549 void (*send_call_func_ipi)(const struct cpumask *mask);
13550 void (*send_call_func_single_ipi)(int cpu);
13551 -};
13552 +} __no_const;
13553
13554 /* Globals due to paravirt */
13555 extern void set_cpu_sibling_map(int cpu);
13556 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13557 extern int safe_smp_processor_id(void);
13558
13559 #elif defined(CONFIG_X86_64_SMP)
13560 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13561 -
13562 -#define stack_smp_processor_id() \
13563 -({ \
13564 - struct thread_info *ti; \
13565 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13566 - ti->cpu; \
13567 -})
13568 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13569 +#define stack_smp_processor_id() raw_smp_processor_id()
13570 #define safe_smp_processor_id() smp_processor_id()
13571
13572 #endif
13573 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13574 index 33692ea..350a534 100644
13575 --- a/arch/x86/include/asm/spinlock.h
13576 +++ b/arch/x86/include/asm/spinlock.h
13577 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13578 static inline void arch_read_lock(arch_rwlock_t *rw)
13579 {
13580 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13581 +
13582 +#ifdef CONFIG_PAX_REFCOUNT
13583 + "jno 0f\n"
13584 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13585 + "int $4\n0:\n"
13586 + _ASM_EXTABLE(0b, 0b)
13587 +#endif
13588 +
13589 "jns 1f\n"
13590 "call __read_lock_failed\n\t"
13591 "1:\n"
13592 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13593 static inline void arch_write_lock(arch_rwlock_t *rw)
13594 {
13595 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13596 +
13597 +#ifdef CONFIG_PAX_REFCOUNT
13598 + "jno 0f\n"
13599 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13600 + "int $4\n0:\n"
13601 + _ASM_EXTABLE(0b, 0b)
13602 +#endif
13603 +
13604 "jz 1f\n"
13605 "call __write_lock_failed\n\t"
13606 "1:\n"
13607 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13608
13609 static inline void arch_read_unlock(arch_rwlock_t *rw)
13610 {
13611 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13612 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13613 +
13614 +#ifdef CONFIG_PAX_REFCOUNT
13615 + "jno 0f\n"
13616 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13617 + "int $4\n0:\n"
13618 + _ASM_EXTABLE(0b, 0b)
13619 +#endif
13620 +
13621 :"+m" (rw->lock) : : "memory");
13622 }
13623
13624 static inline void arch_write_unlock(arch_rwlock_t *rw)
13625 {
13626 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13627 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13628 +
13629 +#ifdef CONFIG_PAX_REFCOUNT
13630 + "jno 0f\n"
13631 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13632 + "int $4\n0:\n"
13633 + _ASM_EXTABLE(0b, 0b)
13634 +#endif
13635 +
13636 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13637 }
13638
13639 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13640 index 6a99859..03cb807 100644
13641 --- a/arch/x86/include/asm/stackprotector.h
13642 +++ b/arch/x86/include/asm/stackprotector.h
13643 @@ -47,7 +47,7 @@
13644 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13645 */
13646 #define GDT_STACK_CANARY_INIT \
13647 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13648 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13649
13650 /*
13651 * Initialize the stackprotector canary value.
13652 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13653
13654 static inline void load_stack_canary_segment(void)
13655 {
13656 -#ifdef CONFIG_X86_32
13657 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13658 asm volatile ("mov %0, %%gs" : : "r" (0));
13659 #endif
13660 }
13661 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13662 index 70bbe39..4ae2bd4 100644
13663 --- a/arch/x86/include/asm/stacktrace.h
13664 +++ b/arch/x86/include/asm/stacktrace.h
13665 @@ -11,28 +11,20 @@
13666
13667 extern int kstack_depth_to_print;
13668
13669 -struct thread_info;
13670 +struct task_struct;
13671 struct stacktrace_ops;
13672
13673 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13674 - unsigned long *stack,
13675 - unsigned long bp,
13676 - const struct stacktrace_ops *ops,
13677 - void *data,
13678 - unsigned long *end,
13679 - int *graph);
13680 +typedef unsigned long walk_stack_t(struct task_struct *task,
13681 + void *stack_start,
13682 + unsigned long *stack,
13683 + unsigned long bp,
13684 + const struct stacktrace_ops *ops,
13685 + void *data,
13686 + unsigned long *end,
13687 + int *graph);
13688
13689 -extern unsigned long
13690 -print_context_stack(struct thread_info *tinfo,
13691 - unsigned long *stack, unsigned long bp,
13692 - const struct stacktrace_ops *ops, void *data,
13693 - unsigned long *end, int *graph);
13694 -
13695 -extern unsigned long
13696 -print_context_stack_bp(struct thread_info *tinfo,
13697 - unsigned long *stack, unsigned long bp,
13698 - const struct stacktrace_ops *ops, void *data,
13699 - unsigned long *end, int *graph);
13700 +extern walk_stack_t print_context_stack;
13701 +extern walk_stack_t print_context_stack_bp;
13702
13703 /* Generic stack tracer with callbacks */
13704
13705 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13706 void (*address)(void *data, unsigned long address, int reliable);
13707 /* On negative return stop dumping */
13708 int (*stack)(void *data, char *name);
13709 - walk_stack_t walk_stack;
13710 + walk_stack_t *walk_stack;
13711 };
13712
13713 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13714 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13715 index 4ec45b3..a4f0a8a 100644
13716 --- a/arch/x86/include/asm/switch_to.h
13717 +++ b/arch/x86/include/asm/switch_to.h
13718 @@ -108,7 +108,7 @@ do { \
13719 "call __switch_to\n\t" \
13720 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13721 __switch_canary \
13722 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13723 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13724 "movq %%rax,%%rdi\n\t" \
13725 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13726 "jnz ret_from_fork\n\t" \
13727 @@ -119,7 +119,7 @@ do { \
13728 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13729 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13730 [_tif_fork] "i" (_TIF_FORK), \
13731 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13732 + [thread_info] "m" (current_tinfo), \
13733 [current_task] "m" (current_task) \
13734 __switch_canary_iparam \
13735 : "memory", "cc" __EXTRA_CLOBBER)
13736 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13737 index 2d946e6..e453ec4 100644
13738 --- a/arch/x86/include/asm/thread_info.h
13739 +++ b/arch/x86/include/asm/thread_info.h
13740 @@ -10,6 +10,7 @@
13741 #include <linux/compiler.h>
13742 #include <asm/page.h>
13743 #include <asm/types.h>
13744 +#include <asm/percpu.h>
13745
13746 /*
13747 * low level task data that entry.S needs immediate access to
13748 @@ -24,7 +25,6 @@ struct exec_domain;
13749 #include <linux/atomic.h>
13750
13751 struct thread_info {
13752 - struct task_struct *task; /* main task structure */
13753 struct exec_domain *exec_domain; /* execution domain */
13754 __u32 flags; /* low level flags */
13755 __u32 status; /* thread synchronous flags */
13756 @@ -34,19 +34,13 @@ struct thread_info {
13757 mm_segment_t addr_limit;
13758 struct restart_block restart_block;
13759 void __user *sysenter_return;
13760 -#ifdef CONFIG_X86_32
13761 - unsigned long previous_esp; /* ESP of the previous stack in
13762 - case of nested (IRQ) stacks
13763 - */
13764 - __u8 supervisor_stack[0];
13765 -#endif
13766 + unsigned long lowest_stack;
13767 unsigned int sig_on_uaccess_error:1;
13768 unsigned int uaccess_err:1; /* uaccess failed */
13769 };
13770
13771 -#define INIT_THREAD_INFO(tsk) \
13772 +#define INIT_THREAD_INFO \
13773 { \
13774 - .task = &tsk, \
13775 .exec_domain = &default_exec_domain, \
13776 .flags = 0, \
13777 .cpu = 0, \
13778 @@ -57,7 +51,7 @@ struct thread_info {
13779 }, \
13780 }
13781
13782 -#define init_thread_info (init_thread_union.thread_info)
13783 +#define init_thread_info (init_thread_union.stack)
13784 #define init_stack (init_thread_union.stack)
13785
13786 #else /* !__ASSEMBLY__ */
13787 @@ -98,6 +92,7 @@ struct thread_info {
13788 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13789 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13790 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13791 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13792
13793 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13794 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13795 @@ -122,17 +117,18 @@ struct thread_info {
13796 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13797 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13798 #define _TIF_X32 (1 << TIF_X32)
13799 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13800
13801 /* work to do in syscall_trace_enter() */
13802 #define _TIF_WORK_SYSCALL_ENTRY \
13803 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13804 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13805 - _TIF_NOHZ)
13806 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13807
13808 /* work to do in syscall_trace_leave() */
13809 #define _TIF_WORK_SYSCALL_EXIT \
13810 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13811 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13812 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13813
13814 /* work to do on interrupt/exception return */
13815 #define _TIF_WORK_MASK \
13816 @@ -143,7 +139,7 @@ struct thread_info {
13817 /* work to do on any return to user space */
13818 #define _TIF_ALLWORK_MASK \
13819 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13820 - _TIF_NOHZ)
13821 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13822
13823 /* Only used for 64 bit */
13824 #define _TIF_DO_NOTIFY_MASK \
13825 @@ -159,45 +155,40 @@ struct thread_info {
13826
13827 #define PREEMPT_ACTIVE 0x10000000
13828
13829 -#ifdef CONFIG_X86_32
13830 -
13831 -#define STACK_WARN (THREAD_SIZE/8)
13832 -/*
13833 - * macros/functions for gaining access to the thread information structure
13834 - *
13835 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13836 - */
13837 -#ifndef __ASSEMBLY__
13838 -
13839 -
13840 -/* how to get the current stack pointer from C */
13841 -register unsigned long current_stack_pointer asm("esp") __used;
13842 -
13843 -/* how to get the thread information struct from C */
13844 -static inline struct thread_info *current_thread_info(void)
13845 -{
13846 - return (struct thread_info *)
13847 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13848 -}
13849 -
13850 -#else /* !__ASSEMBLY__ */
13851 -
13852 +#ifdef __ASSEMBLY__
13853 /* how to get the thread information struct from ASM */
13854 #define GET_THREAD_INFO(reg) \
13855 - movl $-THREAD_SIZE, reg; \
13856 - andl %esp, reg
13857 + mov PER_CPU_VAR(current_tinfo), reg
13858
13859 /* use this one if reg already contains %esp */
13860 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13861 - andl $-THREAD_SIZE, reg
13862 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13863 +#else
13864 +/* how to get the thread information struct from C */
13865 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13866 +
13867 +static __always_inline struct thread_info *current_thread_info(void)
13868 +{
13869 + return this_cpu_read_stable(current_tinfo);
13870 +}
13871 +#endif
13872 +
13873 +#ifdef CONFIG_X86_32
13874 +
13875 +#define STACK_WARN (THREAD_SIZE/8)
13876 +/*
13877 + * macros/functions for gaining access to the thread information structure
13878 + *
13879 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13880 + */
13881 +#ifndef __ASSEMBLY__
13882 +
13883 +/* how to get the current stack pointer from C */
13884 +register unsigned long current_stack_pointer asm("esp") __used;
13885
13886 #endif
13887
13888 #else /* X86_32 */
13889
13890 -#include <asm/percpu.h>
13891 -#define KERNEL_STACK_OFFSET (5*8)
13892 -
13893 /*
13894 * macros/functions for gaining access to the thread information structure
13895 * preempt_count needs to be 1 initially, until the scheduler is functional.
13896 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13897 #ifndef __ASSEMBLY__
13898 DECLARE_PER_CPU(unsigned long, kernel_stack);
13899
13900 -static inline struct thread_info *current_thread_info(void)
13901 -{
13902 - struct thread_info *ti;
13903 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13904 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13905 - return ti;
13906 -}
13907 -
13908 -#else /* !__ASSEMBLY__ */
13909 -
13910 -/* how to get the thread information struct from ASM */
13911 -#define GET_THREAD_INFO(reg) \
13912 - movq PER_CPU_VAR(kernel_stack),reg ; \
13913 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13914 -
13915 -/*
13916 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13917 - * a certain register (to be used in assembler memory operands).
13918 - */
13919 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13920 -
13921 +/* how to get the current stack pointer from C */
13922 +register unsigned long current_stack_pointer asm("rsp") __used;
13923 #endif
13924
13925 #endif /* !X86_32 */
13926 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13927 extern void arch_task_cache_init(void);
13928 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13929 extern void arch_release_task_struct(struct task_struct *tsk);
13930 +
13931 +#define __HAVE_THREAD_FUNCTIONS
13932 +#define task_thread_info(task) (&(task)->tinfo)
13933 +#define task_stack_page(task) ((task)->stack)
13934 +#define setup_thread_stack(p, org) do {} while (0)
13935 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13936 +
13937 #endif
13938 #endif /* _ASM_X86_THREAD_INFO_H */
13939 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13940 index 7ccf8d1..9a18110 100644
13941 --- a/arch/x86/include/asm/uaccess.h
13942 +++ b/arch/x86/include/asm/uaccess.h
13943 @@ -7,6 +7,7 @@
13944 #include <linux/compiler.h>
13945 #include <linux/thread_info.h>
13946 #include <linux/string.h>
13947 +#include <linux/sched.h>
13948 #include <asm/asm.h>
13949 #include <asm/page.h>
13950 #include <asm/smap.h>
13951 @@ -29,7 +30,12 @@
13952
13953 #define get_ds() (KERNEL_DS)
13954 #define get_fs() (current_thread_info()->addr_limit)
13955 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13956 +void __set_fs(mm_segment_t x);
13957 +void set_fs(mm_segment_t x);
13958 +#else
13959 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13960 +#endif
13961
13962 #define segment_eq(a, b) ((a).seg == (b).seg)
13963
13964 @@ -77,8 +83,33 @@
13965 * checks that the pointer is in the user space range - after calling
13966 * this function, memory access functions may still return -EFAULT.
13967 */
13968 -#define access_ok(type, addr, size) \
13969 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13970 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13971 +#define access_ok(type, addr, size) \
13972 +({ \
13973 + long __size = size; \
13974 + unsigned long __addr = (unsigned long)addr; \
13975 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13976 + unsigned long __end_ao = __addr + __size - 1; \
13977 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13978 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13979 + while(__addr_ao <= __end_ao) { \
13980 + char __c_ao; \
13981 + __addr_ao += PAGE_SIZE; \
13982 + if (__size > PAGE_SIZE) \
13983 + cond_resched(); \
13984 + if (__get_user(__c_ao, (char __user *)__addr)) \
13985 + break; \
13986 + if (type != VERIFY_WRITE) { \
13987 + __addr = __addr_ao; \
13988 + continue; \
13989 + } \
13990 + if (__put_user(__c_ao, (char __user *)__addr)) \
13991 + break; \
13992 + __addr = __addr_ao; \
13993 + } \
13994 + } \
13995 + __ret_ao; \
13996 +})
13997
13998 /*
13999 * The exception table consists of pairs of addresses relative to the
14000 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
14001 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
14002 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
14003
14004 -
14005 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
14006 +#define __copyuser_seg "gs;"
14007 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
14008 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
14009 +#else
14010 +#define __copyuser_seg
14011 +#define __COPYUSER_SET_ES
14012 +#define __COPYUSER_RESTORE_ES
14013 +#endif
14014
14015 #ifdef CONFIG_X86_32
14016 #define __put_user_asm_u64(x, addr, err, errret) \
14017 asm volatile(ASM_STAC "\n" \
14018 - "1: movl %%eax,0(%2)\n" \
14019 - "2: movl %%edx,4(%2)\n" \
14020 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
14021 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
14022 "3: " ASM_CLAC "\n" \
14023 ".section .fixup,\"ax\"\n" \
14024 "4: movl %3,%0\n" \
14025 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
14026
14027 #define __put_user_asm_ex_u64(x, addr) \
14028 asm volatile(ASM_STAC "\n" \
14029 - "1: movl %%eax,0(%1)\n" \
14030 - "2: movl %%edx,4(%1)\n" \
14031 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
14032 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
14033 "3: " ASM_CLAC "\n" \
14034 _ASM_EXTABLE_EX(1b, 2b) \
14035 _ASM_EXTABLE_EX(2b, 3b) \
14036 @@ -261,7 +300,7 @@ extern void __put_user_8(void);
14037 __typeof__(*(ptr)) __pu_val; \
14038 __chk_user_ptr(ptr); \
14039 might_fault(); \
14040 - __pu_val = x; \
14041 + __pu_val = (x); \
14042 switch (sizeof(*(ptr))) { \
14043 case 1: \
14044 __put_user_x(1, __pu_val, ptr, __ret_pu); \
14045 @@ -383,7 +422,7 @@ do { \
14046
14047 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14048 asm volatile(ASM_STAC "\n" \
14049 - "1: mov"itype" %2,%"rtype"1\n" \
14050 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
14051 "2: " ASM_CLAC "\n" \
14052 ".section .fixup,\"ax\"\n" \
14053 "3: mov %3,%0\n" \
14054 @@ -391,7 +430,7 @@ do { \
14055 " jmp 2b\n" \
14056 ".previous\n" \
14057 _ASM_EXTABLE(1b, 3b) \
14058 - : "=r" (err), ltype(x) \
14059 + : "=r" (err), ltype (x) \
14060 : "m" (__m(addr)), "i" (errret), "0" (err))
14061
14062 #define __get_user_size_ex(x, ptr, size) \
14063 @@ -416,7 +455,7 @@ do { \
14064 } while (0)
14065
14066 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
14067 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
14068 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
14069 "2:\n" \
14070 _ASM_EXTABLE_EX(1b, 2b) \
14071 : ltype(x) : "m" (__m(addr)))
14072 @@ -433,13 +472,24 @@ do { \
14073 int __gu_err; \
14074 unsigned long __gu_val; \
14075 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
14076 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
14077 + (x) = (__typeof__(*(ptr)))__gu_val; \
14078 __gu_err; \
14079 })
14080
14081 /* FIXME: this hack is definitely wrong -AK */
14082 struct __large_struct { unsigned long buf[100]; };
14083 -#define __m(x) (*(struct __large_struct __user *)(x))
14084 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14085 +#define ____m(x) \
14086 +({ \
14087 + unsigned long ____x = (unsigned long)(x); \
14088 + if (____x < PAX_USER_SHADOW_BASE) \
14089 + ____x += PAX_USER_SHADOW_BASE; \
14090 + (void __user *)____x; \
14091 +})
14092 +#else
14093 +#define ____m(x) (x)
14094 +#endif
14095 +#define __m(x) (*(struct __large_struct __user *)____m(x))
14096
14097 /*
14098 * Tell gcc we read from memory instead of writing: this is because
14099 @@ -448,7 +498,7 @@ struct __large_struct { unsigned long buf[100]; };
14100 */
14101 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14102 asm volatile(ASM_STAC "\n" \
14103 - "1: mov"itype" %"rtype"1,%2\n" \
14104 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14105 "2: " ASM_CLAC "\n" \
14106 ".section .fixup,\"ax\"\n" \
14107 "3: mov %3,%0\n" \
14108 @@ -456,10 +506,10 @@ struct __large_struct { unsigned long buf[100]; };
14109 ".previous\n" \
14110 _ASM_EXTABLE(1b, 3b) \
14111 : "=r"(err) \
14112 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14113 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14114
14115 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14116 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14117 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14118 "2:\n" \
14119 _ASM_EXTABLE_EX(1b, 2b) \
14120 : : ltype(x), "m" (__m(addr)))
14121 @@ -498,8 +548,12 @@ struct __large_struct { unsigned long buf[100]; };
14122 * On error, the variable @x is set to zero.
14123 */
14124
14125 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14126 +#define __get_user(x, ptr) get_user((x), (ptr))
14127 +#else
14128 #define __get_user(x, ptr) \
14129 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14130 +#endif
14131
14132 /**
14133 * __put_user: - Write a simple value into user space, with less checking.
14134 @@ -521,8 +575,12 @@ struct __large_struct { unsigned long buf[100]; };
14135 * Returns zero on success, or -EFAULT on error.
14136 */
14137
14138 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14139 +#define __put_user(x, ptr) put_user((x), (ptr))
14140 +#else
14141 #define __put_user(x, ptr) \
14142 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14143 +#endif
14144
14145 #define __get_user_unaligned __get_user
14146 #define __put_user_unaligned __put_user
14147 @@ -540,7 +598,7 @@ struct __large_struct { unsigned long buf[100]; };
14148 #define get_user_ex(x, ptr) do { \
14149 unsigned long __gue_val; \
14150 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14151 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
14152 + (x) = (__typeof__(*(ptr)))__gue_val; \
14153 } while (0)
14154
14155 #ifdef CONFIG_X86_WP_WORKS_OK
14156 @@ -574,8 +632,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14157 extern __must_check long strlen_user(const char __user *str);
14158 extern __must_check long strnlen_user(const char __user *str, long n);
14159
14160 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14161 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14162 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14163 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14164
14165 /*
14166 * movsl can be slow when source and dest are not both 8-byte aligned
14167 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14168 index 7f760a9..04b1c65 100644
14169 --- a/arch/x86/include/asm/uaccess_32.h
14170 +++ b/arch/x86/include/asm/uaccess_32.h
14171 @@ -11,15 +11,15 @@
14172 #include <asm/page.h>
14173
14174 unsigned long __must_check __copy_to_user_ll
14175 - (void __user *to, const void *from, unsigned long n);
14176 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14177 unsigned long __must_check __copy_from_user_ll
14178 - (void *to, const void __user *from, unsigned long n);
14179 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14180 unsigned long __must_check __copy_from_user_ll_nozero
14181 - (void *to, const void __user *from, unsigned long n);
14182 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14183 unsigned long __must_check __copy_from_user_ll_nocache
14184 - (void *to, const void __user *from, unsigned long n);
14185 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14186 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14187 - (void *to, const void __user *from, unsigned long n);
14188 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14189
14190 /**
14191 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14192 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14193 static __always_inline unsigned long __must_check
14194 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14195 {
14196 + if ((long)n < 0)
14197 + return n;
14198 +
14199 + check_object_size(from, n, true);
14200 +
14201 if (__builtin_constant_p(n)) {
14202 unsigned long ret;
14203
14204 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14205 __copy_to_user(void __user *to, const void *from, unsigned long n)
14206 {
14207 might_fault();
14208 +
14209 return __copy_to_user_inatomic(to, from, n);
14210 }
14211
14212 static __always_inline unsigned long
14213 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14214 {
14215 + if ((long)n < 0)
14216 + return n;
14217 +
14218 /* Avoid zeroing the tail if the copy fails..
14219 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14220 * but as the zeroing behaviour is only significant when n is not
14221 @@ -137,6 +146,12 @@ static __always_inline unsigned long
14222 __copy_from_user(void *to, const void __user *from, unsigned long n)
14223 {
14224 might_fault();
14225 +
14226 + if ((long)n < 0)
14227 + return n;
14228 +
14229 + check_object_size(to, n, false);
14230 +
14231 if (__builtin_constant_p(n)) {
14232 unsigned long ret;
14233
14234 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14235 const void __user *from, unsigned long n)
14236 {
14237 might_fault();
14238 +
14239 + if ((long)n < 0)
14240 + return n;
14241 +
14242 if (__builtin_constant_p(n)) {
14243 unsigned long ret;
14244
14245 @@ -181,15 +200,19 @@ static __always_inline unsigned long
14246 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14247 unsigned long n)
14248 {
14249 - return __copy_from_user_ll_nocache_nozero(to, from, n);
14250 + if ((long)n < 0)
14251 + return n;
14252 +
14253 + return __copy_from_user_ll_nocache_nozero(to, from, n);
14254 }
14255
14256 -unsigned long __must_check copy_to_user(void __user *to,
14257 - const void *from, unsigned long n);
14258 -unsigned long __must_check _copy_from_user(void *to,
14259 - const void __user *from,
14260 - unsigned long n);
14261 -
14262 +extern void copy_to_user_overflow(void)
14263 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14264 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14265 +#else
14266 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14267 +#endif
14268 +;
14269
14270 extern void copy_from_user_overflow(void)
14271 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14272 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
14273 #endif
14274 ;
14275
14276 -static inline unsigned long __must_check copy_from_user(void *to,
14277 - const void __user *from,
14278 - unsigned long n)
14279 +/**
14280 + * copy_to_user: - Copy a block of data into user space.
14281 + * @to: Destination address, in user space.
14282 + * @from: Source address, in kernel space.
14283 + * @n: Number of bytes to copy.
14284 + *
14285 + * Context: User context only. This function may sleep.
14286 + *
14287 + * Copy data from kernel space to user space.
14288 + *
14289 + * Returns number of bytes that could not be copied.
14290 + * On success, this will be zero.
14291 + */
14292 +static inline unsigned long __must_check
14293 +copy_to_user(void __user *to, const void *from, unsigned long n)
14294 {
14295 - int sz = __compiletime_object_size(to);
14296 + size_t sz = __compiletime_object_size(from);
14297
14298 - if (likely(sz == -1 || sz >= n))
14299 - n = _copy_from_user(to, from, n);
14300 - else
14301 + if (unlikely(sz != (size_t)-1 && sz < n))
14302 + copy_to_user_overflow();
14303 + else if (access_ok(VERIFY_WRITE, to, n))
14304 + n = __copy_to_user(to, from, n);
14305 + return n;
14306 +}
14307 +
14308 +/**
14309 + * copy_from_user: - Copy a block of data from user space.
14310 + * @to: Destination address, in kernel space.
14311 + * @from: Source address, in user space.
14312 + * @n: Number of bytes to copy.
14313 + *
14314 + * Context: User context only. This function may sleep.
14315 + *
14316 + * Copy data from user space to kernel space.
14317 + *
14318 + * Returns number of bytes that could not be copied.
14319 + * On success, this will be zero.
14320 + *
14321 + * If some data could not be copied, this function will pad the copied
14322 + * data to the requested size using zero bytes.
14323 + */
14324 +static inline unsigned long __must_check
14325 +copy_from_user(void *to, const void __user *from, unsigned long n)
14326 +{
14327 + size_t sz = __compiletime_object_size(to);
14328 +
14329 + check_object_size(to, n, false);
14330 +
14331 + if (unlikely(sz != (size_t)-1 && sz < n))
14332 copy_from_user_overflow();
14333 -
14334 + else if (access_ok(VERIFY_READ, from, n))
14335 + n = __copy_from_user(to, from, n);
14336 + else if ((long)n > 0)
14337 + memset(to, 0, n);
14338 return n;
14339 }
14340
14341 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14342 index 142810c..4b68a3e 100644
14343 --- a/arch/x86/include/asm/uaccess_64.h
14344 +++ b/arch/x86/include/asm/uaccess_64.h
14345 @@ -10,6 +10,9 @@
14346 #include <asm/alternative.h>
14347 #include <asm/cpufeature.h>
14348 #include <asm/page.h>
14349 +#include <asm/pgtable.h>
14350 +
14351 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
14352
14353 /*
14354 * Copy To/From Userspace
14355 @@ -17,13 +20,13 @@
14356
14357 /* Handles exceptions in both to and from, but doesn't do access_ok */
14358 __must_check unsigned long
14359 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14360 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14361 __must_check unsigned long
14362 -copy_user_generic_string(void *to, const void *from, unsigned len);
14363 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14364 __must_check unsigned long
14365 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14366 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14367
14368 -static __always_inline __must_check unsigned long
14369 +static __always_inline __must_check __size_overflow(3) unsigned long
14370 copy_user_generic(void *to, const void *from, unsigned len)
14371 {
14372 unsigned ret;
14373 @@ -41,142 +44,203 @@ copy_user_generic(void *to, const void *from, unsigned len)
14374 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14375 "=d" (len)),
14376 "1" (to), "2" (from), "3" (len)
14377 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14378 + : "memory", "rcx", "r8", "r9", "r11");
14379 return ret;
14380 }
14381
14382 +static __always_inline __must_check unsigned long
14383 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14384 +static __always_inline __must_check unsigned long
14385 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14386 __must_check unsigned long
14387 -_copy_to_user(void __user *to, const void *from, unsigned len);
14388 -__must_check unsigned long
14389 -_copy_from_user(void *to, const void __user *from, unsigned len);
14390 -__must_check unsigned long
14391 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14392 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14393 +
14394 +extern void copy_to_user_overflow(void)
14395 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14396 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14397 +#else
14398 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14399 +#endif
14400 +;
14401 +
14402 +extern void copy_from_user_overflow(void)
14403 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14404 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14405 +#else
14406 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14407 +#endif
14408 +;
14409
14410 static inline unsigned long __must_check copy_from_user(void *to,
14411 const void __user *from,
14412 unsigned long n)
14413 {
14414 - int sz = __compiletime_object_size(to);
14415 -
14416 might_fault();
14417 - if (likely(sz == -1 || sz >= n))
14418 - n = _copy_from_user(to, from, n);
14419 -#ifdef CONFIG_DEBUG_VM
14420 - else
14421 - WARN(1, "Buffer overflow detected!\n");
14422 -#endif
14423 +
14424 + check_object_size(to, n, false);
14425 + if (access_ok(VERIFY_READ, from, n))
14426 + n = __copy_from_user(to, from, n);
14427 + else if (n < INT_MAX)
14428 + memset(to, 0, n);
14429 return n;
14430 }
14431
14432 static __always_inline __must_check
14433 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14434 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14435 {
14436 might_fault();
14437
14438 - return _copy_to_user(dst, src, size);
14439 + if (access_ok(VERIFY_WRITE, dst, size))
14440 + size = __copy_to_user(dst, src, size);
14441 + return size;
14442 }
14443
14444 static __always_inline __must_check
14445 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14446 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14447 {
14448 - int ret = 0;
14449 + size_t sz = __compiletime_object_size(dst);
14450 + unsigned ret = 0;
14451
14452 might_fault();
14453 +
14454 + if (size > INT_MAX)
14455 + return size;
14456 +
14457 + check_object_size(dst, size, false);
14458 +
14459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14460 + if (!__access_ok(VERIFY_READ, src, size))
14461 + return size;
14462 +#endif
14463 +
14464 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14465 + copy_from_user_overflow();
14466 + return size;
14467 + }
14468 +
14469 if (!__builtin_constant_p(size))
14470 - return copy_user_generic(dst, (__force void *)src, size);
14471 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14472 switch (size) {
14473 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14474 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14475 ret, "b", "b", "=q", 1);
14476 return ret;
14477 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14478 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14479 ret, "w", "w", "=r", 2);
14480 return ret;
14481 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14482 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14483 ret, "l", "k", "=r", 4);
14484 return ret;
14485 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14486 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14487 ret, "q", "", "=r", 8);
14488 return ret;
14489 case 10:
14490 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14491 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14492 ret, "q", "", "=r", 10);
14493 if (unlikely(ret))
14494 return ret;
14495 __get_user_asm(*(u16 *)(8 + (char *)dst),
14496 - (u16 __user *)(8 + (char __user *)src),
14497 + (const u16 __user *)(8 + (const char __user *)src),
14498 ret, "w", "w", "=r", 2);
14499 return ret;
14500 case 16:
14501 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14502 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14503 ret, "q", "", "=r", 16);
14504 if (unlikely(ret))
14505 return ret;
14506 __get_user_asm(*(u64 *)(8 + (char *)dst),
14507 - (u64 __user *)(8 + (char __user *)src),
14508 + (const u64 __user *)(8 + (const char __user *)src),
14509 ret, "q", "", "=r", 8);
14510 return ret;
14511 default:
14512 - return copy_user_generic(dst, (__force void *)src, size);
14513 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14514 }
14515 }
14516
14517 static __always_inline __must_check
14518 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14519 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14520 {
14521 - int ret = 0;
14522 + size_t sz = __compiletime_object_size(src);
14523 + unsigned ret = 0;
14524
14525 might_fault();
14526 +
14527 + if (size > INT_MAX)
14528 + return size;
14529 +
14530 + check_object_size(src, size, true);
14531 +
14532 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14533 + if (!__access_ok(VERIFY_WRITE, dst, size))
14534 + return size;
14535 +#endif
14536 +
14537 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14538 + copy_to_user_overflow();
14539 + return size;
14540 + }
14541 +
14542 if (!__builtin_constant_p(size))
14543 - return copy_user_generic((__force void *)dst, src, size);
14544 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14545 switch (size) {
14546 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14547 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14548 ret, "b", "b", "iq", 1);
14549 return ret;
14550 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14551 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14552 ret, "w", "w", "ir", 2);
14553 return ret;
14554 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14555 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14556 ret, "l", "k", "ir", 4);
14557 return ret;
14558 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14559 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14560 ret, "q", "", "er", 8);
14561 return ret;
14562 case 10:
14563 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14564 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14565 ret, "q", "", "er", 10);
14566 if (unlikely(ret))
14567 return ret;
14568 asm("":::"memory");
14569 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14570 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14571 ret, "w", "w", "ir", 2);
14572 return ret;
14573 case 16:
14574 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14575 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14576 ret, "q", "", "er", 16);
14577 if (unlikely(ret))
14578 return ret;
14579 asm("":::"memory");
14580 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14581 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14582 ret, "q", "", "er", 8);
14583 return ret;
14584 default:
14585 - return copy_user_generic((__force void *)dst, src, size);
14586 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14587 }
14588 }
14589
14590 static __always_inline __must_check
14591 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14592 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14593 {
14594 - int ret = 0;
14595 + unsigned ret = 0;
14596
14597 might_fault();
14598 +
14599 + if (size > INT_MAX)
14600 + return size;
14601 +
14602 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14603 + if (!__access_ok(VERIFY_READ, src, size))
14604 + return size;
14605 + if (!__access_ok(VERIFY_WRITE, dst, size))
14606 + return size;
14607 +#endif
14608 +
14609 if (!__builtin_constant_p(size))
14610 - return copy_user_generic((__force void *)dst,
14611 - (__force void *)src, size);
14612 + return copy_user_generic((__force_kernel void *)____m(dst),
14613 + (__force_kernel const void *)____m(src), size);
14614 switch (size) {
14615 case 1: {
14616 u8 tmp;
14617 - __get_user_asm(tmp, (u8 __user *)src,
14618 + __get_user_asm(tmp, (const u8 __user *)src,
14619 ret, "b", "b", "=q", 1);
14620 if (likely(!ret))
14621 __put_user_asm(tmp, (u8 __user *)dst,
14622 @@ -185,7 +249,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14623 }
14624 case 2: {
14625 u16 tmp;
14626 - __get_user_asm(tmp, (u16 __user *)src,
14627 + __get_user_asm(tmp, (const u16 __user *)src,
14628 ret, "w", "w", "=r", 2);
14629 if (likely(!ret))
14630 __put_user_asm(tmp, (u16 __user *)dst,
14631 @@ -195,7 +259,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14632
14633 case 4: {
14634 u32 tmp;
14635 - __get_user_asm(tmp, (u32 __user *)src,
14636 + __get_user_asm(tmp, (const u32 __user *)src,
14637 ret, "l", "k", "=r", 4);
14638 if (likely(!ret))
14639 __put_user_asm(tmp, (u32 __user *)dst,
14640 @@ -204,7 +268,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14641 }
14642 case 8: {
14643 u64 tmp;
14644 - __get_user_asm(tmp, (u64 __user *)src,
14645 + __get_user_asm(tmp, (const u64 __user *)src,
14646 ret, "q", "", "=r", 8);
14647 if (likely(!ret))
14648 __put_user_asm(tmp, (u64 __user *)dst,
14649 @@ -212,41 +276,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14650 return ret;
14651 }
14652 default:
14653 - return copy_user_generic((__force void *)dst,
14654 - (__force void *)src, size);
14655 + return copy_user_generic((__force_kernel void *)____m(dst),
14656 + (__force_kernel const void *)____m(src), size);
14657 }
14658 }
14659
14660 static __must_check __always_inline int
14661 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14662 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14663 {
14664 - return copy_user_generic(dst, (__force const void *)src, size);
14665 + if (size > INT_MAX)
14666 + return size;
14667 +
14668 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14669 + if (!__access_ok(VERIFY_READ, src, size))
14670 + return size;
14671 +#endif
14672 +
14673 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14674 }
14675
14676 -static __must_check __always_inline int
14677 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14678 +static __must_check __always_inline unsigned long
14679 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14680 {
14681 - return copy_user_generic((__force void *)dst, src, size);
14682 + if (size > INT_MAX)
14683 + return size;
14684 +
14685 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14686 + if (!__access_ok(VERIFY_WRITE, dst, size))
14687 + return size;
14688 +#endif
14689 +
14690 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14691 }
14692
14693 -extern long __copy_user_nocache(void *dst, const void __user *src,
14694 - unsigned size, int zerorest);
14695 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14696 + unsigned long size, int zerorest) __size_overflow(3);
14697
14698 -static inline int
14699 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14700 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14701 {
14702 might_sleep();
14703 +
14704 + if (size > INT_MAX)
14705 + return size;
14706 +
14707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14708 + if (!__access_ok(VERIFY_READ, src, size))
14709 + return size;
14710 +#endif
14711 +
14712 return __copy_user_nocache(dst, src, size, 1);
14713 }
14714
14715 -static inline int
14716 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14717 - unsigned size)
14718 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14719 + unsigned long size)
14720 {
14721 + if (size > INT_MAX)
14722 + return size;
14723 +
14724 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14725 + if (!__access_ok(VERIFY_READ, src, size))
14726 + return size;
14727 +#endif
14728 +
14729 return __copy_user_nocache(dst, src, size, 0);
14730 }
14731
14732 -unsigned long
14733 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14734 +extern unsigned long
14735 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14736
14737 #endif /* _ASM_X86_UACCESS_64_H */
14738 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14739 index 5b238981..77fdd78 100644
14740 --- a/arch/x86/include/asm/word-at-a-time.h
14741 +++ b/arch/x86/include/asm/word-at-a-time.h
14742 @@ -11,7 +11,7 @@
14743 * and shift, for example.
14744 */
14745 struct word_at_a_time {
14746 - const unsigned long one_bits, high_bits;
14747 + unsigned long one_bits, high_bits;
14748 };
14749
14750 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14751 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
14752 index 5769349..a3d3e2a 100644
14753 --- a/arch/x86/include/asm/x86_init.h
14754 +++ b/arch/x86/include/asm/x86_init.h
14755 @@ -141,7 +141,7 @@ struct x86_init_ops {
14756 struct x86_init_timers timers;
14757 struct x86_init_iommu iommu;
14758 struct x86_init_pci pci;
14759 -};
14760 +} __no_const;
14761
14762 /**
14763 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
14764 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
14765 void (*setup_percpu_clockev)(void);
14766 void (*early_percpu_clock_init)(void);
14767 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
14768 -};
14769 +} __no_const;
14770
14771 /**
14772 * struct x86_platform_ops - platform specific runtime functions
14773 @@ -178,7 +178,7 @@ struct x86_platform_ops {
14774 void (*save_sched_clock_state)(void);
14775 void (*restore_sched_clock_state)(void);
14776 void (*apic_post_init)(void);
14777 -};
14778 +} __no_const;
14779
14780 struct pci_dev;
14781
14782 @@ -187,14 +187,14 @@ struct x86_msi_ops {
14783 void (*teardown_msi_irq)(unsigned int irq);
14784 void (*teardown_msi_irqs)(struct pci_dev *dev);
14785 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
14786 -};
14787 +} __no_const;
14788
14789 struct x86_io_apic_ops {
14790 void (*init) (void);
14791 unsigned int (*read) (unsigned int apic, unsigned int reg);
14792 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
14793 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
14794 -};
14795 +} __no_const;
14796
14797 extern struct x86_init_ops x86_init;
14798 extern struct x86_cpuinit_ops x86_cpuinit;
14799 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14800 index 0415cda..b43d877 100644
14801 --- a/arch/x86/include/asm/xsave.h
14802 +++ b/arch/x86/include/asm/xsave.h
14803 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14804 return -EFAULT;
14805
14806 __asm__ __volatile__(ASM_STAC "\n"
14807 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14808 + "1:"
14809 + __copyuser_seg
14810 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14811 "2: " ASM_CLAC "\n"
14812 ".section .fixup,\"ax\"\n"
14813 "3: movl $-1,%[err]\n"
14814 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14815 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14816 {
14817 int err;
14818 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14819 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14820 u32 lmask = mask;
14821 u32 hmask = mask >> 32;
14822
14823 __asm__ __volatile__(ASM_STAC "\n"
14824 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14825 + "1:"
14826 + __copyuser_seg
14827 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14828 "2: " ASM_CLAC "\n"
14829 ".section .fixup,\"ax\"\n"
14830 "3: movl $-1,%[err]\n"
14831 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14832 index 91ce48f..a48ea05 100644
14833 --- a/arch/x86/kernel/Makefile
14834 +++ b/arch/x86/kernel/Makefile
14835 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14836 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14837 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14838 obj-y += probe_roms.o
14839 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14840 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14841 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14842 obj-y += syscall_$(BITS).o
14843 obj-$(CONFIG_X86_64) += vsyscall_64.o
14844 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14845 index 11676cf..a8cf3ec 100644
14846 --- a/arch/x86/kernel/acpi/sleep.c
14847 +++ b/arch/x86/kernel/acpi/sleep.c
14848 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14849 #else /* CONFIG_64BIT */
14850 #ifdef CONFIG_SMP
14851 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14852 +
14853 + pax_open_kernel();
14854 early_gdt_descr.address =
14855 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14856 + pax_close_kernel();
14857 +
14858 initial_gs = per_cpu_offset(smp_processor_id());
14859 #endif
14860 initial_code = (unsigned long)wakeup_long64;
14861 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14862 index 13ab720..95d5442 100644
14863 --- a/arch/x86/kernel/acpi/wakeup_32.S
14864 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14865 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14866 # and restore the stack ... but you need gdt for this to work
14867 movl saved_context_esp, %esp
14868
14869 - movl %cs:saved_magic, %eax
14870 - cmpl $0x12345678, %eax
14871 + cmpl $0x12345678, saved_magic
14872 jne bogus_magic
14873
14874 # jump to place where we left off
14875 - movl saved_eip, %eax
14876 - jmp *%eax
14877 + jmp *(saved_eip)
14878
14879 bogus_magic:
14880 jmp bogus_magic
14881 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14882 index ef5ccca..bd83949 100644
14883 --- a/arch/x86/kernel/alternative.c
14884 +++ b/arch/x86/kernel/alternative.c
14885 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14886 */
14887 for (a = start; a < end; a++) {
14888 instr = (u8 *)&a->instr_offset + a->instr_offset;
14889 +
14890 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14891 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14892 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14893 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14894 +#endif
14895 +
14896 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14897 BUG_ON(a->replacementlen > a->instrlen);
14898 BUG_ON(a->instrlen > sizeof(insnbuf));
14899 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14900 for (poff = start; poff < end; poff++) {
14901 u8 *ptr = (u8 *)poff + *poff;
14902
14903 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14904 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14905 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14906 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14907 +#endif
14908 +
14909 if (!*poff || ptr < text || ptr >= text_end)
14910 continue;
14911 /* turn DS segment override prefix into lock prefix */
14912 - if (*ptr == 0x3e)
14913 + if (*ktla_ktva(ptr) == 0x3e)
14914 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14915 }
14916 mutex_unlock(&text_mutex);
14917 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14918 for (poff = start; poff < end; poff++) {
14919 u8 *ptr = (u8 *)poff + *poff;
14920
14921 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14922 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14923 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14924 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14925 +#endif
14926 +
14927 if (!*poff || ptr < text || ptr >= text_end)
14928 continue;
14929 /* turn lock prefix into DS segment override prefix */
14930 - if (*ptr == 0xf0)
14931 + if (*ktla_ktva(ptr) == 0xf0)
14932 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14933 }
14934 mutex_unlock(&text_mutex);
14935 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14936
14937 BUG_ON(p->len > MAX_PATCH_LEN);
14938 /* prep the buffer with the original instructions */
14939 - memcpy(insnbuf, p->instr, p->len);
14940 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14941 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14942 (unsigned long)p->instr, p->len);
14943
14944 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14945 if (!uniproc_patched || num_possible_cpus() == 1)
14946 free_init_pages("SMP alternatives",
14947 (unsigned long)__smp_locks,
14948 - (unsigned long)__smp_locks_end);
14949 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14950 #endif
14951
14952 apply_paravirt(__parainstructions, __parainstructions_end);
14953 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14954 * instructions. And on the local CPU you need to be protected again NMI or MCE
14955 * handlers seeing an inconsistent instruction while you patch.
14956 */
14957 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14958 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14959 size_t len)
14960 {
14961 unsigned long flags;
14962 local_irq_save(flags);
14963 - memcpy(addr, opcode, len);
14964 +
14965 + pax_open_kernel();
14966 + memcpy(ktla_ktva(addr), opcode, len);
14967 sync_core();
14968 + pax_close_kernel();
14969 +
14970 local_irq_restore(flags);
14971 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14972 that causes hangs on some VIA CPUs. */
14973 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14974 */
14975 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14976 {
14977 - unsigned long flags;
14978 - char *vaddr;
14979 + unsigned char *vaddr = ktla_ktva(addr);
14980 struct page *pages[2];
14981 - int i;
14982 + size_t i;
14983
14984 if (!core_kernel_text((unsigned long)addr)) {
14985 - pages[0] = vmalloc_to_page(addr);
14986 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14987 + pages[0] = vmalloc_to_page(vaddr);
14988 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14989 } else {
14990 - pages[0] = virt_to_page(addr);
14991 + pages[0] = virt_to_page(vaddr);
14992 WARN_ON(!PageReserved(pages[0]));
14993 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14994 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14995 }
14996 BUG_ON(!pages[0]);
14997 - local_irq_save(flags);
14998 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14999 - if (pages[1])
15000 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
15001 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
15002 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
15003 - clear_fixmap(FIX_TEXT_POKE0);
15004 - if (pages[1])
15005 - clear_fixmap(FIX_TEXT_POKE1);
15006 - local_flush_tlb();
15007 - sync_core();
15008 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
15009 - that causes hangs on some VIA CPUs. */
15010 + text_poke_early(addr, opcode, len);
15011 for (i = 0; i < len; i++)
15012 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
15013 - local_irq_restore(flags);
15014 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
15015 return addr;
15016 }
15017
15018 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
15019 index b17416e..5ed0f3e 100644
15020 --- a/arch/x86/kernel/apic/apic.c
15021 +++ b/arch/x86/kernel/apic/apic.c
15022 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
15023 /*
15024 * Debug level, exported for io_apic.c
15025 */
15026 -unsigned int apic_verbosity;
15027 +int apic_verbosity;
15028
15029 int pic_mode;
15030
15031 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
15032 apic_write(APIC_ESR, 0);
15033 v1 = apic_read(APIC_ESR);
15034 ack_APIC_irq();
15035 - atomic_inc(&irq_err_count);
15036 + atomic_inc_unchecked(&irq_err_count);
15037
15038 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
15039 smp_processor_id(), v0 , v1);
15040 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
15041 index 00c77cf..2dc6a2d 100644
15042 --- a/arch/x86/kernel/apic/apic_flat_64.c
15043 +++ b/arch/x86/kernel/apic/apic_flat_64.c
15044 @@ -157,7 +157,7 @@ static int flat_probe(void)
15045 return 1;
15046 }
15047
15048 -static struct apic apic_flat = {
15049 +static struct apic apic_flat __read_only = {
15050 .name = "flat",
15051 .probe = flat_probe,
15052 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
15053 @@ -271,7 +271,7 @@ static int physflat_probe(void)
15054 return 0;
15055 }
15056
15057 -static struct apic apic_physflat = {
15058 +static struct apic apic_physflat __read_only = {
15059
15060 .name = "physical flat",
15061 .probe = physflat_probe,
15062 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
15063 index d50e364..543bee3 100644
15064 --- a/arch/x86/kernel/apic/bigsmp_32.c
15065 +++ b/arch/x86/kernel/apic/bigsmp_32.c
15066 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
15067 return dmi_bigsmp;
15068 }
15069
15070 -static struct apic apic_bigsmp = {
15071 +static struct apic apic_bigsmp __read_only = {
15072
15073 .name = "bigsmp",
15074 .probe = probe_bigsmp,
15075 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
15076 index 0874799..24a836e 100644
15077 --- a/arch/x86/kernel/apic/es7000_32.c
15078 +++ b/arch/x86/kernel/apic/es7000_32.c
15079 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
15080 return ret && es7000_apic_is_cluster();
15081 }
15082
15083 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
15084 -static struct apic __refdata apic_es7000_cluster = {
15085 +static struct apic apic_es7000_cluster __read_only = {
15086
15087 .name = "es7000",
15088 .probe = probe_es7000,
15089 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
15090 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
15091 };
15092
15093 -static struct apic __refdata apic_es7000 = {
15094 +static struct apic __refdata apic_es7000 __read_only = {
15095
15096 .name = "es7000",
15097 .probe = probe_es7000,
15098 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
15099 index 1817fa9..7bff097 100644
15100 --- a/arch/x86/kernel/apic/io_apic.c
15101 +++ b/arch/x86/kernel/apic/io_apic.c
15102 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
15103 }
15104 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
15105
15106 -void lock_vector_lock(void)
15107 +void lock_vector_lock(void) __acquires(vector_lock)
15108 {
15109 /* Used to the online set of cpus does not change
15110 * during assign_irq_vector.
15111 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
15112 raw_spin_lock(&vector_lock);
15113 }
15114
15115 -void unlock_vector_lock(void)
15116 +void unlock_vector_lock(void) __releases(vector_lock)
15117 {
15118 raw_spin_unlock(&vector_lock);
15119 }
15120 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
15121 ack_APIC_irq();
15122 }
15123
15124 -atomic_t irq_mis_count;
15125 +atomic_unchecked_t irq_mis_count;
15126
15127 #ifdef CONFIG_GENERIC_PENDING_IRQ
15128 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15129 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15130 * at the cpu.
15131 */
15132 if (!(v & (1 << (i & 0x1f)))) {
15133 - atomic_inc(&irq_mis_count);
15134 + atomic_inc_unchecked(&irq_mis_count);
15135
15136 eoi_ioapic_irq(irq, cfg);
15137 }
15138 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15139 index d661ee9..791fd33 100644
15140 --- a/arch/x86/kernel/apic/numaq_32.c
15141 +++ b/arch/x86/kernel/apic/numaq_32.c
15142 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
15143 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
15144 }
15145
15146 -/* Use __refdata to keep false positive warning calm. */
15147 -static struct apic __refdata apic_numaq = {
15148 +static struct apic apic_numaq __read_only = {
15149
15150 .name = "NUMAQ",
15151 .probe = probe_numaq,
15152 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
15153 index eb35ef9..f184a21 100644
15154 --- a/arch/x86/kernel/apic/probe_32.c
15155 +++ b/arch/x86/kernel/apic/probe_32.c
15156 @@ -72,7 +72,7 @@ static int probe_default(void)
15157 return 1;
15158 }
15159
15160 -static struct apic apic_default = {
15161 +static struct apic apic_default __read_only = {
15162
15163 .name = "default",
15164 .probe = probe_default,
15165 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
15166 index 77c95c0..434f8a4 100644
15167 --- a/arch/x86/kernel/apic/summit_32.c
15168 +++ b/arch/x86/kernel/apic/summit_32.c
15169 @@ -486,7 +486,7 @@ void setup_summit(void)
15170 }
15171 #endif
15172
15173 -static struct apic apic_summit = {
15174 +static struct apic apic_summit __read_only = {
15175
15176 .name = "summit",
15177 .probe = probe_summit,
15178 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
15179 index c88baa4..a89def0 100644
15180 --- a/arch/x86/kernel/apic/x2apic_cluster.c
15181 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
15182 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
15183 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
15184 }
15185
15186 -static struct apic apic_x2apic_cluster = {
15187 +static struct apic apic_x2apic_cluster __read_only = {
15188
15189 .name = "cluster x2apic",
15190 .probe = x2apic_cluster_probe,
15191 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
15192 index 562a76d..a003c0f 100644
15193 --- a/arch/x86/kernel/apic/x2apic_phys.c
15194 +++ b/arch/x86/kernel/apic/x2apic_phys.c
15195 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
15196 return apic == &apic_x2apic_phys;
15197 }
15198
15199 -static struct apic apic_x2apic_phys = {
15200 +static struct apic apic_x2apic_phys __read_only = {
15201
15202 .name = "physical x2apic",
15203 .probe = x2apic_phys_probe,
15204 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15205 index 8cfade9..b9d04fc 100644
15206 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
15207 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15208 @@ -333,7 +333,7 @@ static int uv_probe(void)
15209 return apic == &apic_x2apic_uv_x;
15210 }
15211
15212 -static struct apic __refdata apic_x2apic_uv_x = {
15213 +static struct apic apic_x2apic_uv_x __read_only = {
15214
15215 .name = "UV large system",
15216 .probe = uv_probe,
15217 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15218 index d65464e..1035d31 100644
15219 --- a/arch/x86/kernel/apm_32.c
15220 +++ b/arch/x86/kernel/apm_32.c
15221 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15222 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15223 * even though they are called in protected mode.
15224 */
15225 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15226 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15227 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15228
15229 static const char driver_version[] = "1.16ac"; /* no spaces */
15230 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15231 BUG_ON(cpu != 0);
15232 gdt = get_cpu_gdt_table(cpu);
15233 save_desc_40 = gdt[0x40 / 8];
15234 +
15235 + pax_open_kernel();
15236 gdt[0x40 / 8] = bad_bios_desc;
15237 + pax_close_kernel();
15238
15239 apm_irq_save(flags);
15240 APM_DO_SAVE_SEGS;
15241 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15242 &call->esi);
15243 APM_DO_RESTORE_SEGS;
15244 apm_irq_restore(flags);
15245 +
15246 + pax_open_kernel();
15247 gdt[0x40 / 8] = save_desc_40;
15248 + pax_close_kernel();
15249 +
15250 put_cpu();
15251
15252 return call->eax & 0xff;
15253 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15254 BUG_ON(cpu != 0);
15255 gdt = get_cpu_gdt_table(cpu);
15256 save_desc_40 = gdt[0x40 / 8];
15257 +
15258 + pax_open_kernel();
15259 gdt[0x40 / 8] = bad_bios_desc;
15260 + pax_close_kernel();
15261
15262 apm_irq_save(flags);
15263 APM_DO_SAVE_SEGS;
15264 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15265 &call->eax);
15266 APM_DO_RESTORE_SEGS;
15267 apm_irq_restore(flags);
15268 +
15269 + pax_open_kernel();
15270 gdt[0x40 / 8] = save_desc_40;
15271 + pax_close_kernel();
15272 +
15273 put_cpu();
15274 return error;
15275 }
15276 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15277 * code to that CPU.
15278 */
15279 gdt = get_cpu_gdt_table(0);
15280 +
15281 + pax_open_kernel();
15282 set_desc_base(&gdt[APM_CS >> 3],
15283 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15284 set_desc_base(&gdt[APM_CS_16 >> 3],
15285 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15286 set_desc_base(&gdt[APM_DS >> 3],
15287 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15288 + pax_close_kernel();
15289
15290 proc_create("apm", 0, NULL, &apm_file_ops);
15291
15292 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15293 index 2861082..6d4718e 100644
15294 --- a/arch/x86/kernel/asm-offsets.c
15295 +++ b/arch/x86/kernel/asm-offsets.c
15296 @@ -33,6 +33,8 @@ void common(void) {
15297 OFFSET(TI_status, thread_info, status);
15298 OFFSET(TI_addr_limit, thread_info, addr_limit);
15299 OFFSET(TI_preempt_count, thread_info, preempt_count);
15300 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15301 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15302
15303 BLANK();
15304 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15305 @@ -53,8 +55,26 @@ void common(void) {
15306 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15307 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15308 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15309 +
15310 +#ifdef CONFIG_PAX_KERNEXEC
15311 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15312 #endif
15313
15314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15315 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15316 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15317 +#ifdef CONFIG_X86_64
15318 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15319 +#endif
15320 +#endif
15321 +
15322 +#endif
15323 +
15324 + BLANK();
15325 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15326 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15327 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15328 +
15329 #ifdef CONFIG_XEN
15330 BLANK();
15331 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15332 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15333 index 1b4754f..fbb4227 100644
15334 --- a/arch/x86/kernel/asm-offsets_64.c
15335 +++ b/arch/x86/kernel/asm-offsets_64.c
15336 @@ -76,6 +76,7 @@ int main(void)
15337 BLANK();
15338 #undef ENTRY
15339
15340 + DEFINE(TSS_size, sizeof(struct tss_struct));
15341 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15342 BLANK();
15343
15344 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15345 index a0e067d..9c7db16 100644
15346 --- a/arch/x86/kernel/cpu/Makefile
15347 +++ b/arch/x86/kernel/cpu/Makefile
15348 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15349 CFLAGS_REMOVE_perf_event.o = -pg
15350 endif
15351
15352 -# Make sure load_percpu_segment has no stackprotector
15353 -nostackp := $(call cc-option, -fno-stack-protector)
15354 -CFLAGS_common.o := $(nostackp)
15355 -
15356 obj-y := intel_cacheinfo.o scattered.o topology.o
15357 obj-y += proc.o capflags.o powerflags.o common.o
15358 obj-y += vmware.o hypervisor.o mshyperv.o
15359 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15360 index 1b7d165..b9e2627 100644
15361 --- a/arch/x86/kernel/cpu/amd.c
15362 +++ b/arch/x86/kernel/cpu/amd.c
15363 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15364 unsigned int size)
15365 {
15366 /* AMD errata T13 (order #21922) */
15367 - if ((c->x86 == 6)) {
15368 + if (c->x86 == 6) {
15369 /* Duron Rev A0 */
15370 if (c->x86_model == 3 && c->x86_mask == 0)
15371 size = 64;
15372 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15373 index 7505f7b..d59dac0 100644
15374 --- a/arch/x86/kernel/cpu/common.c
15375 +++ b/arch/x86/kernel/cpu/common.c
15376 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15377
15378 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15379
15380 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15381 -#ifdef CONFIG_X86_64
15382 - /*
15383 - * We need valid kernel segments for data and code in long mode too
15384 - * IRET will check the segment types kkeil 2000/10/28
15385 - * Also sysret mandates a special GDT layout
15386 - *
15387 - * TLS descriptors are currently at a different place compared to i386.
15388 - * Hopefully nobody expects them at a fixed place (Wine?)
15389 - */
15390 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15391 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15392 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15393 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15394 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15395 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15396 -#else
15397 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15398 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15399 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15400 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15401 - /*
15402 - * Segments used for calling PnP BIOS have byte granularity.
15403 - * They code segments and data segments have fixed 64k limits,
15404 - * the transfer segment sizes are set at run time.
15405 - */
15406 - /* 32-bit code */
15407 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15408 - /* 16-bit code */
15409 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15410 - /* 16-bit data */
15411 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15412 - /* 16-bit data */
15413 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15414 - /* 16-bit data */
15415 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15416 - /*
15417 - * The APM segments have byte granularity and their bases
15418 - * are set at run time. All have 64k limits.
15419 - */
15420 - /* 32-bit code */
15421 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15422 - /* 16-bit code */
15423 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15424 - /* data */
15425 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15426 -
15427 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15428 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15429 - GDT_STACK_CANARY_INIT
15430 -#endif
15431 -} };
15432 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15433 -
15434 static int __init x86_xsave_setup(char *s)
15435 {
15436 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15437 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15438 {
15439 struct desc_ptr gdt_descr;
15440
15441 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15442 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15443 gdt_descr.size = GDT_SIZE - 1;
15444 load_gdt(&gdt_descr);
15445 /* Reload the per-cpu base */
15446 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15447 /* Filter out anything that depends on CPUID levels we don't have */
15448 filter_cpuid_features(c, true);
15449
15450 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15451 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15452 +#endif
15453 +
15454 /* If the model name is still unset, do table lookup. */
15455 if (!c->x86_model_id[0]) {
15456 const char *p;
15457 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15458 }
15459 __setup("clearcpuid=", setup_disablecpuid);
15460
15461 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15462 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15463 +
15464 #ifdef CONFIG_X86_64
15465 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15466 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15467 - (unsigned long) nmi_idt_table };
15468 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15469
15470 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15471 irq_stack_union) __aligned(PAGE_SIZE);
15472 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15473 EXPORT_PER_CPU_SYMBOL(current_task);
15474
15475 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15476 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15477 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15478 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15479
15480 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15481 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15482 {
15483 memset(regs, 0, sizeof(struct pt_regs));
15484 regs->fs = __KERNEL_PERCPU;
15485 - regs->gs = __KERNEL_STACK_CANARY;
15486 + savesegment(gs, regs->gs);
15487
15488 return regs;
15489 }
15490 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15491 int i;
15492
15493 cpu = stack_smp_processor_id();
15494 - t = &per_cpu(init_tss, cpu);
15495 + t = init_tss + cpu;
15496 oist = &per_cpu(orig_ist, cpu);
15497
15498 #ifdef CONFIG_NUMA
15499 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15500 switch_to_new_gdt(cpu);
15501 loadsegment(fs, 0);
15502
15503 - load_idt((const struct desc_ptr *)&idt_descr);
15504 + load_idt(&idt_descr);
15505
15506 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15507 syscall_init();
15508 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15509 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15510 barrier();
15511
15512 - x86_configure_nx();
15513 if (cpu != 0)
15514 enable_x2apic();
15515
15516 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15517 {
15518 int cpu = smp_processor_id();
15519 struct task_struct *curr = current;
15520 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15521 + struct tss_struct *t = init_tss + cpu;
15522 struct thread_struct *thread = &curr->thread;
15523
15524 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15525 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15526 index 198e019..867575e 100644
15527 --- a/arch/x86/kernel/cpu/intel.c
15528 +++ b/arch/x86/kernel/cpu/intel.c
15529 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15530 * Update the IDT descriptor and reload the IDT so that
15531 * it uses the read-only mapped virtual address.
15532 */
15533 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15534 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15535 load_idt(&idt_descr);
15536 }
15537 #endif
15538 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15539 index 93c5451..3887433 100644
15540 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15541 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15542 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15543 };
15544
15545 #ifdef CONFIG_AMD_NB
15546 +static struct attribute *default_attrs_amd_nb[] = {
15547 + &type.attr,
15548 + &level.attr,
15549 + &coherency_line_size.attr,
15550 + &physical_line_partition.attr,
15551 + &ways_of_associativity.attr,
15552 + &number_of_sets.attr,
15553 + &size.attr,
15554 + &shared_cpu_map.attr,
15555 + &shared_cpu_list.attr,
15556 + NULL,
15557 + NULL,
15558 + NULL,
15559 + NULL
15560 +};
15561 +
15562 static struct attribute ** __cpuinit amd_l3_attrs(void)
15563 {
15564 static struct attribute **attrs;
15565 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15566
15567 n = ARRAY_SIZE(default_attrs);
15568
15569 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15570 - n += 2;
15571 -
15572 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15573 - n += 1;
15574 -
15575 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15576 - if (attrs == NULL)
15577 - return attrs = default_attrs;
15578 -
15579 - for (n = 0; default_attrs[n]; n++)
15580 - attrs[n] = default_attrs[n];
15581 + attrs = default_attrs_amd_nb;
15582
15583 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15584 attrs[n++] = &cache_disable_0.attr;
15585 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15586 .default_attrs = default_attrs,
15587 };
15588
15589 +#ifdef CONFIG_AMD_NB
15590 +static struct kobj_type ktype_cache_amd_nb = {
15591 + .sysfs_ops = &sysfs_ops,
15592 + .default_attrs = default_attrs_amd_nb,
15593 +};
15594 +#endif
15595 +
15596 static struct kobj_type ktype_percpu_entry = {
15597 .sysfs_ops = &sysfs_ops,
15598 };
15599 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15600 return retval;
15601 }
15602
15603 +#ifdef CONFIG_AMD_NB
15604 + amd_l3_attrs();
15605 +#endif
15606 +
15607 for (i = 0; i < num_cache_leaves; i++) {
15608 + struct kobj_type *ktype;
15609 +
15610 this_object = INDEX_KOBJECT_PTR(cpu, i);
15611 this_object->cpu = cpu;
15612 this_object->index = i;
15613
15614 this_leaf = CPUID4_INFO_IDX(cpu, i);
15615
15616 - ktype_cache.default_attrs = default_attrs;
15617 + ktype = &ktype_cache;
15618 #ifdef CONFIG_AMD_NB
15619 if (this_leaf->base.nb)
15620 - ktype_cache.default_attrs = amd_l3_attrs();
15621 + ktype = &ktype_cache_amd_nb;
15622 #endif
15623 retval = kobject_init_and_add(&(this_object->kobj),
15624 - &ktype_cache,
15625 + ktype,
15626 per_cpu(ici_cache_kobject, cpu),
15627 "index%1lu", i);
15628 if (unlikely(retval)) {
15629 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15630 index 46cbf86..55c7292 100644
15631 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15632 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15633 @@ -45,6 +45,7 @@
15634 #include <asm/processor.h>
15635 #include <asm/mce.h>
15636 #include <asm/msr.h>
15637 +#include <asm/local.h>
15638
15639 #include "mce-internal.h"
15640
15641 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15642 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15643 m->cs, m->ip);
15644
15645 - if (m->cs == __KERNEL_CS)
15646 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15647 print_symbol("{%s}", m->ip);
15648 pr_cont("\n");
15649 }
15650 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15651
15652 #define PANIC_TIMEOUT 5 /* 5 seconds */
15653
15654 -static atomic_t mce_paniced;
15655 +static atomic_unchecked_t mce_paniced;
15656
15657 static int fake_panic;
15658 -static atomic_t mce_fake_paniced;
15659 +static atomic_unchecked_t mce_fake_paniced;
15660
15661 /* Panic in progress. Enable interrupts and wait for final IPI */
15662 static void wait_for_panic(void)
15663 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15664 /*
15665 * Make sure only one CPU runs in machine check panic
15666 */
15667 - if (atomic_inc_return(&mce_paniced) > 1)
15668 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15669 wait_for_panic();
15670 barrier();
15671
15672 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15673 console_verbose();
15674 } else {
15675 /* Don't log too much for fake panic */
15676 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15677 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15678 return;
15679 }
15680 /* First print corrected ones that are still unlogged */
15681 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15682 * might have been modified by someone else.
15683 */
15684 rmb();
15685 - if (atomic_read(&mce_paniced))
15686 + if (atomic_read_unchecked(&mce_paniced))
15687 wait_for_panic();
15688 if (!monarch_timeout)
15689 goto out;
15690 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15691 }
15692
15693 /* Call the installed machine check handler for this CPU setup. */
15694 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15695 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15696 unexpected_machine_check;
15697
15698 /*
15699 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15700 return;
15701 }
15702
15703 + pax_open_kernel();
15704 machine_check_vector = do_machine_check;
15705 + pax_close_kernel();
15706
15707 __mcheck_cpu_init_generic();
15708 __mcheck_cpu_init_vendor(c);
15709 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15710 */
15711
15712 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15713 -static int mce_chrdev_open_count; /* #times opened */
15714 +static local_t mce_chrdev_open_count; /* #times opened */
15715 static int mce_chrdev_open_exclu; /* already open exclusive? */
15716
15717 static int mce_chrdev_open(struct inode *inode, struct file *file)
15718 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15719 spin_lock(&mce_chrdev_state_lock);
15720
15721 if (mce_chrdev_open_exclu ||
15722 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15723 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15724 spin_unlock(&mce_chrdev_state_lock);
15725
15726 return -EBUSY;
15727 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15728
15729 if (file->f_flags & O_EXCL)
15730 mce_chrdev_open_exclu = 1;
15731 - mce_chrdev_open_count++;
15732 + local_inc(&mce_chrdev_open_count);
15733
15734 spin_unlock(&mce_chrdev_state_lock);
15735
15736 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15737 {
15738 spin_lock(&mce_chrdev_state_lock);
15739
15740 - mce_chrdev_open_count--;
15741 + local_dec(&mce_chrdev_open_count);
15742 mce_chrdev_open_exclu = 0;
15743
15744 spin_unlock(&mce_chrdev_state_lock);
15745 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15746 return NOTIFY_OK;
15747 }
15748
15749 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15750 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15751 .notifier_call = mce_cpu_callback,
15752 };
15753
15754 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15755 static void mce_reset(void)
15756 {
15757 cpu_missing = 0;
15758 - atomic_set(&mce_fake_paniced, 0);
15759 + atomic_set_unchecked(&mce_fake_paniced, 0);
15760 atomic_set(&mce_executing, 0);
15761 atomic_set(&mce_callin, 0);
15762 atomic_set(&global_nwo, 0);
15763 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15764 index 2d5454c..51987eb 100644
15765 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15766 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15767 @@ -11,6 +11,7 @@
15768 #include <asm/processor.h>
15769 #include <asm/mce.h>
15770 #include <asm/msr.h>
15771 +#include <asm/pgtable.h>
15772
15773 /* By default disabled */
15774 int mce_p5_enabled __read_mostly;
15775 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15776 if (!cpu_has(c, X86_FEATURE_MCE))
15777 return;
15778
15779 + pax_open_kernel();
15780 machine_check_vector = pentium_machine_check;
15781 + pax_close_kernel();
15782 /* Make sure the vector pointer is visible before we enable MCEs: */
15783 wmb();
15784
15785 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15786 index 2d7998f..17c9de1 100644
15787 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15788 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15789 @@ -10,6 +10,7 @@
15790 #include <asm/processor.h>
15791 #include <asm/mce.h>
15792 #include <asm/msr.h>
15793 +#include <asm/pgtable.h>
15794
15795 /* Machine check handler for WinChip C6: */
15796 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15797 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15798 {
15799 u32 lo, hi;
15800
15801 + pax_open_kernel();
15802 machine_check_vector = winchip_machine_check;
15803 + pax_close_kernel();
15804 /* Make sure the vector pointer is visible before we enable MCEs: */
15805 wmb();
15806
15807 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15808 index 6b96110..0da73eb 100644
15809 --- a/arch/x86/kernel/cpu/mtrr/main.c
15810 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15811 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15812 u64 size_or_mask, size_and_mask;
15813 static bool mtrr_aps_delayed_init;
15814
15815 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15816 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15817
15818 const struct mtrr_ops *mtrr_if;
15819
15820 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15821 index df5e41f..816c719 100644
15822 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15823 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15824 @@ -25,7 +25,7 @@ struct mtrr_ops {
15825 int (*validate_add_page)(unsigned long base, unsigned long size,
15826 unsigned int type);
15827 int (*have_wrcomb)(void);
15828 -};
15829 +} __do_const;
15830
15831 extern int generic_get_free_region(unsigned long base, unsigned long size,
15832 int replace_reg);
15833 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15834 index d18b2b8..d3b834c 100644
15835 --- a/arch/x86/kernel/cpu/perf_event.c
15836 +++ b/arch/x86/kernel/cpu/perf_event.c
15837 @@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15838 if (idx > GDT_ENTRIES)
15839 return 0;
15840
15841 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15842 + desc = get_cpu_gdt_table(smp_processor_id());
15843 }
15844
15845 return get_desc_base(desc + idx);
15846 @@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15847 break;
15848
15849 perf_callchain_store(entry, frame.return_address);
15850 - fp = frame.next_frame;
15851 + fp = (const void __force_user *)frame.next_frame;
15852 }
15853 }
15854
15855 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15856 index 324bb52..1a93d85 100644
15857 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15858 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15859 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15860 * v2 and above have a perf capabilities MSR
15861 */
15862 if (version > 1) {
15863 - u64 capabilities;
15864 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15865
15866 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15867 - x86_pmu.intel_cap.capabilities = capabilities;
15868 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15869 + x86_pmu.intel_cap.capabilities = capabilities;
15870 }
15871
15872 intel_ds_init();
15873 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15874 index 13ad899..f642b9a 100644
15875 --- a/arch/x86/kernel/crash.c
15876 +++ b/arch/x86/kernel/crash.c
15877 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15878 {
15879 #ifdef CONFIG_X86_32
15880 struct pt_regs fixed_regs;
15881 -#endif
15882
15883 -#ifdef CONFIG_X86_32
15884 - if (!user_mode_vm(regs)) {
15885 + if (!user_mode(regs)) {
15886 crash_fixup_ss_esp(&fixed_regs, regs);
15887 regs = &fixed_regs;
15888 }
15889 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15890 index 37250fe..bf2ec74 100644
15891 --- a/arch/x86/kernel/doublefault_32.c
15892 +++ b/arch/x86/kernel/doublefault_32.c
15893 @@ -11,7 +11,7 @@
15894
15895 #define DOUBLEFAULT_STACKSIZE (1024)
15896 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15897 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15898 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15899
15900 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15901
15902 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15903 unsigned long gdt, tss;
15904
15905 store_gdt(&gdt_desc);
15906 - gdt = gdt_desc.address;
15907 + gdt = (unsigned long)gdt_desc.address;
15908
15909 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15910
15911 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15912 /* 0x2 bit is always set */
15913 .flags = X86_EFLAGS_SF | 0x2,
15914 .sp = STACK_START,
15915 - .es = __USER_DS,
15916 + .es = __KERNEL_DS,
15917 .cs = __KERNEL_CS,
15918 .ss = __KERNEL_DS,
15919 - .ds = __USER_DS,
15920 + .ds = __KERNEL_DS,
15921 .fs = __KERNEL_PERCPU,
15922
15923 .__cr3 = __pa_nodebug(swapper_pg_dir),
15924 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15925 index ae42418b..787c16b 100644
15926 --- a/arch/x86/kernel/dumpstack.c
15927 +++ b/arch/x86/kernel/dumpstack.c
15928 @@ -2,6 +2,9 @@
15929 * Copyright (C) 1991, 1992 Linus Torvalds
15930 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15931 */
15932 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15933 +#define __INCLUDED_BY_HIDESYM 1
15934 +#endif
15935 #include <linux/kallsyms.h>
15936 #include <linux/kprobes.h>
15937 #include <linux/uaccess.h>
15938 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15939 static void
15940 print_ftrace_graph_addr(unsigned long addr, void *data,
15941 const struct stacktrace_ops *ops,
15942 - struct thread_info *tinfo, int *graph)
15943 + struct task_struct *task, int *graph)
15944 {
15945 - struct task_struct *task;
15946 unsigned long ret_addr;
15947 int index;
15948
15949 if (addr != (unsigned long)return_to_handler)
15950 return;
15951
15952 - task = tinfo->task;
15953 index = task->curr_ret_stack;
15954
15955 if (!task->ret_stack || index < *graph)
15956 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15957 static inline void
15958 print_ftrace_graph_addr(unsigned long addr, void *data,
15959 const struct stacktrace_ops *ops,
15960 - struct thread_info *tinfo, int *graph)
15961 + struct task_struct *task, int *graph)
15962 { }
15963 #endif
15964
15965 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15966 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15967 */
15968
15969 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15970 - void *p, unsigned int size, void *end)
15971 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15972 {
15973 - void *t = tinfo;
15974 if (end) {
15975 if (p < end && p >= (end-THREAD_SIZE))
15976 return 1;
15977 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15978 }
15979
15980 unsigned long
15981 -print_context_stack(struct thread_info *tinfo,
15982 +print_context_stack(struct task_struct *task, void *stack_start,
15983 unsigned long *stack, unsigned long bp,
15984 const struct stacktrace_ops *ops, void *data,
15985 unsigned long *end, int *graph)
15986 {
15987 struct stack_frame *frame = (struct stack_frame *)bp;
15988
15989 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15990 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15991 unsigned long addr;
15992
15993 addr = *stack;
15994 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15995 } else {
15996 ops->address(data, addr, 0);
15997 }
15998 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15999 + print_ftrace_graph_addr(addr, data, ops, task, graph);
16000 }
16001 stack++;
16002 }
16003 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
16004 EXPORT_SYMBOL_GPL(print_context_stack);
16005
16006 unsigned long
16007 -print_context_stack_bp(struct thread_info *tinfo,
16008 +print_context_stack_bp(struct task_struct *task, void *stack_start,
16009 unsigned long *stack, unsigned long bp,
16010 const struct stacktrace_ops *ops, void *data,
16011 unsigned long *end, int *graph)
16012 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
16013 struct stack_frame *frame = (struct stack_frame *)bp;
16014 unsigned long *ret_addr = &frame->return_address;
16015
16016 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
16017 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
16018 unsigned long addr = *ret_addr;
16019
16020 if (!__kernel_text_address(addr))
16021 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
16022 ops->address(data, addr, 1);
16023 frame = frame->next_frame;
16024 ret_addr = &frame->return_address;
16025 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
16026 + print_ftrace_graph_addr(addr, data, ops, task, graph);
16027 }
16028
16029 return (unsigned long)frame;
16030 @@ -189,7 +188,7 @@ void dump_stack(void)
16031
16032 bp = stack_frame(current, NULL);
16033 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
16034 - current->pid, current->comm, print_tainted(),
16035 + task_pid_nr(current), current->comm, print_tainted(),
16036 init_utsname()->release,
16037 (int)strcspn(init_utsname()->version, " "),
16038 init_utsname()->version);
16039 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
16040 }
16041 EXPORT_SYMBOL_GPL(oops_begin);
16042
16043 +extern void gr_handle_kernel_exploit(void);
16044 +
16045 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
16046 {
16047 if (regs && kexec_should_crash(current))
16048 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
16049 panic("Fatal exception in interrupt");
16050 if (panic_on_oops)
16051 panic("Fatal exception");
16052 - do_exit(signr);
16053 +
16054 + gr_handle_kernel_exploit();
16055 +
16056 + do_group_exit(signr);
16057 }
16058
16059 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
16060 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
16061 print_modules();
16062 show_regs(regs);
16063 #ifdef CONFIG_X86_32
16064 - if (user_mode_vm(regs)) {
16065 + if (user_mode(regs)) {
16066 sp = regs->sp;
16067 ss = regs->ss & 0xffff;
16068 } else {
16069 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
16070 unsigned long flags = oops_begin();
16071 int sig = SIGSEGV;
16072
16073 - if (!user_mode_vm(regs))
16074 + if (!user_mode(regs))
16075 report_bug(regs->ip, regs);
16076
16077 if (__die(str, regs, err))
16078 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
16079 index 1038a41..db2c12b 100644
16080 --- a/arch/x86/kernel/dumpstack_32.c
16081 +++ b/arch/x86/kernel/dumpstack_32.c
16082 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16083 bp = stack_frame(task, regs);
16084
16085 for (;;) {
16086 - struct thread_info *context;
16087 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16088
16089 - context = (struct thread_info *)
16090 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
16091 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
16092 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16093
16094 - stack = (unsigned long *)context->previous_esp;
16095 - if (!stack)
16096 + if (stack_start == task_stack_page(task))
16097 break;
16098 + stack = *(unsigned long **)stack_start;
16099 if (ops->stack(data, "IRQ") < 0)
16100 break;
16101 touch_nmi_watchdog();
16102 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
16103 {
16104 int i;
16105
16106 - __show_regs(regs, !user_mode_vm(regs));
16107 + __show_regs(regs, !user_mode(regs));
16108
16109 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
16110 TASK_COMM_LEN, current->comm, task_pid_nr(current),
16111 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
16112 * When in-kernel, we also print out the stack and code at the
16113 * time of the fault..
16114 */
16115 - if (!user_mode_vm(regs)) {
16116 + if (!user_mode(regs)) {
16117 unsigned int code_prologue = code_bytes * 43 / 64;
16118 unsigned int code_len = code_bytes;
16119 unsigned char c;
16120 u8 *ip;
16121 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
16122
16123 pr_emerg("Stack:\n");
16124 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
16125
16126 pr_emerg("Code:");
16127
16128 - ip = (u8 *)regs->ip - code_prologue;
16129 + ip = (u8 *)regs->ip - code_prologue + cs_base;
16130 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
16131 /* try starting at IP */
16132 - ip = (u8 *)regs->ip;
16133 + ip = (u8 *)regs->ip + cs_base;
16134 code_len = code_len - code_prologue + 1;
16135 }
16136 for (i = 0; i < code_len; i++, ip++) {
16137 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
16138 pr_cont(" Bad EIP value.");
16139 break;
16140 }
16141 - if (ip == (u8 *)regs->ip)
16142 + if (ip == (u8 *)regs->ip + cs_base)
16143 pr_cont(" <%02x>", c);
16144 else
16145 pr_cont(" %02x", c);
16146 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
16147 {
16148 unsigned short ud2;
16149
16150 + ip = ktla_ktva(ip);
16151 if (ip < PAGE_OFFSET)
16152 return 0;
16153 if (probe_kernel_address((unsigned short *)ip, ud2))
16154 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16155
16156 return ud2 == 0x0b0f;
16157 }
16158 +
16159 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16160 +void pax_check_alloca(unsigned long size)
16161 +{
16162 + unsigned long sp = (unsigned long)&sp, stack_left;
16163 +
16164 + /* all kernel stacks are of the same size */
16165 + stack_left = sp & (THREAD_SIZE - 1);
16166 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16167 +}
16168 +EXPORT_SYMBOL(pax_check_alloca);
16169 +#endif
16170 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16171 index b653675..51cc8c0 100644
16172 --- a/arch/x86/kernel/dumpstack_64.c
16173 +++ b/arch/x86/kernel/dumpstack_64.c
16174 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16175 unsigned long *irq_stack_end =
16176 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16177 unsigned used = 0;
16178 - struct thread_info *tinfo;
16179 int graph = 0;
16180 unsigned long dummy;
16181 + void *stack_start;
16182
16183 if (!task)
16184 task = current;
16185 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16186 * current stack address. If the stacks consist of nested
16187 * exceptions
16188 */
16189 - tinfo = task_thread_info(task);
16190 for (;;) {
16191 char *id;
16192 unsigned long *estack_end;
16193 +
16194 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16195 &used, &id);
16196
16197 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16198 if (ops->stack(data, id) < 0)
16199 break;
16200
16201 - bp = ops->walk_stack(tinfo, stack, bp, ops,
16202 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16203 data, estack_end, &graph);
16204 ops->stack(data, "<EOE>");
16205 /*
16206 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16207 * second-to-last pointer (index -2 to end) in the
16208 * exception stack:
16209 */
16210 + if ((u16)estack_end[-1] != __KERNEL_DS)
16211 + goto out;
16212 stack = (unsigned long *) estack_end[-2];
16213 continue;
16214 }
16215 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16216 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16217 if (ops->stack(data, "IRQ") < 0)
16218 break;
16219 - bp = ops->walk_stack(tinfo, stack, bp,
16220 + bp = ops->walk_stack(task, irq_stack, stack, bp,
16221 ops, data, irq_stack_end, &graph);
16222 /*
16223 * We link to the next stack (which would be
16224 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16225 /*
16226 * This handles the process stack:
16227 */
16228 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16229 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16230 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16231 +out:
16232 put_cpu();
16233 }
16234 EXPORT_SYMBOL(dump_trace);
16235 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16236 {
16237 int i;
16238 unsigned long sp;
16239 - const int cpu = smp_processor_id();
16240 + const int cpu = raw_smp_processor_id();
16241 struct task_struct *cur = current;
16242
16243 sp = regs->sp;
16244 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16245
16246 return ud2 == 0x0b0f;
16247 }
16248 +
16249 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16250 +void pax_check_alloca(unsigned long size)
16251 +{
16252 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16253 + unsigned cpu, used;
16254 + char *id;
16255 +
16256 + /* check the process stack first */
16257 + stack_start = (unsigned long)task_stack_page(current);
16258 + stack_end = stack_start + THREAD_SIZE;
16259 + if (likely(stack_start <= sp && sp < stack_end)) {
16260 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
16261 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16262 + return;
16263 + }
16264 +
16265 + cpu = get_cpu();
16266 +
16267 + /* check the irq stacks */
16268 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16269 + stack_start = stack_end - IRQ_STACK_SIZE;
16270 + if (stack_start <= sp && sp < stack_end) {
16271 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16272 + put_cpu();
16273 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16274 + return;
16275 + }
16276 +
16277 + /* check the exception stacks */
16278 + used = 0;
16279 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16280 + stack_start = stack_end - EXCEPTION_STKSZ;
16281 + if (stack_end && stack_start <= sp && sp < stack_end) {
16282 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16283 + put_cpu();
16284 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16285 + return;
16286 + }
16287 +
16288 + put_cpu();
16289 +
16290 + /* unknown stack */
16291 + BUG();
16292 +}
16293 +EXPORT_SYMBOL(pax_check_alloca);
16294 +#endif
16295 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16296 index 9b9f18b..9fcaa04 100644
16297 --- a/arch/x86/kernel/early_printk.c
16298 +++ b/arch/x86/kernel/early_printk.c
16299 @@ -7,6 +7,7 @@
16300 #include <linux/pci_regs.h>
16301 #include <linux/pci_ids.h>
16302 #include <linux/errno.h>
16303 +#include <linux/sched.h>
16304 #include <asm/io.h>
16305 #include <asm/processor.h>
16306 #include <asm/fcntl.h>
16307 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16308 index cf8639b..6c6a674 100644
16309 --- a/arch/x86/kernel/entry_32.S
16310 +++ b/arch/x86/kernel/entry_32.S
16311 @@ -177,13 +177,153 @@
16312 /*CFI_REL_OFFSET gs, PT_GS*/
16313 .endm
16314 .macro SET_KERNEL_GS reg
16315 +
16316 +#ifdef CONFIG_CC_STACKPROTECTOR
16317 movl $(__KERNEL_STACK_CANARY), \reg
16318 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16319 + movl $(__USER_DS), \reg
16320 +#else
16321 + xorl \reg, \reg
16322 +#endif
16323 +
16324 movl \reg, %gs
16325 .endm
16326
16327 #endif /* CONFIG_X86_32_LAZY_GS */
16328
16329 -.macro SAVE_ALL
16330 +.macro pax_enter_kernel
16331 +#ifdef CONFIG_PAX_KERNEXEC
16332 + call pax_enter_kernel
16333 +#endif
16334 +.endm
16335 +
16336 +.macro pax_exit_kernel
16337 +#ifdef CONFIG_PAX_KERNEXEC
16338 + call pax_exit_kernel
16339 +#endif
16340 +.endm
16341 +
16342 +#ifdef CONFIG_PAX_KERNEXEC
16343 +ENTRY(pax_enter_kernel)
16344 +#ifdef CONFIG_PARAVIRT
16345 + pushl %eax
16346 + pushl %ecx
16347 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16348 + mov %eax, %esi
16349 +#else
16350 + mov %cr0, %esi
16351 +#endif
16352 + bts $16, %esi
16353 + jnc 1f
16354 + mov %cs, %esi
16355 + cmp $__KERNEL_CS, %esi
16356 + jz 3f
16357 + ljmp $__KERNEL_CS, $3f
16358 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16359 +2:
16360 +#ifdef CONFIG_PARAVIRT
16361 + mov %esi, %eax
16362 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16363 +#else
16364 + mov %esi, %cr0
16365 +#endif
16366 +3:
16367 +#ifdef CONFIG_PARAVIRT
16368 + popl %ecx
16369 + popl %eax
16370 +#endif
16371 + ret
16372 +ENDPROC(pax_enter_kernel)
16373 +
16374 +ENTRY(pax_exit_kernel)
16375 +#ifdef CONFIG_PARAVIRT
16376 + pushl %eax
16377 + pushl %ecx
16378 +#endif
16379 + mov %cs, %esi
16380 + cmp $__KERNEXEC_KERNEL_CS, %esi
16381 + jnz 2f
16382 +#ifdef CONFIG_PARAVIRT
16383 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16384 + mov %eax, %esi
16385 +#else
16386 + mov %cr0, %esi
16387 +#endif
16388 + btr $16, %esi
16389 + ljmp $__KERNEL_CS, $1f
16390 +1:
16391 +#ifdef CONFIG_PARAVIRT
16392 + mov %esi, %eax
16393 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16394 +#else
16395 + mov %esi, %cr0
16396 +#endif
16397 +2:
16398 +#ifdef CONFIG_PARAVIRT
16399 + popl %ecx
16400 + popl %eax
16401 +#endif
16402 + ret
16403 +ENDPROC(pax_exit_kernel)
16404 +#endif
16405 +
16406 +.macro pax_erase_kstack
16407 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16408 + call pax_erase_kstack
16409 +#endif
16410 +.endm
16411 +
16412 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16413 +/*
16414 + * ebp: thread_info
16415 + */
16416 +ENTRY(pax_erase_kstack)
16417 + pushl %edi
16418 + pushl %ecx
16419 + pushl %eax
16420 +
16421 + mov TI_lowest_stack(%ebp), %edi
16422 + mov $-0xBEEF, %eax
16423 + std
16424 +
16425 +1: mov %edi, %ecx
16426 + and $THREAD_SIZE_asm - 1, %ecx
16427 + shr $2, %ecx
16428 + repne scasl
16429 + jecxz 2f
16430 +
16431 + cmp $2*16, %ecx
16432 + jc 2f
16433 +
16434 + mov $2*16, %ecx
16435 + repe scasl
16436 + jecxz 2f
16437 + jne 1b
16438 +
16439 +2: cld
16440 + mov %esp, %ecx
16441 + sub %edi, %ecx
16442 +
16443 + cmp $THREAD_SIZE_asm, %ecx
16444 + jb 3f
16445 + ud2
16446 +3:
16447 +
16448 + shr $2, %ecx
16449 + rep stosl
16450 +
16451 + mov TI_task_thread_sp0(%ebp), %edi
16452 + sub $128, %edi
16453 + mov %edi, TI_lowest_stack(%ebp)
16454 +
16455 + popl %eax
16456 + popl %ecx
16457 + popl %edi
16458 + ret
16459 +ENDPROC(pax_erase_kstack)
16460 +#endif
16461 +
16462 +.macro __SAVE_ALL _DS
16463 cld
16464 PUSH_GS
16465 pushl_cfi %fs
16466 @@ -206,7 +346,7 @@
16467 CFI_REL_OFFSET ecx, 0
16468 pushl_cfi %ebx
16469 CFI_REL_OFFSET ebx, 0
16470 - movl $(__USER_DS), %edx
16471 + movl $\_DS, %edx
16472 movl %edx, %ds
16473 movl %edx, %es
16474 movl $(__KERNEL_PERCPU), %edx
16475 @@ -214,6 +354,15 @@
16476 SET_KERNEL_GS %edx
16477 .endm
16478
16479 +.macro SAVE_ALL
16480 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16481 + __SAVE_ALL __KERNEL_DS
16482 + pax_enter_kernel
16483 +#else
16484 + __SAVE_ALL __USER_DS
16485 +#endif
16486 +.endm
16487 +
16488 .macro RESTORE_INT_REGS
16489 popl_cfi %ebx
16490 CFI_RESTORE ebx
16491 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16492 popfl_cfi
16493 jmp syscall_exit
16494 CFI_ENDPROC
16495 -END(ret_from_fork)
16496 +ENDPROC(ret_from_fork)
16497
16498 ENTRY(ret_from_kernel_thread)
16499 CFI_STARTPROC
16500 @@ -344,7 +493,15 @@ ret_from_intr:
16501 andl $SEGMENT_RPL_MASK, %eax
16502 #endif
16503 cmpl $USER_RPL, %eax
16504 +
16505 +#ifdef CONFIG_PAX_KERNEXEC
16506 + jae resume_userspace
16507 +
16508 + pax_exit_kernel
16509 + jmp resume_kernel
16510 +#else
16511 jb resume_kernel # not returning to v8086 or userspace
16512 +#endif
16513
16514 ENTRY(resume_userspace)
16515 LOCKDEP_SYS_EXIT
16516 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16517 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16518 # int/exception return?
16519 jne work_pending
16520 - jmp restore_all
16521 -END(ret_from_exception)
16522 + jmp restore_all_pax
16523 +ENDPROC(ret_from_exception)
16524
16525 #ifdef CONFIG_PREEMPT
16526 ENTRY(resume_kernel)
16527 @@ -372,7 +529,7 @@ need_resched:
16528 jz restore_all
16529 call preempt_schedule_irq
16530 jmp need_resched
16531 -END(resume_kernel)
16532 +ENDPROC(resume_kernel)
16533 #endif
16534 CFI_ENDPROC
16535 /*
16536 @@ -406,30 +563,45 @@ sysenter_past_esp:
16537 /*CFI_REL_OFFSET cs, 0*/
16538 /*
16539 * Push current_thread_info()->sysenter_return to the stack.
16540 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16541 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16542 */
16543 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16544 + pushl_cfi $0
16545 CFI_REL_OFFSET eip, 0
16546
16547 pushl_cfi %eax
16548 SAVE_ALL
16549 + GET_THREAD_INFO(%ebp)
16550 + movl TI_sysenter_return(%ebp),%ebp
16551 + movl %ebp,PT_EIP(%esp)
16552 ENABLE_INTERRUPTS(CLBR_NONE)
16553
16554 /*
16555 * Load the potential sixth argument from user stack.
16556 * Careful about security.
16557 */
16558 + movl PT_OLDESP(%esp),%ebp
16559 +
16560 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16561 + mov PT_OLDSS(%esp),%ds
16562 +1: movl %ds:(%ebp),%ebp
16563 + push %ss
16564 + pop %ds
16565 +#else
16566 cmpl $__PAGE_OFFSET-3,%ebp
16567 jae syscall_fault
16568 ASM_STAC
16569 1: movl (%ebp),%ebp
16570 ASM_CLAC
16571 +#endif
16572 +
16573 movl %ebp,PT_EBP(%esp)
16574 _ASM_EXTABLE(1b,syscall_fault)
16575
16576 GET_THREAD_INFO(%ebp)
16577
16578 +#ifdef CONFIG_PAX_RANDKSTACK
16579 + pax_erase_kstack
16580 +#endif
16581 +
16582 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16583 jnz sysenter_audit
16584 sysenter_do_call:
16585 @@ -444,12 +616,24 @@ sysenter_do_call:
16586 testl $_TIF_ALLWORK_MASK, %ecx
16587 jne sysexit_audit
16588 sysenter_exit:
16589 +
16590 +#ifdef CONFIG_PAX_RANDKSTACK
16591 + pushl_cfi %eax
16592 + movl %esp, %eax
16593 + call pax_randomize_kstack
16594 + popl_cfi %eax
16595 +#endif
16596 +
16597 + pax_erase_kstack
16598 +
16599 /* if something modifies registers it must also disable sysexit */
16600 movl PT_EIP(%esp), %edx
16601 movl PT_OLDESP(%esp), %ecx
16602 xorl %ebp,%ebp
16603 TRACE_IRQS_ON
16604 1: mov PT_FS(%esp), %fs
16605 +2: mov PT_DS(%esp), %ds
16606 +3: mov PT_ES(%esp), %es
16607 PTGS_TO_GS
16608 ENABLE_INTERRUPTS_SYSEXIT
16609
16610 @@ -466,6 +650,9 @@ sysenter_audit:
16611 movl %eax,%edx /* 2nd arg: syscall number */
16612 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16613 call __audit_syscall_entry
16614 +
16615 + pax_erase_kstack
16616 +
16617 pushl_cfi %ebx
16618 movl PT_EAX(%esp),%eax /* reload syscall number */
16619 jmp sysenter_do_call
16620 @@ -491,10 +678,16 @@ sysexit_audit:
16621
16622 CFI_ENDPROC
16623 .pushsection .fixup,"ax"
16624 -2: movl $0,PT_FS(%esp)
16625 +4: movl $0,PT_FS(%esp)
16626 + jmp 1b
16627 +5: movl $0,PT_DS(%esp)
16628 + jmp 1b
16629 +6: movl $0,PT_ES(%esp)
16630 jmp 1b
16631 .popsection
16632 - _ASM_EXTABLE(1b,2b)
16633 + _ASM_EXTABLE(1b,4b)
16634 + _ASM_EXTABLE(2b,5b)
16635 + _ASM_EXTABLE(3b,6b)
16636 PTGS_TO_GS_EX
16637 ENDPROC(ia32_sysenter_target)
16638
16639 @@ -509,6 +702,11 @@ ENTRY(system_call)
16640 pushl_cfi %eax # save orig_eax
16641 SAVE_ALL
16642 GET_THREAD_INFO(%ebp)
16643 +
16644 +#ifdef CONFIG_PAX_RANDKSTACK
16645 + pax_erase_kstack
16646 +#endif
16647 +
16648 # system call tracing in operation / emulation
16649 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16650 jnz syscall_trace_entry
16651 @@ -527,6 +725,15 @@ syscall_exit:
16652 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16653 jne syscall_exit_work
16654
16655 +restore_all_pax:
16656 +
16657 +#ifdef CONFIG_PAX_RANDKSTACK
16658 + movl %esp, %eax
16659 + call pax_randomize_kstack
16660 +#endif
16661 +
16662 + pax_erase_kstack
16663 +
16664 restore_all:
16665 TRACE_IRQS_IRET
16666 restore_all_notrace:
16667 @@ -583,14 +790,34 @@ ldt_ss:
16668 * compensating for the offset by changing to the ESPFIX segment with
16669 * a base address that matches for the difference.
16670 */
16671 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16672 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16673 mov %esp, %edx /* load kernel esp */
16674 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16675 mov %dx, %ax /* eax: new kernel esp */
16676 sub %eax, %edx /* offset (low word is 0) */
16677 +#ifdef CONFIG_SMP
16678 + movl PER_CPU_VAR(cpu_number), %ebx
16679 + shll $PAGE_SHIFT_asm, %ebx
16680 + addl $cpu_gdt_table, %ebx
16681 +#else
16682 + movl $cpu_gdt_table, %ebx
16683 +#endif
16684 shr $16, %edx
16685 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16686 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16687 +
16688 +#ifdef CONFIG_PAX_KERNEXEC
16689 + mov %cr0, %esi
16690 + btr $16, %esi
16691 + mov %esi, %cr0
16692 +#endif
16693 +
16694 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16695 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16696 +
16697 +#ifdef CONFIG_PAX_KERNEXEC
16698 + bts $16, %esi
16699 + mov %esi, %cr0
16700 +#endif
16701 +
16702 pushl_cfi $__ESPFIX_SS
16703 pushl_cfi %eax /* new kernel esp */
16704 /* Disable interrupts, but do not irqtrace this section: we
16705 @@ -619,20 +846,18 @@ work_resched:
16706 movl TI_flags(%ebp), %ecx
16707 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16708 # than syscall tracing?
16709 - jz restore_all
16710 + jz restore_all_pax
16711 testb $_TIF_NEED_RESCHED, %cl
16712 jnz work_resched
16713
16714 work_notifysig: # deal with pending signals and
16715 # notify-resume requests
16716 + movl %esp, %eax
16717 #ifdef CONFIG_VM86
16718 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16719 - movl %esp, %eax
16720 jne work_notifysig_v86 # returning to kernel-space or
16721 # vm86-space
16722 1:
16723 -#else
16724 - movl %esp, %eax
16725 #endif
16726 TRACE_IRQS_ON
16727 ENABLE_INTERRUPTS(CLBR_NONE)
16728 @@ -653,7 +878,7 @@ work_notifysig_v86:
16729 movl %eax, %esp
16730 jmp 1b
16731 #endif
16732 -END(work_pending)
16733 +ENDPROC(work_pending)
16734
16735 # perform syscall exit tracing
16736 ALIGN
16737 @@ -661,11 +886,14 @@ syscall_trace_entry:
16738 movl $-ENOSYS,PT_EAX(%esp)
16739 movl %esp, %eax
16740 call syscall_trace_enter
16741 +
16742 + pax_erase_kstack
16743 +
16744 /* What it returned is what we'll actually use. */
16745 cmpl $(NR_syscalls), %eax
16746 jnae syscall_call
16747 jmp syscall_exit
16748 -END(syscall_trace_entry)
16749 +ENDPROC(syscall_trace_entry)
16750
16751 # perform syscall exit tracing
16752 ALIGN
16753 @@ -678,21 +906,25 @@ syscall_exit_work:
16754 movl %esp, %eax
16755 call syscall_trace_leave
16756 jmp resume_userspace
16757 -END(syscall_exit_work)
16758 +ENDPROC(syscall_exit_work)
16759 CFI_ENDPROC
16760
16761 RING0_INT_FRAME # can't unwind into user space anyway
16762 syscall_fault:
16763 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16764 + push %ss
16765 + pop %ds
16766 +#endif
16767 ASM_CLAC
16768 GET_THREAD_INFO(%ebp)
16769 movl $-EFAULT,PT_EAX(%esp)
16770 jmp resume_userspace
16771 -END(syscall_fault)
16772 +ENDPROC(syscall_fault)
16773
16774 syscall_badsys:
16775 movl $-ENOSYS,PT_EAX(%esp)
16776 jmp resume_userspace
16777 -END(syscall_badsys)
16778 +ENDPROC(syscall_badsys)
16779 CFI_ENDPROC
16780 /*
16781 * End of kprobes section
16782 @@ -772,8 +1004,15 @@ ENDPROC(ptregs_clone)
16783 * normal stack and adjusts ESP with the matching offset.
16784 */
16785 /* fixup the stack */
16786 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16787 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16788 +#ifdef CONFIG_SMP
16789 + movl PER_CPU_VAR(cpu_number), %ebx
16790 + shll $PAGE_SHIFT_asm, %ebx
16791 + addl $cpu_gdt_table, %ebx
16792 +#else
16793 + movl $cpu_gdt_table, %ebx
16794 +#endif
16795 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16796 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16797 shl $16, %eax
16798 addl %esp, %eax /* the adjusted stack pointer */
16799 pushl_cfi $__KERNEL_DS
16800 @@ -826,7 +1065,7 @@ vector=vector+1
16801 .endr
16802 2: jmp common_interrupt
16803 .endr
16804 -END(irq_entries_start)
16805 +ENDPROC(irq_entries_start)
16806
16807 .previous
16808 END(interrupt)
16809 @@ -877,7 +1116,7 @@ ENTRY(coprocessor_error)
16810 pushl_cfi $do_coprocessor_error
16811 jmp error_code
16812 CFI_ENDPROC
16813 -END(coprocessor_error)
16814 +ENDPROC(coprocessor_error)
16815
16816 ENTRY(simd_coprocessor_error)
16817 RING0_INT_FRAME
16818 @@ -899,7 +1138,7 @@ ENTRY(simd_coprocessor_error)
16819 #endif
16820 jmp error_code
16821 CFI_ENDPROC
16822 -END(simd_coprocessor_error)
16823 +ENDPROC(simd_coprocessor_error)
16824
16825 ENTRY(device_not_available)
16826 RING0_INT_FRAME
16827 @@ -908,18 +1147,18 @@ ENTRY(device_not_available)
16828 pushl_cfi $do_device_not_available
16829 jmp error_code
16830 CFI_ENDPROC
16831 -END(device_not_available)
16832 +ENDPROC(device_not_available)
16833
16834 #ifdef CONFIG_PARAVIRT
16835 ENTRY(native_iret)
16836 iret
16837 _ASM_EXTABLE(native_iret, iret_exc)
16838 -END(native_iret)
16839 +ENDPROC(native_iret)
16840
16841 ENTRY(native_irq_enable_sysexit)
16842 sti
16843 sysexit
16844 -END(native_irq_enable_sysexit)
16845 +ENDPROC(native_irq_enable_sysexit)
16846 #endif
16847
16848 ENTRY(overflow)
16849 @@ -929,7 +1168,7 @@ ENTRY(overflow)
16850 pushl_cfi $do_overflow
16851 jmp error_code
16852 CFI_ENDPROC
16853 -END(overflow)
16854 +ENDPROC(overflow)
16855
16856 ENTRY(bounds)
16857 RING0_INT_FRAME
16858 @@ -938,7 +1177,7 @@ ENTRY(bounds)
16859 pushl_cfi $do_bounds
16860 jmp error_code
16861 CFI_ENDPROC
16862 -END(bounds)
16863 +ENDPROC(bounds)
16864
16865 ENTRY(invalid_op)
16866 RING0_INT_FRAME
16867 @@ -947,7 +1186,7 @@ ENTRY(invalid_op)
16868 pushl_cfi $do_invalid_op
16869 jmp error_code
16870 CFI_ENDPROC
16871 -END(invalid_op)
16872 +ENDPROC(invalid_op)
16873
16874 ENTRY(coprocessor_segment_overrun)
16875 RING0_INT_FRAME
16876 @@ -956,7 +1195,7 @@ ENTRY(coprocessor_segment_overrun)
16877 pushl_cfi $do_coprocessor_segment_overrun
16878 jmp error_code
16879 CFI_ENDPROC
16880 -END(coprocessor_segment_overrun)
16881 +ENDPROC(coprocessor_segment_overrun)
16882
16883 ENTRY(invalid_TSS)
16884 RING0_EC_FRAME
16885 @@ -964,7 +1203,7 @@ ENTRY(invalid_TSS)
16886 pushl_cfi $do_invalid_TSS
16887 jmp error_code
16888 CFI_ENDPROC
16889 -END(invalid_TSS)
16890 +ENDPROC(invalid_TSS)
16891
16892 ENTRY(segment_not_present)
16893 RING0_EC_FRAME
16894 @@ -972,7 +1211,7 @@ ENTRY(segment_not_present)
16895 pushl_cfi $do_segment_not_present
16896 jmp error_code
16897 CFI_ENDPROC
16898 -END(segment_not_present)
16899 +ENDPROC(segment_not_present)
16900
16901 ENTRY(stack_segment)
16902 RING0_EC_FRAME
16903 @@ -980,7 +1219,7 @@ ENTRY(stack_segment)
16904 pushl_cfi $do_stack_segment
16905 jmp error_code
16906 CFI_ENDPROC
16907 -END(stack_segment)
16908 +ENDPROC(stack_segment)
16909
16910 ENTRY(alignment_check)
16911 RING0_EC_FRAME
16912 @@ -988,7 +1227,7 @@ ENTRY(alignment_check)
16913 pushl_cfi $do_alignment_check
16914 jmp error_code
16915 CFI_ENDPROC
16916 -END(alignment_check)
16917 +ENDPROC(alignment_check)
16918
16919 ENTRY(divide_error)
16920 RING0_INT_FRAME
16921 @@ -997,7 +1236,7 @@ ENTRY(divide_error)
16922 pushl_cfi $do_divide_error
16923 jmp error_code
16924 CFI_ENDPROC
16925 -END(divide_error)
16926 +ENDPROC(divide_error)
16927
16928 #ifdef CONFIG_X86_MCE
16929 ENTRY(machine_check)
16930 @@ -1007,7 +1246,7 @@ ENTRY(machine_check)
16931 pushl_cfi machine_check_vector
16932 jmp error_code
16933 CFI_ENDPROC
16934 -END(machine_check)
16935 +ENDPROC(machine_check)
16936 #endif
16937
16938 ENTRY(spurious_interrupt_bug)
16939 @@ -1017,7 +1256,7 @@ ENTRY(spurious_interrupt_bug)
16940 pushl_cfi $do_spurious_interrupt_bug
16941 jmp error_code
16942 CFI_ENDPROC
16943 -END(spurious_interrupt_bug)
16944 +ENDPROC(spurious_interrupt_bug)
16945 /*
16946 * End of kprobes section
16947 */
16948 @@ -1120,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16949
16950 ENTRY(mcount)
16951 ret
16952 -END(mcount)
16953 +ENDPROC(mcount)
16954
16955 ENTRY(ftrace_caller)
16956 cmpl $0, function_trace_stop
16957 @@ -1153,7 +1392,7 @@ ftrace_graph_call:
16958 .globl ftrace_stub
16959 ftrace_stub:
16960 ret
16961 -END(ftrace_caller)
16962 +ENDPROC(ftrace_caller)
16963
16964 ENTRY(ftrace_regs_caller)
16965 pushf /* push flags before compare (in cs location) */
16966 @@ -1254,7 +1493,7 @@ trace:
16967 popl %ecx
16968 popl %eax
16969 jmp ftrace_stub
16970 -END(mcount)
16971 +ENDPROC(mcount)
16972 #endif /* CONFIG_DYNAMIC_FTRACE */
16973 #endif /* CONFIG_FUNCTION_TRACER */
16974
16975 @@ -1272,7 +1511,7 @@ ENTRY(ftrace_graph_caller)
16976 popl %ecx
16977 popl %eax
16978 ret
16979 -END(ftrace_graph_caller)
16980 +ENDPROC(ftrace_graph_caller)
16981
16982 .globl return_to_handler
16983 return_to_handler:
16984 @@ -1328,15 +1567,18 @@ error_code:
16985 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16986 REG_TO_PTGS %ecx
16987 SET_KERNEL_GS %ecx
16988 - movl $(__USER_DS), %ecx
16989 + movl $(__KERNEL_DS), %ecx
16990 movl %ecx, %ds
16991 movl %ecx, %es
16992 +
16993 + pax_enter_kernel
16994 +
16995 TRACE_IRQS_OFF
16996 movl %esp,%eax # pt_regs pointer
16997 call *%edi
16998 jmp ret_from_exception
16999 CFI_ENDPROC
17000 -END(page_fault)
17001 +ENDPROC(page_fault)
17002
17003 /*
17004 * Debug traps and NMI can happen at the one SYSENTER instruction
17005 @@ -1379,7 +1621,7 @@ debug_stack_correct:
17006 call do_debug
17007 jmp ret_from_exception
17008 CFI_ENDPROC
17009 -END(debug)
17010 +ENDPROC(debug)
17011
17012 /*
17013 * NMI is doubly nasty. It can happen _while_ we're handling
17014 @@ -1417,6 +1659,9 @@ nmi_stack_correct:
17015 xorl %edx,%edx # zero error code
17016 movl %esp,%eax # pt_regs pointer
17017 call do_nmi
17018 +
17019 + pax_exit_kernel
17020 +
17021 jmp restore_all_notrace
17022 CFI_ENDPROC
17023
17024 @@ -1453,12 +1698,15 @@ nmi_espfix_stack:
17025 FIXUP_ESPFIX_STACK # %eax == %esp
17026 xorl %edx,%edx # zero error code
17027 call do_nmi
17028 +
17029 + pax_exit_kernel
17030 +
17031 RESTORE_REGS
17032 lss 12+4(%esp), %esp # back to espfix stack
17033 CFI_ADJUST_CFA_OFFSET -24
17034 jmp irq_return
17035 CFI_ENDPROC
17036 -END(nmi)
17037 +ENDPROC(nmi)
17038
17039 ENTRY(int3)
17040 RING0_INT_FRAME
17041 @@ -1471,14 +1719,14 @@ ENTRY(int3)
17042 call do_int3
17043 jmp ret_from_exception
17044 CFI_ENDPROC
17045 -END(int3)
17046 +ENDPROC(int3)
17047
17048 ENTRY(general_protection)
17049 RING0_EC_FRAME
17050 pushl_cfi $do_general_protection
17051 jmp error_code
17052 CFI_ENDPROC
17053 -END(general_protection)
17054 +ENDPROC(general_protection)
17055
17056 #ifdef CONFIG_KVM_GUEST
17057 ENTRY(async_page_fault)
17058 @@ -1487,7 +1735,7 @@ ENTRY(async_page_fault)
17059 pushl_cfi $do_async_page_fault
17060 jmp error_code
17061 CFI_ENDPROC
17062 -END(async_page_fault)
17063 +ENDPROC(async_page_fault)
17064 #endif
17065
17066 /*
17067 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
17068 index 1328fe4..cb03298 100644
17069 --- a/arch/x86/kernel/entry_64.S
17070 +++ b/arch/x86/kernel/entry_64.S
17071 @@ -59,6 +59,8 @@
17072 #include <asm/rcu.h>
17073 #include <asm/smap.h>
17074 #include <linux/err.h>
17075 +#include <asm/pgtable.h>
17076 +#include <asm/alternative-asm.h>
17077
17078 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
17079 #include <linux/elf-em.h>
17080 @@ -80,8 +82,9 @@
17081 #ifdef CONFIG_DYNAMIC_FTRACE
17082
17083 ENTRY(function_hook)
17084 + pax_force_retaddr
17085 retq
17086 -END(function_hook)
17087 +ENDPROC(function_hook)
17088
17089 /* skip is set if stack has been adjusted */
17090 .macro ftrace_caller_setup skip=0
17091 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
17092 #endif
17093
17094 GLOBAL(ftrace_stub)
17095 + pax_force_retaddr
17096 retq
17097 -END(ftrace_caller)
17098 +ENDPROC(ftrace_caller)
17099
17100 ENTRY(ftrace_regs_caller)
17101 /* Save the current flags before compare (in SS location)*/
17102 @@ -191,7 +195,7 @@ ftrace_restore_flags:
17103 popfq
17104 jmp ftrace_stub
17105
17106 -END(ftrace_regs_caller)
17107 +ENDPROC(ftrace_regs_caller)
17108
17109
17110 #else /* ! CONFIG_DYNAMIC_FTRACE */
17111 @@ -212,6 +216,7 @@ ENTRY(function_hook)
17112 #endif
17113
17114 GLOBAL(ftrace_stub)
17115 + pax_force_retaddr
17116 retq
17117
17118 trace:
17119 @@ -225,12 +230,13 @@ trace:
17120 #endif
17121 subq $MCOUNT_INSN_SIZE, %rdi
17122
17123 + pax_force_fptr ftrace_trace_function
17124 call *ftrace_trace_function
17125
17126 MCOUNT_RESTORE_FRAME
17127
17128 jmp ftrace_stub
17129 -END(function_hook)
17130 +ENDPROC(function_hook)
17131 #endif /* CONFIG_DYNAMIC_FTRACE */
17132 #endif /* CONFIG_FUNCTION_TRACER */
17133
17134 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17135
17136 MCOUNT_RESTORE_FRAME
17137
17138 + pax_force_retaddr
17139 retq
17140 -END(ftrace_graph_caller)
17141 +ENDPROC(ftrace_graph_caller)
17142
17143 GLOBAL(return_to_handler)
17144 subq $24, %rsp
17145 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17146 movq 8(%rsp), %rdx
17147 movq (%rsp), %rax
17148 addq $24, %rsp
17149 + pax_force_fptr %rdi
17150 jmp *%rdi
17151 +ENDPROC(return_to_handler)
17152 #endif
17153
17154
17155 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17156 ENDPROC(native_usergs_sysret64)
17157 #endif /* CONFIG_PARAVIRT */
17158
17159 + .macro ljmpq sel, off
17160 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17161 + .byte 0x48; ljmp *1234f(%rip)
17162 + .pushsection .rodata
17163 + .align 16
17164 + 1234: .quad \off; .word \sel
17165 + .popsection
17166 +#else
17167 + pushq $\sel
17168 + pushq $\off
17169 + lretq
17170 +#endif
17171 + .endm
17172 +
17173 + .macro pax_enter_kernel
17174 + pax_set_fptr_mask
17175 +#ifdef CONFIG_PAX_KERNEXEC
17176 + call pax_enter_kernel
17177 +#endif
17178 + .endm
17179 +
17180 + .macro pax_exit_kernel
17181 +#ifdef CONFIG_PAX_KERNEXEC
17182 + call pax_exit_kernel
17183 +#endif
17184 + .endm
17185 +
17186 +#ifdef CONFIG_PAX_KERNEXEC
17187 +ENTRY(pax_enter_kernel)
17188 + pushq %rdi
17189 +
17190 +#ifdef CONFIG_PARAVIRT
17191 + PV_SAVE_REGS(CLBR_RDI)
17192 +#endif
17193 +
17194 + GET_CR0_INTO_RDI
17195 + bts $16,%rdi
17196 + jnc 3f
17197 + mov %cs,%edi
17198 + cmp $__KERNEL_CS,%edi
17199 + jnz 2f
17200 +1:
17201 +
17202 +#ifdef CONFIG_PARAVIRT
17203 + PV_RESTORE_REGS(CLBR_RDI)
17204 +#endif
17205 +
17206 + popq %rdi
17207 + pax_force_retaddr
17208 + retq
17209 +
17210 +2: ljmpq __KERNEL_CS,1f
17211 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
17212 +4: SET_RDI_INTO_CR0
17213 + jmp 1b
17214 +ENDPROC(pax_enter_kernel)
17215 +
17216 +ENTRY(pax_exit_kernel)
17217 + pushq %rdi
17218 +
17219 +#ifdef CONFIG_PARAVIRT
17220 + PV_SAVE_REGS(CLBR_RDI)
17221 +#endif
17222 +
17223 + mov %cs,%rdi
17224 + cmp $__KERNEXEC_KERNEL_CS,%edi
17225 + jz 2f
17226 +1:
17227 +
17228 +#ifdef CONFIG_PARAVIRT
17229 + PV_RESTORE_REGS(CLBR_RDI);
17230 +#endif
17231 +
17232 + popq %rdi
17233 + pax_force_retaddr
17234 + retq
17235 +
17236 +2: GET_CR0_INTO_RDI
17237 + btr $16,%rdi
17238 + ljmpq __KERNEL_CS,3f
17239 +3: SET_RDI_INTO_CR0
17240 + jmp 1b
17241 +ENDPROC(pax_exit_kernel)
17242 +#endif
17243 +
17244 + .macro pax_enter_kernel_user
17245 + pax_set_fptr_mask
17246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17247 + call pax_enter_kernel_user
17248 +#endif
17249 + .endm
17250 +
17251 + .macro pax_exit_kernel_user
17252 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17253 + call pax_exit_kernel_user
17254 +#endif
17255 +#ifdef CONFIG_PAX_RANDKSTACK
17256 + pushq %rax
17257 + call pax_randomize_kstack
17258 + popq %rax
17259 +#endif
17260 + .endm
17261 +
17262 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17263 +ENTRY(pax_enter_kernel_user)
17264 + pushq %rdi
17265 + pushq %rbx
17266 +
17267 +#ifdef CONFIG_PARAVIRT
17268 + PV_SAVE_REGS(CLBR_RDI)
17269 +#endif
17270 +
17271 + GET_CR3_INTO_RDI
17272 + mov %rdi,%rbx
17273 + add $__START_KERNEL_map,%rbx
17274 + sub phys_base(%rip),%rbx
17275 +
17276 +#ifdef CONFIG_PARAVIRT
17277 + pushq %rdi
17278 + cmpl $0, pv_info+PARAVIRT_enabled
17279 + jz 1f
17280 + i = 0
17281 + .rept USER_PGD_PTRS
17282 + mov i*8(%rbx),%rsi
17283 + mov $0,%sil
17284 + lea i*8(%rbx),%rdi
17285 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17286 + i = i + 1
17287 + .endr
17288 + jmp 2f
17289 +1:
17290 +#endif
17291 +
17292 + i = 0
17293 + .rept USER_PGD_PTRS
17294 + movb $0,i*8(%rbx)
17295 + i = i + 1
17296 + .endr
17297 +
17298 +#ifdef CONFIG_PARAVIRT
17299 +2: popq %rdi
17300 +#endif
17301 + SET_RDI_INTO_CR3
17302 +
17303 +#ifdef CONFIG_PAX_KERNEXEC
17304 + GET_CR0_INTO_RDI
17305 + bts $16,%rdi
17306 + SET_RDI_INTO_CR0
17307 +#endif
17308 +
17309 +#ifdef CONFIG_PARAVIRT
17310 + PV_RESTORE_REGS(CLBR_RDI)
17311 +#endif
17312 +
17313 + popq %rbx
17314 + popq %rdi
17315 + pax_force_retaddr
17316 + retq
17317 +ENDPROC(pax_enter_kernel_user)
17318 +
17319 +ENTRY(pax_exit_kernel_user)
17320 + push %rdi
17321 +
17322 +#ifdef CONFIG_PARAVIRT
17323 + pushq %rbx
17324 + PV_SAVE_REGS(CLBR_RDI)
17325 +#endif
17326 +
17327 +#ifdef CONFIG_PAX_KERNEXEC
17328 + GET_CR0_INTO_RDI
17329 + btr $16,%rdi
17330 + SET_RDI_INTO_CR0
17331 +#endif
17332 +
17333 + GET_CR3_INTO_RDI
17334 + add $__START_KERNEL_map,%rdi
17335 + sub phys_base(%rip),%rdi
17336 +
17337 +#ifdef CONFIG_PARAVIRT
17338 + cmpl $0, pv_info+PARAVIRT_enabled
17339 + jz 1f
17340 + mov %rdi,%rbx
17341 + i = 0
17342 + .rept USER_PGD_PTRS
17343 + mov i*8(%rbx),%rsi
17344 + mov $0x67,%sil
17345 + lea i*8(%rbx),%rdi
17346 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17347 + i = i + 1
17348 + .endr
17349 + jmp 2f
17350 +1:
17351 +#endif
17352 +
17353 + i = 0
17354 + .rept USER_PGD_PTRS
17355 + movb $0x67,i*8(%rdi)
17356 + i = i + 1
17357 + .endr
17358 +
17359 +#ifdef CONFIG_PARAVIRT
17360 +2: PV_RESTORE_REGS(CLBR_RDI)
17361 + popq %rbx
17362 +#endif
17363 +
17364 + popq %rdi
17365 + pax_force_retaddr
17366 + retq
17367 +ENDPROC(pax_exit_kernel_user)
17368 +#endif
17369 +
17370 +.macro pax_erase_kstack
17371 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17372 + call pax_erase_kstack
17373 +#endif
17374 +.endm
17375 +
17376 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17377 +ENTRY(pax_erase_kstack)
17378 + pushq %rdi
17379 + pushq %rcx
17380 + pushq %rax
17381 + pushq %r11
17382 +
17383 + GET_THREAD_INFO(%r11)
17384 + mov TI_lowest_stack(%r11), %rdi
17385 + mov $-0xBEEF, %rax
17386 + std
17387 +
17388 +1: mov %edi, %ecx
17389 + and $THREAD_SIZE_asm - 1, %ecx
17390 + shr $3, %ecx
17391 + repne scasq
17392 + jecxz 2f
17393 +
17394 + cmp $2*8, %ecx
17395 + jc 2f
17396 +
17397 + mov $2*8, %ecx
17398 + repe scasq
17399 + jecxz 2f
17400 + jne 1b
17401 +
17402 +2: cld
17403 + mov %esp, %ecx
17404 + sub %edi, %ecx
17405 +
17406 + cmp $THREAD_SIZE_asm, %rcx
17407 + jb 3f
17408 + ud2
17409 +3:
17410 +
17411 + shr $3, %ecx
17412 + rep stosq
17413 +
17414 + mov TI_task_thread_sp0(%r11), %rdi
17415 + sub $256, %rdi
17416 + mov %rdi, TI_lowest_stack(%r11)
17417 +
17418 + popq %r11
17419 + popq %rax
17420 + popq %rcx
17421 + popq %rdi
17422 + pax_force_retaddr
17423 + ret
17424 +ENDPROC(pax_erase_kstack)
17425 +#endif
17426
17427 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17428 #ifdef CONFIG_TRACE_IRQFLAGS
17429 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17430 .endm
17431
17432 .macro UNFAKE_STACK_FRAME
17433 - addq $8*6, %rsp
17434 - CFI_ADJUST_CFA_OFFSET -(6*8)
17435 + addq $8*6 + ARG_SKIP, %rsp
17436 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17437 .endm
17438
17439 /*
17440 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17441 movq %rsp, %rsi
17442
17443 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17444 - testl $3, CS-RBP(%rsi)
17445 + testb $3, CS-RBP(%rsi)
17446 je 1f
17447 SWAPGS
17448 /*
17449 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17450 movq_cfi r15, R15+16
17451 movq %r11, 8(%rsp) /* return address */
17452 FIXUP_TOP_OF_STACK %r11, 16
17453 + pax_force_retaddr
17454 ret
17455 CFI_ENDPROC
17456 -END(save_rest)
17457 +ENDPROC(save_rest)
17458
17459 /* save complete stack frame */
17460 .pushsection .kprobes.text, "ax"
17461 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17462 js 1f /* negative -> in kernel */
17463 SWAPGS
17464 xorl %ebx,%ebx
17465 -1: ret
17466 +1: pax_force_retaddr_bts
17467 + ret
17468 CFI_ENDPROC
17469 -END(save_paranoid)
17470 +ENDPROC(save_paranoid)
17471 .popsection
17472
17473 /*
17474 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17475
17476 RESTORE_REST
17477
17478 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17479 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17480 jz 1f
17481
17482 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17483 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17484 RESTORE_REST
17485 jmp int_ret_from_sys_call
17486 CFI_ENDPROC
17487 -END(ret_from_fork)
17488 +ENDPROC(ret_from_fork)
17489
17490 /*
17491 * System call entry. Up to 6 arguments in registers are supported.
17492 @@ -608,7 +886,7 @@ END(ret_from_fork)
17493 ENTRY(system_call)
17494 CFI_STARTPROC simple
17495 CFI_SIGNAL_FRAME
17496 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17497 + CFI_DEF_CFA rsp,0
17498 CFI_REGISTER rip,rcx
17499 /*CFI_REGISTER rflags,r11*/
17500 SWAPGS_UNSAFE_STACK
17501 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17502
17503 movq %rsp,PER_CPU_VAR(old_rsp)
17504 movq PER_CPU_VAR(kernel_stack),%rsp
17505 + SAVE_ARGS 8*6,0
17506 + pax_enter_kernel_user
17507 +
17508 +#ifdef CONFIG_PAX_RANDKSTACK
17509 + pax_erase_kstack
17510 +#endif
17511 +
17512 /*
17513 * No need to follow this irqs off/on section - it's straight
17514 * and short:
17515 */
17516 ENABLE_INTERRUPTS(CLBR_NONE)
17517 - SAVE_ARGS 8,0
17518 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17519 movq %rcx,RIP-ARGOFFSET(%rsp)
17520 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17521 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17522 + GET_THREAD_INFO(%rcx)
17523 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17524 jnz tracesys
17525 system_call_fastpath:
17526 #if __SYSCALL_MASK == ~0
17527 @@ -640,7 +925,7 @@ system_call_fastpath:
17528 cmpl $__NR_syscall_max,%eax
17529 #endif
17530 ja badsys
17531 - movq %r10,%rcx
17532 + movq R10-ARGOFFSET(%rsp),%rcx
17533 call *sys_call_table(,%rax,8) # XXX: rip relative
17534 movq %rax,RAX-ARGOFFSET(%rsp)
17535 /*
17536 @@ -654,10 +939,13 @@ sysret_check:
17537 LOCKDEP_SYS_EXIT
17538 DISABLE_INTERRUPTS(CLBR_NONE)
17539 TRACE_IRQS_OFF
17540 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17541 + GET_THREAD_INFO(%rcx)
17542 + movl TI_flags(%rcx),%edx
17543 andl %edi,%edx
17544 jnz sysret_careful
17545 CFI_REMEMBER_STATE
17546 + pax_exit_kernel_user
17547 + pax_erase_kstack
17548 /*
17549 * sysretq will re-enable interrupts:
17550 */
17551 @@ -709,14 +997,18 @@ badsys:
17552 * jump back to the normal fast path.
17553 */
17554 auditsys:
17555 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17556 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17557 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17558 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17559 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17560 movq %rax,%rsi /* 2nd arg: syscall number */
17561 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17562 call __audit_syscall_entry
17563 +
17564 + pax_erase_kstack
17565 +
17566 LOAD_ARGS 0 /* reload call-clobbered registers */
17567 + pax_set_fptr_mask
17568 jmp system_call_fastpath
17569
17570 /*
17571 @@ -737,7 +1029,7 @@ sysret_audit:
17572 /* Do syscall tracing */
17573 tracesys:
17574 #ifdef CONFIG_AUDITSYSCALL
17575 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17576 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17577 jz auditsys
17578 #endif
17579 SAVE_REST
17580 @@ -745,12 +1037,16 @@ tracesys:
17581 FIXUP_TOP_OF_STACK %rdi
17582 movq %rsp,%rdi
17583 call syscall_trace_enter
17584 +
17585 + pax_erase_kstack
17586 +
17587 /*
17588 * Reload arg registers from stack in case ptrace changed them.
17589 * We don't reload %rax because syscall_trace_enter() returned
17590 * the value it wants us to use in the table lookup.
17591 */
17592 LOAD_ARGS ARGOFFSET, 1
17593 + pax_set_fptr_mask
17594 RESTORE_REST
17595 #if __SYSCALL_MASK == ~0
17596 cmpq $__NR_syscall_max,%rax
17597 @@ -759,7 +1055,7 @@ tracesys:
17598 cmpl $__NR_syscall_max,%eax
17599 #endif
17600 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17601 - movq %r10,%rcx /* fixup for C */
17602 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17603 call *sys_call_table(,%rax,8)
17604 movq %rax,RAX-ARGOFFSET(%rsp)
17605 /* Use IRET because user could have changed frame */
17606 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17607 andl %edi,%edx
17608 jnz int_careful
17609 andl $~TS_COMPAT,TI_status(%rcx)
17610 - jmp retint_swapgs
17611 + pax_exit_kernel_user
17612 + pax_erase_kstack
17613 + jmp retint_swapgs_pax
17614
17615 /* Either reschedule or signal or syscall exit tracking needed. */
17616 /* First do a reschedule test. */
17617 @@ -826,7 +1124,7 @@ int_restore_rest:
17618 TRACE_IRQS_OFF
17619 jmp int_with_check
17620 CFI_ENDPROC
17621 -END(system_call)
17622 +ENDPROC(system_call)
17623
17624 /*
17625 * Certain special system calls that need to save a complete full stack frame.
17626 @@ -842,7 +1140,7 @@ ENTRY(\label)
17627 call \func
17628 jmp ptregscall_common
17629 CFI_ENDPROC
17630 -END(\label)
17631 +ENDPROC(\label)
17632 .endm
17633
17634 PTREGSCALL stub_clone, sys_clone, %r8
17635 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17636 movq_cfi_restore R12+8, r12
17637 movq_cfi_restore RBP+8, rbp
17638 movq_cfi_restore RBX+8, rbx
17639 + pax_force_retaddr
17640 ret $REST_SKIP /* pop extended registers */
17641 CFI_ENDPROC
17642 -END(ptregscall_common)
17643 +ENDPROC(ptregscall_common)
17644
17645 ENTRY(stub_execve)
17646 CFI_STARTPROC
17647 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17648 RESTORE_REST
17649 jmp int_ret_from_sys_call
17650 CFI_ENDPROC
17651 -END(stub_execve)
17652 +ENDPROC(stub_execve)
17653
17654 /*
17655 * sigreturn is special because it needs to restore all registers on return.
17656 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17657 RESTORE_REST
17658 jmp int_ret_from_sys_call
17659 CFI_ENDPROC
17660 -END(stub_rt_sigreturn)
17661 +ENDPROC(stub_rt_sigreturn)
17662
17663 #ifdef CONFIG_X86_X32_ABI
17664 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17665 @@ -962,7 +1261,7 @@ vector=vector+1
17666 2: jmp common_interrupt
17667 .endr
17668 CFI_ENDPROC
17669 -END(irq_entries_start)
17670 +ENDPROC(irq_entries_start)
17671
17672 .previous
17673 END(interrupt)
17674 @@ -982,6 +1281,16 @@ END(interrupt)
17675 subq $ORIG_RAX-RBP, %rsp
17676 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17677 SAVE_ARGS_IRQ
17678 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17679 + testb $3, CS(%rdi)
17680 + jnz 1f
17681 + pax_enter_kernel
17682 + jmp 2f
17683 +1: pax_enter_kernel_user
17684 +2:
17685 +#else
17686 + pax_enter_kernel
17687 +#endif
17688 call \func
17689 .endm
17690
17691 @@ -1014,7 +1323,7 @@ ret_from_intr:
17692
17693 exit_intr:
17694 GET_THREAD_INFO(%rcx)
17695 - testl $3,CS-ARGOFFSET(%rsp)
17696 + testb $3,CS-ARGOFFSET(%rsp)
17697 je retint_kernel
17698
17699 /* Interrupt came from user space */
17700 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17701 * The iretq could re-enable interrupts:
17702 */
17703 DISABLE_INTERRUPTS(CLBR_ANY)
17704 + pax_exit_kernel_user
17705 +retint_swapgs_pax:
17706 TRACE_IRQS_IRETQ
17707 SWAPGS
17708 jmp restore_args
17709
17710 retint_restore_args: /* return to kernel space */
17711 DISABLE_INTERRUPTS(CLBR_ANY)
17712 + pax_exit_kernel
17713 + pax_force_retaddr (RIP-ARGOFFSET)
17714 /*
17715 * The iretq could re-enable interrupts:
17716 */
17717 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17718 #endif
17719
17720 CFI_ENDPROC
17721 -END(common_interrupt)
17722 +ENDPROC(common_interrupt)
17723 /*
17724 * End of kprobes section
17725 */
17726 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17727 interrupt \do_sym
17728 jmp ret_from_intr
17729 CFI_ENDPROC
17730 -END(\sym)
17731 +ENDPROC(\sym)
17732 .endm
17733
17734 #ifdef CONFIG_SMP
17735 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17736 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17737 call error_entry
17738 DEFAULT_FRAME 0
17739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17740 + testb $3, CS(%rsp)
17741 + jnz 1f
17742 + pax_enter_kernel
17743 + jmp 2f
17744 +1: pax_enter_kernel_user
17745 +2:
17746 +#else
17747 + pax_enter_kernel
17748 +#endif
17749 movq %rsp,%rdi /* pt_regs pointer */
17750 xorl %esi,%esi /* no error code */
17751 call \do_sym
17752 jmp error_exit /* %ebx: no swapgs flag */
17753 CFI_ENDPROC
17754 -END(\sym)
17755 +ENDPROC(\sym)
17756 .endm
17757
17758 .macro paranoidzeroentry sym do_sym
17759 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17760 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17761 call save_paranoid
17762 TRACE_IRQS_OFF
17763 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17764 + testb $3, CS(%rsp)
17765 + jnz 1f
17766 + pax_enter_kernel
17767 + jmp 2f
17768 +1: pax_enter_kernel_user
17769 +2:
17770 +#else
17771 + pax_enter_kernel
17772 +#endif
17773 movq %rsp,%rdi /* pt_regs pointer */
17774 xorl %esi,%esi /* no error code */
17775 call \do_sym
17776 jmp paranoid_exit /* %ebx: no swapgs flag */
17777 CFI_ENDPROC
17778 -END(\sym)
17779 +ENDPROC(\sym)
17780 .endm
17781
17782 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17783 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17784 .macro paranoidzeroentry_ist sym do_sym ist
17785 ENTRY(\sym)
17786 INTR_FRAME
17787 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17788 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17789 call save_paranoid
17790 TRACE_IRQS_OFF_DEBUG
17791 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17792 + testb $3, CS(%rsp)
17793 + jnz 1f
17794 + pax_enter_kernel
17795 + jmp 2f
17796 +1: pax_enter_kernel_user
17797 +2:
17798 +#else
17799 + pax_enter_kernel
17800 +#endif
17801 movq %rsp,%rdi /* pt_regs pointer */
17802 xorl %esi,%esi /* no error code */
17803 +#ifdef CONFIG_SMP
17804 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17805 + lea init_tss(%r12), %r12
17806 +#else
17807 + lea init_tss(%rip), %r12
17808 +#endif
17809 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17810 call \do_sym
17811 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17812 jmp paranoid_exit /* %ebx: no swapgs flag */
17813 CFI_ENDPROC
17814 -END(\sym)
17815 +ENDPROC(\sym)
17816 .endm
17817
17818 .macro errorentry sym do_sym
17819 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17820 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17821 call error_entry
17822 DEFAULT_FRAME 0
17823 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17824 + testb $3, CS(%rsp)
17825 + jnz 1f
17826 + pax_enter_kernel
17827 + jmp 2f
17828 +1: pax_enter_kernel_user
17829 +2:
17830 +#else
17831 + pax_enter_kernel
17832 +#endif
17833 movq %rsp,%rdi /* pt_regs pointer */
17834 movq ORIG_RAX(%rsp),%rsi /* get error code */
17835 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17836 call \do_sym
17837 jmp error_exit /* %ebx: no swapgs flag */
17838 CFI_ENDPROC
17839 -END(\sym)
17840 +ENDPROC(\sym)
17841 .endm
17842
17843 /* error code is on the stack already */
17844 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17845 call save_paranoid
17846 DEFAULT_FRAME 0
17847 TRACE_IRQS_OFF
17848 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17849 + testb $3, CS(%rsp)
17850 + jnz 1f
17851 + pax_enter_kernel
17852 + jmp 2f
17853 +1: pax_enter_kernel_user
17854 +2:
17855 +#else
17856 + pax_enter_kernel
17857 +#endif
17858 movq %rsp,%rdi /* pt_regs pointer */
17859 movq ORIG_RAX(%rsp),%rsi /* get error code */
17860 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17861 call \do_sym
17862 jmp paranoid_exit /* %ebx: no swapgs flag */
17863 CFI_ENDPROC
17864 -END(\sym)
17865 +ENDPROC(\sym)
17866 .endm
17867
17868 zeroentry divide_error do_divide_error
17869 @@ -1310,9 +1679,10 @@ gs_change:
17870 2: mfence /* workaround */
17871 SWAPGS
17872 popfq_cfi
17873 + pax_force_retaddr
17874 ret
17875 CFI_ENDPROC
17876 -END(native_load_gs_index)
17877 +ENDPROC(native_load_gs_index)
17878
17879 _ASM_EXTABLE(gs_change,bad_gs)
17880 .section .fixup,"ax"
17881 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17882 CFI_DEF_CFA_REGISTER rsp
17883 CFI_ADJUST_CFA_OFFSET -8
17884 decl PER_CPU_VAR(irq_count)
17885 + pax_force_retaddr
17886 ret
17887 CFI_ENDPROC
17888 -END(call_softirq)
17889 +ENDPROC(call_softirq)
17890
17891 #ifdef CONFIG_XEN
17892 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17893 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17894 decl PER_CPU_VAR(irq_count)
17895 jmp error_exit
17896 CFI_ENDPROC
17897 -END(xen_do_hypervisor_callback)
17898 +ENDPROC(xen_do_hypervisor_callback)
17899
17900 /*
17901 * Hypervisor uses this for application faults while it executes.
17902 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17903 SAVE_ALL
17904 jmp error_exit
17905 CFI_ENDPROC
17906 -END(xen_failsafe_callback)
17907 +ENDPROC(xen_failsafe_callback)
17908
17909 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17910 xen_hvm_callback_vector xen_evtchn_do_upcall
17911 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17912 TRACE_IRQS_OFF_DEBUG
17913 testl %ebx,%ebx /* swapgs needed? */
17914 jnz paranoid_restore
17915 - testl $3,CS(%rsp)
17916 + testb $3,CS(%rsp)
17917 jnz paranoid_userspace
17918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17919 + pax_exit_kernel
17920 + TRACE_IRQS_IRETQ 0
17921 + SWAPGS_UNSAFE_STACK
17922 + RESTORE_ALL 8
17923 + pax_force_retaddr_bts
17924 + jmp irq_return
17925 +#endif
17926 paranoid_swapgs:
17927 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17928 + pax_exit_kernel_user
17929 +#else
17930 + pax_exit_kernel
17931 +#endif
17932 TRACE_IRQS_IRETQ 0
17933 SWAPGS_UNSAFE_STACK
17934 RESTORE_ALL 8
17935 jmp irq_return
17936 paranoid_restore:
17937 + pax_exit_kernel
17938 TRACE_IRQS_IRETQ_DEBUG 0
17939 RESTORE_ALL 8
17940 + pax_force_retaddr_bts
17941 jmp irq_return
17942 paranoid_userspace:
17943 GET_THREAD_INFO(%rcx)
17944 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17945 TRACE_IRQS_OFF
17946 jmp paranoid_userspace
17947 CFI_ENDPROC
17948 -END(paranoid_exit)
17949 +ENDPROC(paranoid_exit)
17950
17951 /*
17952 * Exception entry point. This expects an error code/orig_rax on the stack.
17953 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17954 movq_cfi r14, R14+8
17955 movq_cfi r15, R15+8
17956 xorl %ebx,%ebx
17957 - testl $3,CS+8(%rsp)
17958 + testb $3,CS+8(%rsp)
17959 je error_kernelspace
17960 error_swapgs:
17961 SWAPGS
17962 error_sti:
17963 TRACE_IRQS_OFF
17964 + pax_force_retaddr_bts
17965 ret
17966
17967 /*
17968 @@ -1585,7 +1972,7 @@ bstep_iret:
17969 movq %rcx,RIP+8(%rsp)
17970 jmp error_swapgs
17971 CFI_ENDPROC
17972 -END(error_entry)
17973 +ENDPROC(error_entry)
17974
17975
17976 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17977 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17978 jnz retint_careful
17979 jmp retint_swapgs
17980 CFI_ENDPROC
17981 -END(error_exit)
17982 +ENDPROC(error_exit)
17983
17984 /*
17985 * Test if a given stack is an NMI stack or not.
17986 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17987 * If %cs was not the kernel segment, then the NMI triggered in user
17988 * space, which means it is definitely not nested.
17989 */
17990 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17991 + je 1f
17992 cmpl $__KERNEL_CS, 16(%rsp)
17993 jne first_nmi
17994 -
17995 +1:
17996 /*
17997 * Check the special variable on the stack to see if NMIs are
17998 * executing.
17999 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
18000 */
18001 movq %cr2, %r12
18002
18003 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18004 + testb $3, CS(%rsp)
18005 + jnz 1f
18006 + pax_enter_kernel
18007 + jmp 2f
18008 +1: pax_enter_kernel_user
18009 +2:
18010 +#else
18011 + pax_enter_kernel
18012 +#endif
18013 +
18014 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
18015 movq %rsp,%rdi
18016 movq $-1,%rsi
18017 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
18018 testl %ebx,%ebx /* swapgs needed? */
18019 jnz nmi_restore
18020 nmi_swapgs:
18021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18022 + pax_exit_kernel_user
18023 +#else
18024 + pax_exit_kernel
18025 +#endif
18026 SWAPGS_UNSAFE_STACK
18027 + RESTORE_ALL 8
18028 + /* Clear the NMI executing stack variable */
18029 + movq $0, 10*8(%rsp)
18030 + jmp irq_return
18031 nmi_restore:
18032 + pax_exit_kernel
18033 RESTORE_ALL 8
18034 + pax_force_retaddr_bts
18035 /* Clear the NMI executing stack variable */
18036 movq $0, 10*8(%rsp)
18037 jmp irq_return
18038 CFI_ENDPROC
18039 -END(nmi)
18040 +ENDPROC(nmi)
18041
18042 ENTRY(ignore_sysret)
18043 CFI_STARTPROC
18044 mov $-ENOSYS,%eax
18045 sysret
18046 CFI_ENDPROC
18047 -END(ignore_sysret)
18048 +ENDPROC(ignore_sysret)
18049
18050 /*
18051 * End of kprobes section
18052 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
18053 index 1d41402..af9a46a 100644
18054 --- a/arch/x86/kernel/ftrace.c
18055 +++ b/arch/x86/kernel/ftrace.c
18056 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
18057 {
18058 unsigned char replaced[MCOUNT_INSN_SIZE];
18059
18060 + ip = ktla_ktva(ip);
18061 +
18062 /*
18063 * Note: Due to modules and __init, code can
18064 * disappear and change, we need to protect against faulting
18065 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
18066 unsigned char old[MCOUNT_INSN_SIZE], *new;
18067 int ret;
18068
18069 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
18070 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
18071 new = ftrace_call_replace(ip, (unsigned long)func);
18072
18073 /* See comment above by declaration of modifying_ftrace_code */
18074 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
18075 /* Also update the regs callback function */
18076 if (!ret) {
18077 ip = (unsigned long)(&ftrace_regs_call);
18078 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
18079 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
18080 new = ftrace_call_replace(ip, (unsigned long)func);
18081 ret = ftrace_modify_code(ip, old, new);
18082 }
18083 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
18084 * kernel identity mapping to modify code.
18085 */
18086 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
18087 - ip = (unsigned long)__va(__pa(ip));
18088 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
18089
18090 return probe_kernel_write((void *)ip, val, size);
18091 }
18092 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
18093 unsigned char replaced[MCOUNT_INSN_SIZE];
18094 unsigned char brk = BREAKPOINT_INSTRUCTION;
18095
18096 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
18097 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
18098 return -EFAULT;
18099
18100 /* Make sure it is what we expect it to be */
18101 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
18102 return ret;
18103
18104 fail_update:
18105 - probe_kernel_write((void *)ip, &old_code[0], 1);
18106 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
18107 goto out;
18108 }
18109
18110 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
18111 {
18112 unsigned char code[MCOUNT_INSN_SIZE];
18113
18114 + ip = ktla_ktva(ip);
18115 +
18116 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18117 return -EFAULT;
18118
18119 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18120 index c18f59d..9c0c9f6 100644
18121 --- a/arch/x86/kernel/head32.c
18122 +++ b/arch/x86/kernel/head32.c
18123 @@ -18,6 +18,7 @@
18124 #include <asm/io_apic.h>
18125 #include <asm/bios_ebda.h>
18126 #include <asm/tlbflush.h>
18127 +#include <asm/boot.h>
18128
18129 static void __init i386_default_early_setup(void)
18130 {
18131 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
18132
18133 void __init i386_start_kernel(void)
18134 {
18135 - memblock_reserve(__pa_symbol(&_text),
18136 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18137 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18138
18139 #ifdef CONFIG_BLK_DEV_INITRD
18140 /* Reserve INITRD */
18141 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18142 index 4dac2f6..bc6a335 100644
18143 --- a/arch/x86/kernel/head_32.S
18144 +++ b/arch/x86/kernel/head_32.S
18145 @@ -26,6 +26,12 @@
18146 /* Physical address */
18147 #define pa(X) ((X) - __PAGE_OFFSET)
18148
18149 +#ifdef CONFIG_PAX_KERNEXEC
18150 +#define ta(X) (X)
18151 +#else
18152 +#define ta(X) ((X) - __PAGE_OFFSET)
18153 +#endif
18154 +
18155 /*
18156 * References to members of the new_cpu_data structure.
18157 */
18158 @@ -55,11 +61,7 @@
18159 * and small than max_low_pfn, otherwise will waste some page table entries
18160 */
18161
18162 -#if PTRS_PER_PMD > 1
18163 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18164 -#else
18165 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18166 -#endif
18167 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18168
18169 /* Number of possible pages in the lowmem region */
18170 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18171 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18172 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18173
18174 /*
18175 + * Real beginning of normal "text" segment
18176 + */
18177 +ENTRY(stext)
18178 +ENTRY(_stext)
18179 +
18180 +/*
18181 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18182 * %esi points to the real-mode code as a 32-bit pointer.
18183 * CS and DS must be 4 GB flat segments, but we don't depend on
18184 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18185 * can.
18186 */
18187 __HEAD
18188 +
18189 +#ifdef CONFIG_PAX_KERNEXEC
18190 + jmp startup_32
18191 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18192 +.fill PAGE_SIZE-5,1,0xcc
18193 +#endif
18194 +
18195 ENTRY(startup_32)
18196 movl pa(stack_start),%ecx
18197
18198 @@ -106,6 +121,59 @@ ENTRY(startup_32)
18199 2:
18200 leal -__PAGE_OFFSET(%ecx),%esp
18201
18202 +#ifdef CONFIG_SMP
18203 + movl $pa(cpu_gdt_table),%edi
18204 + movl $__per_cpu_load,%eax
18205 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18206 + rorl $16,%eax
18207 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18208 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18209 + movl $__per_cpu_end - 1,%eax
18210 + subl $__per_cpu_start,%eax
18211 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18212 +#endif
18213 +
18214 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18215 + movl $NR_CPUS,%ecx
18216 + movl $pa(cpu_gdt_table),%edi
18217 +1:
18218 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18219 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18220 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18221 + addl $PAGE_SIZE_asm,%edi
18222 + loop 1b
18223 +#endif
18224 +
18225 +#ifdef CONFIG_PAX_KERNEXEC
18226 + movl $pa(boot_gdt),%edi
18227 + movl $__LOAD_PHYSICAL_ADDR,%eax
18228 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18229 + rorl $16,%eax
18230 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18231 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18232 + rorl $16,%eax
18233 +
18234 + ljmp $(__BOOT_CS),$1f
18235 +1:
18236 +
18237 + movl $NR_CPUS,%ecx
18238 + movl $pa(cpu_gdt_table),%edi
18239 + addl $__PAGE_OFFSET,%eax
18240 +1:
18241 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18242 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18243 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18244 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18245 + rorl $16,%eax
18246 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18247 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18248 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18249 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18250 + rorl $16,%eax
18251 + addl $PAGE_SIZE_asm,%edi
18252 + loop 1b
18253 +#endif
18254 +
18255 /*
18256 * Clear BSS first so that there are no surprises...
18257 */
18258 @@ -196,8 +264,11 @@ ENTRY(startup_32)
18259 movl %eax, pa(max_pfn_mapped)
18260
18261 /* Do early initialization of the fixmap area */
18262 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18263 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18264 +#ifdef CONFIG_COMPAT_VDSO
18265 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18266 +#else
18267 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18268 +#endif
18269 #else /* Not PAE */
18270
18271 page_pde_offset = (__PAGE_OFFSET >> 20);
18272 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18273 movl %eax, pa(max_pfn_mapped)
18274
18275 /* Do early initialization of the fixmap area */
18276 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18277 - movl %eax,pa(initial_page_table+0xffc)
18278 +#ifdef CONFIG_COMPAT_VDSO
18279 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18280 +#else
18281 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18282 +#endif
18283 #endif
18284
18285 #ifdef CONFIG_PARAVIRT
18286 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18287 cmpl $num_subarch_entries, %eax
18288 jae bad_subarch
18289
18290 - movl pa(subarch_entries)(,%eax,4), %eax
18291 - subl $__PAGE_OFFSET, %eax
18292 - jmp *%eax
18293 + jmp *pa(subarch_entries)(,%eax,4)
18294
18295 bad_subarch:
18296 WEAK(lguest_entry)
18297 @@ -256,10 +328,10 @@ WEAK(xen_entry)
18298 __INITDATA
18299
18300 subarch_entries:
18301 - .long default_entry /* normal x86/PC */
18302 - .long lguest_entry /* lguest hypervisor */
18303 - .long xen_entry /* Xen hypervisor */
18304 - .long default_entry /* Moorestown MID */
18305 + .long ta(default_entry) /* normal x86/PC */
18306 + .long ta(lguest_entry) /* lguest hypervisor */
18307 + .long ta(xen_entry) /* Xen hypervisor */
18308 + .long ta(default_entry) /* Moorestown MID */
18309 num_subarch_entries = (. - subarch_entries) / 4
18310 .previous
18311 #else
18312 @@ -316,6 +388,7 @@ default_entry:
18313 movl pa(mmu_cr4_features),%eax
18314 movl %eax,%cr4
18315
18316 +#ifdef CONFIG_X86_PAE
18317 testb $X86_CR4_PAE, %al # check if PAE is enabled
18318 jz 6f
18319
18320 @@ -344,6 +417,9 @@ default_entry:
18321 /* Make changes effective */
18322 wrmsr
18323
18324 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18325 +#endif
18326 +
18327 6:
18328
18329 /*
18330 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18331 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18332 movl %eax,%ss # after changing gdt.
18333
18334 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
18335 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18336 movl %eax,%ds
18337 movl %eax,%es
18338
18339 movl $(__KERNEL_PERCPU), %eax
18340 movl %eax,%fs # set this cpu's percpu
18341
18342 +#ifdef CONFIG_CC_STACKPROTECTOR
18343 movl $(__KERNEL_STACK_CANARY),%eax
18344 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18345 + movl $(__USER_DS),%eax
18346 +#else
18347 + xorl %eax,%eax
18348 +#endif
18349 movl %eax,%gs
18350
18351 xorl %eax,%eax # Clear LDT
18352 @@ -526,8 +608,11 @@ setup_once:
18353 * relocation. Manually set base address in stack canary
18354 * segment descriptor.
18355 */
18356 - movl $gdt_page,%eax
18357 + movl $cpu_gdt_table,%eax
18358 movl $stack_canary,%ecx
18359 +#ifdef CONFIG_SMP
18360 + addl $__per_cpu_load,%ecx
18361 +#endif
18362 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18363 shrl $16, %ecx
18364 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18365 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18366 /* This is global to keep gas from relaxing the jumps */
18367 ENTRY(early_idt_handler)
18368 cld
18369 - cmpl $2,%ss:early_recursion_flag
18370 + cmpl $1,%ss:early_recursion_flag
18371 je hlt_loop
18372 incl %ss:early_recursion_flag
18373
18374 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18375 pushl (20+6*4)(%esp) /* trapno */
18376 pushl $fault_msg
18377 call printk
18378 -#endif
18379 call dump_stack
18380 +#endif
18381 hlt_loop:
18382 hlt
18383 jmp hlt_loop
18384 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18385 /* This is the default interrupt "handler" :-) */
18386 ALIGN
18387 ignore_int:
18388 - cld
18389 #ifdef CONFIG_PRINTK
18390 + cmpl $2,%ss:early_recursion_flag
18391 + je hlt_loop
18392 + incl %ss:early_recursion_flag
18393 + cld
18394 pushl %eax
18395 pushl %ecx
18396 pushl %edx
18397 @@ -626,9 +714,6 @@ ignore_int:
18398 movl $(__KERNEL_DS),%eax
18399 movl %eax,%ds
18400 movl %eax,%es
18401 - cmpl $2,early_recursion_flag
18402 - je hlt_loop
18403 - incl early_recursion_flag
18404 pushl 16(%esp)
18405 pushl 24(%esp)
18406 pushl 32(%esp)
18407 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18408 /*
18409 * BSS section
18410 */
18411 -__PAGE_ALIGNED_BSS
18412 - .align PAGE_SIZE
18413 #ifdef CONFIG_X86_PAE
18414 +.section .initial_pg_pmd,"a",@progbits
18415 initial_pg_pmd:
18416 .fill 1024*KPMDS,4,0
18417 #else
18418 +.section .initial_page_table,"a",@progbits
18419 ENTRY(initial_page_table)
18420 .fill 1024,4,0
18421 #endif
18422 +.section .initial_pg_fixmap,"a",@progbits
18423 initial_pg_fixmap:
18424 .fill 1024,4,0
18425 +.section .empty_zero_page,"a",@progbits
18426 ENTRY(empty_zero_page)
18427 .fill 4096,1,0
18428 +.section .swapper_pg_dir,"a",@progbits
18429 ENTRY(swapper_pg_dir)
18430 +#ifdef CONFIG_X86_PAE
18431 + .fill 4,8,0
18432 +#else
18433 .fill 1024,4,0
18434 +#endif
18435 +
18436 +/*
18437 + * The IDT has to be page-aligned to simplify the Pentium
18438 + * F0 0F bug workaround.. We have a special link segment
18439 + * for this.
18440 + */
18441 +.section .idt,"a",@progbits
18442 +ENTRY(idt_table)
18443 + .fill 256,8,0
18444
18445 /*
18446 * This starts the data section.
18447 */
18448 #ifdef CONFIG_X86_PAE
18449 -__PAGE_ALIGNED_DATA
18450 - /* Page-aligned for the benefit of paravirt? */
18451 - .align PAGE_SIZE
18452 +.section .initial_page_table,"a",@progbits
18453 ENTRY(initial_page_table)
18454 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18455 # if KPMDS == 3
18456 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18457 # error "Kernel PMDs should be 1, 2 or 3"
18458 # endif
18459 .align PAGE_SIZE /* needs to be page-sized too */
18460 +
18461 +#ifdef CONFIG_PAX_PER_CPU_PGD
18462 +ENTRY(cpu_pgd)
18463 + .rept NR_CPUS
18464 + .fill 4,8,0
18465 + .endr
18466 +#endif
18467 +
18468 #endif
18469
18470 .data
18471 .balign 4
18472 ENTRY(stack_start)
18473 - .long init_thread_union+THREAD_SIZE
18474 + .long init_thread_union+THREAD_SIZE-8
18475
18476 __INITRODATA
18477 int_msg:
18478 @@ -736,7 +843,7 @@ fault_msg:
18479 * segment size, and 32-bit linear address value:
18480 */
18481
18482 - .data
18483 +.section .rodata,"a",@progbits
18484 .globl boot_gdt_descr
18485 .globl idt_descr
18486
18487 @@ -745,7 +852,7 @@ fault_msg:
18488 .word 0 # 32 bit align gdt_desc.address
18489 boot_gdt_descr:
18490 .word __BOOT_DS+7
18491 - .long boot_gdt - __PAGE_OFFSET
18492 + .long pa(boot_gdt)
18493
18494 .word 0 # 32-bit align idt_desc.address
18495 idt_descr:
18496 @@ -756,7 +863,7 @@ idt_descr:
18497 .word 0 # 32 bit align gdt_desc.address
18498 ENTRY(early_gdt_descr)
18499 .word GDT_ENTRIES*8-1
18500 - .long gdt_page /* Overwritten for secondary CPUs */
18501 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18502
18503 /*
18504 * The boot_gdt must mirror the equivalent in setup.S and is
18505 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18506 .align L1_CACHE_BYTES
18507 ENTRY(boot_gdt)
18508 .fill GDT_ENTRY_BOOT_CS,8,0
18509 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18510 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18511 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18512 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18513 +
18514 + .align PAGE_SIZE_asm
18515 +ENTRY(cpu_gdt_table)
18516 + .rept NR_CPUS
18517 + .quad 0x0000000000000000 /* NULL descriptor */
18518 + .quad 0x0000000000000000 /* 0x0b reserved */
18519 + .quad 0x0000000000000000 /* 0x13 reserved */
18520 + .quad 0x0000000000000000 /* 0x1b reserved */
18521 +
18522 +#ifdef CONFIG_PAX_KERNEXEC
18523 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18524 +#else
18525 + .quad 0x0000000000000000 /* 0x20 unused */
18526 +#endif
18527 +
18528 + .quad 0x0000000000000000 /* 0x28 unused */
18529 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18530 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18531 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18532 + .quad 0x0000000000000000 /* 0x4b reserved */
18533 + .quad 0x0000000000000000 /* 0x53 reserved */
18534 + .quad 0x0000000000000000 /* 0x5b reserved */
18535 +
18536 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18537 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18538 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18539 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18540 +
18541 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18542 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18543 +
18544 + /*
18545 + * Segments used for calling PnP BIOS have byte granularity.
18546 + * The code segments and data segments have fixed 64k limits,
18547 + * the transfer segment sizes are set at run time.
18548 + */
18549 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18550 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18551 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18552 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18553 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18554 +
18555 + /*
18556 + * The APM segments have byte granularity and their bases
18557 + * are set at run time. All have 64k limits.
18558 + */
18559 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18560 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18561 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18562 +
18563 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18564 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18565 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18566 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18567 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18568 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18569 +
18570 + /* Be sure this is zeroed to avoid false validations in Xen */
18571 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18572 + .endr
18573 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18574 index 94bf9cc..400455a 100644
18575 --- a/arch/x86/kernel/head_64.S
18576 +++ b/arch/x86/kernel/head_64.S
18577 @@ -20,6 +20,8 @@
18578 #include <asm/processor-flags.h>
18579 #include <asm/percpu.h>
18580 #include <asm/nops.h>
18581 +#include <asm/cpufeature.h>
18582 +#include <asm/alternative-asm.h>
18583
18584 #ifdef CONFIG_PARAVIRT
18585 #include <asm/asm-offsets.h>
18586 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18587 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18588 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18589 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18590 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18591 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18592 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18593 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18594 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18595 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18596
18597 .text
18598 __HEAD
18599 @@ -88,35 +96,23 @@ startup_64:
18600 */
18601 addq %rbp, init_level4_pgt + 0(%rip)
18602 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18603 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18604 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18605 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18606 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18607
18608 addq %rbp, level3_ident_pgt + 0(%rip)
18609 +#ifndef CONFIG_XEN
18610 + addq %rbp, level3_ident_pgt + 8(%rip)
18611 +#endif
18612
18613 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18614 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18615 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18616 +
18617 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18618 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18619
18620 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18621 -
18622 - /* Add an Identity mapping if I am above 1G */
18623 - leaq _text(%rip), %rdi
18624 - andq $PMD_PAGE_MASK, %rdi
18625 -
18626 - movq %rdi, %rax
18627 - shrq $PUD_SHIFT, %rax
18628 - andq $(PTRS_PER_PUD - 1), %rax
18629 - jz ident_complete
18630 -
18631 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18632 - leaq level3_ident_pgt(%rip), %rbx
18633 - movq %rdx, 0(%rbx, %rax, 8)
18634 -
18635 - movq %rdi, %rax
18636 - shrq $PMD_SHIFT, %rax
18637 - andq $(PTRS_PER_PMD - 1), %rax
18638 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18639 - leaq level2_spare_pgt(%rip), %rbx
18640 - movq %rdx, 0(%rbx, %rax, 8)
18641 -ident_complete:
18642 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18643
18644 /*
18645 * Fixup the kernel text+data virtual addresses. Note that
18646 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18647 * after the boot processor executes this code.
18648 */
18649
18650 - /* Enable PAE mode and PGE */
18651 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18652 + /* Enable PAE mode and PSE/PGE */
18653 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18654 movq %rax, %cr4
18655
18656 /* Setup early boot stage 4 level pagetables. */
18657 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18658 movl $MSR_EFER, %ecx
18659 rdmsr
18660 btsl $_EFER_SCE, %eax /* Enable System Call */
18661 - btl $20,%edi /* No Execute supported? */
18662 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18663 jnc 1f
18664 btsl $_EFER_NX, %eax
18665 + leaq init_level4_pgt(%rip), %rdi
18666 +#ifndef CONFIG_EFI
18667 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18668 +#endif
18669 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18670 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18671 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18672 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18673 1: wrmsr /* Make changes effective */
18674
18675 /* Setup cr0 */
18676 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18677 * jump. In addition we need to ensure %cs is set so we make this
18678 * a far return.
18679 */
18680 + pax_set_fptr_mask
18681 movq initial_code(%rip),%rax
18682 pushq $0 # fake return address to stop unwinder
18683 pushq $__KERNEL_CS # set correct cs
18684 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18685 bad_address:
18686 jmp bad_address
18687
18688 - .section ".init.text","ax"
18689 + __INIT
18690 .globl early_idt_handlers
18691 early_idt_handlers:
18692 # 104(%rsp) %rflags
18693 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18694 addq $16,%rsp # drop vector number and error code
18695 decl early_recursion_flag(%rip)
18696 INTERRUPT_RETURN
18697 + .previous
18698
18699 + __INITDATA
18700 .balign 4
18701 early_recursion_flag:
18702 .long 0
18703 + .previous
18704
18705 + .section .rodata,"a",@progbits
18706 #ifdef CONFIG_EARLY_PRINTK
18707 early_idt_msg:
18708 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18709 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18710 #endif /* CONFIG_EARLY_PRINTK */
18711 .previous
18712
18713 + .section .rodata,"a",@progbits
18714 #define NEXT_PAGE(name) \
18715 .balign PAGE_SIZE; \
18716 ENTRY(name)
18717 @@ -372,7 +382,6 @@ ENTRY(name)
18718 i = i + 1 ; \
18719 .endr
18720
18721 - .data
18722 /*
18723 * This default setting generates an ident mapping at address 0x100000
18724 * and a mapping for the kernel that precisely maps virtual address
18725 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18726 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18727 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18728 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18729 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18730 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18731 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18732 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18733 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18734 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18735 .org init_level4_pgt + L4_START_KERNEL*8, 0
18736 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18737 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18738
18739 +#ifdef CONFIG_PAX_PER_CPU_PGD
18740 +NEXT_PAGE(cpu_pgd)
18741 + .rept NR_CPUS
18742 + .fill 512,8,0
18743 + .endr
18744 +#endif
18745 +
18746 NEXT_PAGE(level3_ident_pgt)
18747 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18748 +#ifdef CONFIG_XEN
18749 .fill 511,8,0
18750 +#else
18751 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18752 + .fill 510,8,0
18753 +#endif
18754 +
18755 +NEXT_PAGE(level3_vmalloc_start_pgt)
18756 + .fill 512,8,0
18757 +
18758 +NEXT_PAGE(level3_vmalloc_end_pgt)
18759 + .fill 512,8,0
18760 +
18761 +NEXT_PAGE(level3_vmemmap_pgt)
18762 + .fill L3_VMEMMAP_START,8,0
18763 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18764
18765 NEXT_PAGE(level3_kernel_pgt)
18766 .fill L3_START_KERNEL,8,0
18767 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18768 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18769 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18770
18771 +NEXT_PAGE(level2_vmemmap_pgt)
18772 + .fill 512,8,0
18773 +
18774 NEXT_PAGE(level2_fixmap_pgt)
18775 - .fill 506,8,0
18776 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18777 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18778 - .fill 5,8,0
18779 + .fill 507,8,0
18780 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18781 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18782 + .fill 4,8,0
18783
18784 -NEXT_PAGE(level1_fixmap_pgt)
18785 +NEXT_PAGE(level1_vsyscall_pgt)
18786 .fill 512,8,0
18787
18788 -NEXT_PAGE(level2_ident_pgt)
18789 - /* Since I easily can, map the first 1G.
18790 + /* Since I easily can, map the first 2G.
18791 * Don't set NX because code runs from these pages.
18792 */
18793 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18794 +NEXT_PAGE(level2_ident_pgt)
18795 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18796
18797 NEXT_PAGE(level2_kernel_pgt)
18798 /*
18799 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18800 * If you want to increase this then increase MODULES_VADDR
18801 * too.)
18802 */
18803 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18804 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18805 -
18806 -NEXT_PAGE(level2_spare_pgt)
18807 - .fill 512, 8, 0
18808 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18809
18810 #undef PMDS
18811 #undef NEXT_PAGE
18812
18813 - .data
18814 + .align PAGE_SIZE
18815 +ENTRY(cpu_gdt_table)
18816 + .rept NR_CPUS
18817 + .quad 0x0000000000000000 /* NULL descriptor */
18818 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18819 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18820 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18821 + .quad 0x00cffb000000ffff /* __USER32_CS */
18822 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18823 + .quad 0x00affb000000ffff /* __USER_CS */
18824 +
18825 +#ifdef CONFIG_PAX_KERNEXEC
18826 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18827 +#else
18828 + .quad 0x0 /* unused */
18829 +#endif
18830 +
18831 + .quad 0,0 /* TSS */
18832 + .quad 0,0 /* LDT */
18833 + .quad 0,0,0 /* three TLS descriptors */
18834 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18835 + /* asm/segment.h:GDT_ENTRIES must match this */
18836 +
18837 + /* zero the remaining page */
18838 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18839 + .endr
18840 +
18841 .align 16
18842 .globl early_gdt_descr
18843 early_gdt_descr:
18844 .word GDT_ENTRIES*8-1
18845 early_gdt_descr_base:
18846 - .quad INIT_PER_CPU_VAR(gdt_page)
18847 + .quad cpu_gdt_table
18848
18849 ENTRY(phys_base)
18850 /* This must match the first entry in level2_kernel_pgt */
18851 .quad 0x0000000000000000
18852
18853 #include "../../x86/xen/xen-head.S"
18854 -
18855 - .section .bss, "aw", @nobits
18856 +
18857 + .section .rodata,"a",@progbits
18858 .align L1_CACHE_BYTES
18859 ENTRY(idt_table)
18860 - .skip IDT_ENTRIES * 16
18861 + .fill 512,8,0
18862
18863 .align L1_CACHE_BYTES
18864 ENTRY(nmi_idt_table)
18865 - .skip IDT_ENTRIES * 16
18866 + .fill 512,8,0
18867
18868 __PAGE_ALIGNED_BSS
18869 .align PAGE_SIZE
18870 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18871 index 9c3bd4a..e1d9b35 100644
18872 --- a/arch/x86/kernel/i386_ksyms_32.c
18873 +++ b/arch/x86/kernel/i386_ksyms_32.c
18874 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18875 EXPORT_SYMBOL(cmpxchg8b_emu);
18876 #endif
18877
18878 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18879 +
18880 /* Networking helper routines. */
18881 EXPORT_SYMBOL(csum_partial_copy_generic);
18882 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18883 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18884
18885 EXPORT_SYMBOL(__get_user_1);
18886 EXPORT_SYMBOL(__get_user_2);
18887 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18888
18889 EXPORT_SYMBOL(csum_partial);
18890 EXPORT_SYMBOL(empty_zero_page);
18891 +
18892 +#ifdef CONFIG_PAX_KERNEXEC
18893 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18894 +#endif
18895 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18896 index 675a050..95febfd 100644
18897 --- a/arch/x86/kernel/i387.c
18898 +++ b/arch/x86/kernel/i387.c
18899 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18900 static inline bool interrupted_user_mode(void)
18901 {
18902 struct pt_regs *regs = get_irq_regs();
18903 - return regs && user_mode_vm(regs);
18904 + return regs && user_mode(regs);
18905 }
18906
18907 /*
18908 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18909 index 9a5c460..dc4374d 100644
18910 --- a/arch/x86/kernel/i8259.c
18911 +++ b/arch/x86/kernel/i8259.c
18912 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18913 "spurious 8259A interrupt: IRQ%d.\n", irq);
18914 spurious_irq_mask |= irqmask;
18915 }
18916 - atomic_inc(&irq_err_count);
18917 + atomic_inc_unchecked(&irq_err_count);
18918 /*
18919 * Theoretically we do not have to handle this IRQ,
18920 * but in Linux this does not cause problems and is
18921 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18922 index 8c96897..be66bfa 100644
18923 --- a/arch/x86/kernel/ioport.c
18924 +++ b/arch/x86/kernel/ioport.c
18925 @@ -6,6 +6,7 @@
18926 #include <linux/sched.h>
18927 #include <linux/kernel.h>
18928 #include <linux/capability.h>
18929 +#include <linux/security.h>
18930 #include <linux/errno.h>
18931 #include <linux/types.h>
18932 #include <linux/ioport.h>
18933 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18934
18935 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18936 return -EINVAL;
18937 +#ifdef CONFIG_GRKERNSEC_IO
18938 + if (turn_on && grsec_disable_privio) {
18939 + gr_handle_ioperm();
18940 + return -EPERM;
18941 + }
18942 +#endif
18943 if (turn_on && !capable(CAP_SYS_RAWIO))
18944 return -EPERM;
18945
18946 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18947 * because the ->io_bitmap_max value must match the bitmap
18948 * contents:
18949 */
18950 - tss = &per_cpu(init_tss, get_cpu());
18951 + tss = init_tss + get_cpu();
18952
18953 if (turn_on)
18954 bitmap_clear(t->io_bitmap_ptr, from, num);
18955 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18956 return -EINVAL;
18957 /* Trying to gain more privileges? */
18958 if (level > old) {
18959 +#ifdef CONFIG_GRKERNSEC_IO
18960 + if (grsec_disable_privio) {
18961 + gr_handle_iopl();
18962 + return -EPERM;
18963 + }
18964 +#endif
18965 if (!capable(CAP_SYS_RAWIO))
18966 return -EPERM;
18967 }
18968 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18969 index e4595f1..ee3bfb8 100644
18970 --- a/arch/x86/kernel/irq.c
18971 +++ b/arch/x86/kernel/irq.c
18972 @@ -18,7 +18,7 @@
18973 #include <asm/mce.h>
18974 #include <asm/hw_irq.h>
18975
18976 -atomic_t irq_err_count;
18977 +atomic_unchecked_t irq_err_count;
18978
18979 /* Function pointer for generic interrupt vector handling */
18980 void (*x86_platform_ipi_callback)(void) = NULL;
18981 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18982 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18983 seq_printf(p, " Machine check polls\n");
18984 #endif
18985 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18986 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18987 #if defined(CONFIG_X86_IO_APIC)
18988 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18989 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18990 #endif
18991 return 0;
18992 }
18993 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18994
18995 u64 arch_irq_stat(void)
18996 {
18997 - u64 sum = atomic_read(&irq_err_count);
18998 + u64 sum = atomic_read_unchecked(&irq_err_count);
18999
19000 #ifdef CONFIG_X86_IO_APIC
19001 - sum += atomic_read(&irq_mis_count);
19002 + sum += atomic_read_unchecked(&irq_mis_count);
19003 #endif
19004 return sum;
19005 }
19006 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
19007 index 344faf8..355f60d 100644
19008 --- a/arch/x86/kernel/irq_32.c
19009 +++ b/arch/x86/kernel/irq_32.c
19010 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
19011 __asm__ __volatile__("andl %%esp,%0" :
19012 "=r" (sp) : "0" (THREAD_SIZE - 1));
19013
19014 - return sp < (sizeof(struct thread_info) + STACK_WARN);
19015 + return sp < STACK_WARN;
19016 }
19017
19018 static void print_stack_overflow(void)
19019 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
19020 * per-CPU IRQ handling contexts (thread information and stack)
19021 */
19022 union irq_ctx {
19023 - struct thread_info tinfo;
19024 - u32 stack[THREAD_SIZE/sizeof(u32)];
19025 + unsigned long previous_esp;
19026 + u32 stack[THREAD_SIZE/sizeof(u32)];
19027 } __attribute__((aligned(THREAD_SIZE)));
19028
19029 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
19030 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
19031 static inline int
19032 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19033 {
19034 - union irq_ctx *curctx, *irqctx;
19035 + union irq_ctx *irqctx;
19036 u32 *isp, arg1, arg2;
19037
19038 - curctx = (union irq_ctx *) current_thread_info();
19039 irqctx = __this_cpu_read(hardirq_ctx);
19040
19041 /*
19042 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19043 * handler) we can't do that and just have to keep using the
19044 * current stack (which is the irq stack already after all)
19045 */
19046 - if (unlikely(curctx == irqctx))
19047 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
19048 return 0;
19049
19050 /* build the stack frame on the IRQ stack */
19051 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19052 - irqctx->tinfo.task = curctx->tinfo.task;
19053 - irqctx->tinfo.previous_esp = current_stack_pointer;
19054 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19055 + irqctx->previous_esp = current_stack_pointer;
19056
19057 - /* Copy the preempt_count so that the [soft]irq checks work. */
19058 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
19059 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19060 + __set_fs(MAKE_MM_SEG(0));
19061 +#endif
19062
19063 if (unlikely(overflow))
19064 call_on_stack(print_stack_overflow, isp);
19065 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19066 : "0" (irq), "1" (desc), "2" (isp),
19067 "D" (desc->handle_irq)
19068 : "memory", "cc", "ecx");
19069 +
19070 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19071 + __set_fs(current_thread_info()->addr_limit);
19072 +#endif
19073 +
19074 return 1;
19075 }
19076
19077 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19078 */
19079 void __cpuinit irq_ctx_init(int cpu)
19080 {
19081 - union irq_ctx *irqctx;
19082 -
19083 if (per_cpu(hardirq_ctx, cpu))
19084 return;
19085
19086 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19087 - THREADINFO_GFP,
19088 - THREAD_SIZE_ORDER));
19089 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19090 - irqctx->tinfo.cpu = cpu;
19091 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
19092 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19093 -
19094 - per_cpu(hardirq_ctx, cpu) = irqctx;
19095 -
19096 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19097 - THREADINFO_GFP,
19098 - THREAD_SIZE_ORDER));
19099 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19100 - irqctx->tinfo.cpu = cpu;
19101 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19102 -
19103 - per_cpu(softirq_ctx, cpu) = irqctx;
19104 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19105 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19106 +
19107 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19108 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19109
19110 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19111 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19112 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19113 asmlinkage void do_softirq(void)
19114 {
19115 unsigned long flags;
19116 - struct thread_info *curctx;
19117 union irq_ctx *irqctx;
19118 u32 *isp;
19119
19120 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19121 local_irq_save(flags);
19122
19123 if (local_softirq_pending()) {
19124 - curctx = current_thread_info();
19125 irqctx = __this_cpu_read(softirq_ctx);
19126 - irqctx->tinfo.task = curctx->task;
19127 - irqctx->tinfo.previous_esp = current_stack_pointer;
19128 + irqctx->previous_esp = current_stack_pointer;
19129
19130 /* build the stack frame on the softirq stack */
19131 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19132 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19133 +
19134 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19135 + __set_fs(MAKE_MM_SEG(0));
19136 +#endif
19137
19138 call_on_stack(__do_softirq, isp);
19139 +
19140 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19141 + __set_fs(current_thread_info()->addr_limit);
19142 +#endif
19143 +
19144 /*
19145 * Shouldn't happen, we returned above if in_interrupt():
19146 */
19147 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19148 if (unlikely(!desc))
19149 return false;
19150
19151 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19152 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19153 if (unlikely(overflow))
19154 print_stack_overflow();
19155 desc->handle_irq(irq, desc);
19156 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19157 index d04d3ec..ea4b374 100644
19158 --- a/arch/x86/kernel/irq_64.c
19159 +++ b/arch/x86/kernel/irq_64.c
19160 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19161 u64 estack_top, estack_bottom;
19162 u64 curbase = (u64)task_stack_page(current);
19163
19164 - if (user_mode_vm(regs))
19165 + if (user_mode(regs))
19166 return;
19167
19168 if (regs->sp >= curbase + sizeof(struct thread_info) +
19169 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19170 index dc1404b..bbc43e7 100644
19171 --- a/arch/x86/kernel/kdebugfs.c
19172 +++ b/arch/x86/kernel/kdebugfs.c
19173 @@ -27,7 +27,7 @@ struct setup_data_node {
19174 u32 len;
19175 };
19176
19177 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19178 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19179 size_t count, loff_t *ppos)
19180 {
19181 struct setup_data_node *node = file->private_data;
19182 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19183 index 836f832..a8bda67 100644
19184 --- a/arch/x86/kernel/kgdb.c
19185 +++ b/arch/x86/kernel/kgdb.c
19186 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19187 #ifdef CONFIG_X86_32
19188 switch (regno) {
19189 case GDB_SS:
19190 - if (!user_mode_vm(regs))
19191 + if (!user_mode(regs))
19192 *(unsigned long *)mem = __KERNEL_DS;
19193 break;
19194 case GDB_SP:
19195 - if (!user_mode_vm(regs))
19196 + if (!user_mode(regs))
19197 *(unsigned long *)mem = kernel_stack_pointer(regs);
19198 break;
19199 case GDB_GS:
19200 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19201 bp->attr.bp_addr = breakinfo[breakno].addr;
19202 bp->attr.bp_len = breakinfo[breakno].len;
19203 bp->attr.bp_type = breakinfo[breakno].type;
19204 - info->address = breakinfo[breakno].addr;
19205 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19206 + info->address = ktla_ktva(breakinfo[breakno].addr);
19207 + else
19208 + info->address = breakinfo[breakno].addr;
19209 info->len = breakinfo[breakno].len;
19210 info->type = breakinfo[breakno].type;
19211 val = arch_install_hw_breakpoint(bp);
19212 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19213 case 'k':
19214 /* clear the trace bit */
19215 linux_regs->flags &= ~X86_EFLAGS_TF;
19216 - atomic_set(&kgdb_cpu_doing_single_step, -1);
19217 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19218
19219 /* set the trace bit if we're stepping */
19220 if (remcomInBuffer[0] == 's') {
19221 linux_regs->flags |= X86_EFLAGS_TF;
19222 - atomic_set(&kgdb_cpu_doing_single_step,
19223 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19224 raw_smp_processor_id());
19225 }
19226
19227 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19228
19229 switch (cmd) {
19230 case DIE_DEBUG:
19231 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19232 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19233 if (user_mode(regs))
19234 return single_step_cont(regs, args);
19235 break;
19236 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19237 #endif /* CONFIG_DEBUG_RODATA */
19238
19239 bpt->type = BP_BREAKPOINT;
19240 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19241 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19242 BREAK_INSTR_SIZE);
19243 if (err)
19244 return err;
19245 - err = probe_kernel_write((char *)bpt->bpt_addr,
19246 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19247 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19248 #ifdef CONFIG_DEBUG_RODATA
19249 if (!err)
19250 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19251 return -EBUSY;
19252 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19253 BREAK_INSTR_SIZE);
19254 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19255 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19256 if (err)
19257 return err;
19258 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19259 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19260 if (mutex_is_locked(&text_mutex))
19261 goto knl_write;
19262 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19263 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19264 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19265 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19266 goto knl_write;
19267 return err;
19268 knl_write:
19269 #endif /* CONFIG_DEBUG_RODATA */
19270 - return probe_kernel_write((char *)bpt->bpt_addr,
19271 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19272 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19273 }
19274
19275 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19276 index c5e410e..ed5a7f0 100644
19277 --- a/arch/x86/kernel/kprobes-opt.c
19278 +++ b/arch/x86/kernel/kprobes-opt.c
19279 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19280 * Verify if the address gap is in 2GB range, because this uses
19281 * a relative jump.
19282 */
19283 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19284 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19285 if (abs(rel) > 0x7fffffff)
19286 return -ERANGE;
19287
19288 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19289 op->optinsn.size = ret;
19290
19291 /* Copy arch-dep-instance from template */
19292 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19293 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19294
19295 /* Set probe information */
19296 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19297
19298 /* Set probe function call */
19299 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19300 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19301
19302 /* Set returning jmp instruction at the tail of out-of-line buffer */
19303 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19304 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19305 (u8 *)op->kp.addr + op->optinsn.size);
19306
19307 flush_icache_range((unsigned long) buf,
19308 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19309 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19310
19311 /* Backup instructions which will be replaced by jump address */
19312 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19313 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19314 RELATIVE_ADDR_SIZE);
19315
19316 insn_buf[0] = RELATIVEJUMP_OPCODE;
19317 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19318 /* This kprobe is really able to run optimized path. */
19319 op = container_of(p, struct optimized_kprobe, kp);
19320 /* Detour through copied instructions */
19321 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19322 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19323 if (!reenter)
19324 reset_current_kprobe();
19325 preempt_enable_no_resched();
19326 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19327 index 57916c0..9e0b9d0 100644
19328 --- a/arch/x86/kernel/kprobes.c
19329 +++ b/arch/x86/kernel/kprobes.c
19330 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19331 s32 raddr;
19332 } __attribute__((packed)) *insn;
19333
19334 - insn = (struct __arch_relative_insn *)from;
19335 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
19336 +
19337 + pax_open_kernel();
19338 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19339 insn->op = op;
19340 + pax_close_kernel();
19341 }
19342
19343 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19344 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19345 kprobe_opcode_t opcode;
19346 kprobe_opcode_t *orig_opcodes = opcodes;
19347
19348 - if (search_exception_tables((unsigned long)opcodes))
19349 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19350 return 0; /* Page fault may occur on this address. */
19351
19352 retry:
19353 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19354 * for the first byte, we can recover the original instruction
19355 * from it and kp->opcode.
19356 */
19357 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19358 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19359 buf[0] = kp->opcode;
19360 - return (unsigned long)buf;
19361 + return ktva_ktla((unsigned long)buf);
19362 }
19363
19364 /*
19365 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19366 /* Another subsystem puts a breakpoint, failed to recover */
19367 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19368 return 0;
19369 + pax_open_kernel();
19370 memcpy(dest, insn.kaddr, insn.length);
19371 + pax_close_kernel();
19372
19373 #ifdef CONFIG_X86_64
19374 if (insn_rip_relative(&insn)) {
19375 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19376 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19377 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19378 disp = (u8 *) dest + insn_offset_displacement(&insn);
19379 + pax_open_kernel();
19380 *(s32 *) disp = (s32) newdisp;
19381 + pax_close_kernel();
19382 }
19383 #endif
19384 return insn.length;
19385 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19386 * nor set current_kprobe, because it doesn't use single
19387 * stepping.
19388 */
19389 - regs->ip = (unsigned long)p->ainsn.insn;
19390 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19391 preempt_enable_no_resched();
19392 return;
19393 }
19394 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19395 regs->flags &= ~X86_EFLAGS_IF;
19396 /* single step inline if the instruction is an int3 */
19397 if (p->opcode == BREAKPOINT_INSTRUCTION)
19398 - regs->ip = (unsigned long)p->addr;
19399 + regs->ip = ktla_ktva((unsigned long)p->addr);
19400 else
19401 - regs->ip = (unsigned long)p->ainsn.insn;
19402 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19403 }
19404
19405 /*
19406 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19407 setup_singlestep(p, regs, kcb, 0);
19408 return 1;
19409 }
19410 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19411 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19412 /*
19413 * The breakpoint instruction was removed right
19414 * after we hit it. Another cpu has removed
19415 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19416 " movq %rax, 152(%rsp)\n"
19417 RESTORE_REGS_STRING
19418 " popfq\n"
19419 +#ifdef KERNEXEC_PLUGIN
19420 + " btsq $63,(%rsp)\n"
19421 +#endif
19422 #else
19423 " pushf\n"
19424 SAVE_REGS_STRING
19425 @@ -788,7 +798,7 @@ static void __kprobes
19426 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19427 {
19428 unsigned long *tos = stack_addr(regs);
19429 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19430 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19431 unsigned long orig_ip = (unsigned long)p->addr;
19432 kprobe_opcode_t *insn = p->ainsn.insn;
19433
19434 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19435 struct die_args *args = data;
19436 int ret = NOTIFY_DONE;
19437
19438 - if (args->regs && user_mode_vm(args->regs))
19439 + if (args->regs && user_mode(args->regs))
19440 return ret;
19441
19442 switch (val) {
19443 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19444 index ebc9873..1b9724b 100644
19445 --- a/arch/x86/kernel/ldt.c
19446 +++ b/arch/x86/kernel/ldt.c
19447 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19448 if (reload) {
19449 #ifdef CONFIG_SMP
19450 preempt_disable();
19451 - load_LDT(pc);
19452 + load_LDT_nolock(pc);
19453 if (!cpumask_equal(mm_cpumask(current->mm),
19454 cpumask_of(smp_processor_id())))
19455 smp_call_function(flush_ldt, current->mm, 1);
19456 preempt_enable();
19457 #else
19458 - load_LDT(pc);
19459 + load_LDT_nolock(pc);
19460 #endif
19461 }
19462 if (oldsize) {
19463 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19464 return err;
19465
19466 for (i = 0; i < old->size; i++)
19467 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19468 + write_ldt_entry(new->ldt, i, old->ldt + i);
19469 return 0;
19470 }
19471
19472 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19473 retval = copy_ldt(&mm->context, &old_mm->context);
19474 mutex_unlock(&old_mm->context.lock);
19475 }
19476 +
19477 + if (tsk == current) {
19478 + mm->context.vdso = 0;
19479 +
19480 +#ifdef CONFIG_X86_32
19481 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19482 + mm->context.user_cs_base = 0UL;
19483 + mm->context.user_cs_limit = ~0UL;
19484 +
19485 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19486 + cpus_clear(mm->context.cpu_user_cs_mask);
19487 +#endif
19488 +
19489 +#endif
19490 +#endif
19491 +
19492 + }
19493 +
19494 return retval;
19495 }
19496
19497 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19498 }
19499 }
19500
19501 +#ifdef CONFIG_PAX_SEGMEXEC
19502 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19503 + error = -EINVAL;
19504 + goto out_unlock;
19505 + }
19506 +#endif
19507 +
19508 fill_ldt(&ldt, &ldt_info);
19509 if (oldmode)
19510 ldt.avl = 0;
19511 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19512 index 5b19e4d..6476a76 100644
19513 --- a/arch/x86/kernel/machine_kexec_32.c
19514 +++ b/arch/x86/kernel/machine_kexec_32.c
19515 @@ -26,7 +26,7 @@
19516 #include <asm/cacheflush.h>
19517 #include <asm/debugreg.h>
19518
19519 -static void set_idt(void *newidt, __u16 limit)
19520 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19521 {
19522 struct desc_ptr curidt;
19523
19524 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19525 }
19526
19527
19528 -static void set_gdt(void *newgdt, __u16 limit)
19529 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19530 {
19531 struct desc_ptr curgdt;
19532
19533 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19534 }
19535
19536 control_page = page_address(image->control_code_page);
19537 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19538 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19539
19540 relocate_kernel_ptr = control_page;
19541 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19542 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19543 index 3544aed..01ddc1c 100644
19544 --- a/arch/x86/kernel/microcode_intel.c
19545 +++ b/arch/x86/kernel/microcode_intel.c
19546 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19547
19548 static int get_ucode_user(void *to, const void *from, size_t n)
19549 {
19550 - return copy_from_user(to, from, n);
19551 + return copy_from_user(to, (const void __force_user *)from, n);
19552 }
19553
19554 static enum ucode_state
19555 request_microcode_user(int cpu, const void __user *buf, size_t size)
19556 {
19557 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19558 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19559 }
19560
19561 static void microcode_fini_cpu(int cpu)
19562 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19563 index 216a4d7..228255a 100644
19564 --- a/arch/x86/kernel/module.c
19565 +++ b/arch/x86/kernel/module.c
19566 @@ -43,15 +43,60 @@ do { \
19567 } while (0)
19568 #endif
19569
19570 -void *module_alloc(unsigned long size)
19571 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19572 {
19573 - if (PAGE_ALIGN(size) > MODULES_LEN)
19574 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
19575 return NULL;
19576 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19577 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19578 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19579 -1, __builtin_return_address(0));
19580 }
19581
19582 +void *module_alloc(unsigned long size)
19583 +{
19584 +
19585 +#ifdef CONFIG_PAX_KERNEXEC
19586 + return __module_alloc(size, PAGE_KERNEL);
19587 +#else
19588 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19589 +#endif
19590 +
19591 +}
19592 +
19593 +#ifdef CONFIG_PAX_KERNEXEC
19594 +#ifdef CONFIG_X86_32
19595 +void *module_alloc_exec(unsigned long size)
19596 +{
19597 + struct vm_struct *area;
19598 +
19599 + if (size == 0)
19600 + return NULL;
19601 +
19602 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19603 + return area ? area->addr : NULL;
19604 +}
19605 +EXPORT_SYMBOL(module_alloc_exec);
19606 +
19607 +void module_free_exec(struct module *mod, void *module_region)
19608 +{
19609 + vunmap(module_region);
19610 +}
19611 +EXPORT_SYMBOL(module_free_exec);
19612 +#else
19613 +void module_free_exec(struct module *mod, void *module_region)
19614 +{
19615 + module_free(mod, module_region);
19616 +}
19617 +EXPORT_SYMBOL(module_free_exec);
19618 +
19619 +void *module_alloc_exec(unsigned long size)
19620 +{
19621 + return __module_alloc(size, PAGE_KERNEL_RX);
19622 +}
19623 +EXPORT_SYMBOL(module_alloc_exec);
19624 +#endif
19625 +#endif
19626 +
19627 #ifdef CONFIG_X86_32
19628 int apply_relocate(Elf32_Shdr *sechdrs,
19629 const char *strtab,
19630 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19631 unsigned int i;
19632 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19633 Elf32_Sym *sym;
19634 - uint32_t *location;
19635 + uint32_t *plocation, location;
19636
19637 DEBUGP("Applying relocate section %u to %u\n",
19638 relsec, sechdrs[relsec].sh_info);
19639 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19640 /* This is where to make the change */
19641 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19642 - + rel[i].r_offset;
19643 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19644 + location = (uint32_t)plocation;
19645 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19646 + plocation = ktla_ktva((void *)plocation);
19647 /* This is the symbol it is referring to. Note that all
19648 undefined symbols have been resolved. */
19649 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19650 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19651 switch (ELF32_R_TYPE(rel[i].r_info)) {
19652 case R_386_32:
19653 /* We add the value into the location given */
19654 - *location += sym->st_value;
19655 + pax_open_kernel();
19656 + *plocation += sym->st_value;
19657 + pax_close_kernel();
19658 break;
19659 case R_386_PC32:
19660 /* Add the value, subtract its position */
19661 - *location += sym->st_value - (uint32_t)location;
19662 + pax_open_kernel();
19663 + *plocation += sym->st_value - location;
19664 + pax_close_kernel();
19665 break;
19666 default:
19667 pr_err("%s: Unknown relocation: %u\n",
19668 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19669 case R_X86_64_NONE:
19670 break;
19671 case R_X86_64_64:
19672 + pax_open_kernel();
19673 *(u64 *)loc = val;
19674 + pax_close_kernel();
19675 break;
19676 case R_X86_64_32:
19677 + pax_open_kernel();
19678 *(u32 *)loc = val;
19679 + pax_close_kernel();
19680 if (val != *(u32 *)loc)
19681 goto overflow;
19682 break;
19683 case R_X86_64_32S:
19684 + pax_open_kernel();
19685 *(s32 *)loc = val;
19686 + pax_close_kernel();
19687 if ((s64)val != *(s32 *)loc)
19688 goto overflow;
19689 break;
19690 case R_X86_64_PC32:
19691 val -= (u64)loc;
19692 + pax_open_kernel();
19693 *(u32 *)loc = val;
19694 + pax_close_kernel();
19695 +
19696 #if 0
19697 if ((s64)val != *(s32 *)loc)
19698 goto overflow;
19699 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19700 index f84f5c5..e27e54b 100644
19701 --- a/arch/x86/kernel/nmi.c
19702 +++ b/arch/x86/kernel/nmi.c
19703 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19704 dotraplinkage notrace __kprobes void
19705 do_nmi(struct pt_regs *regs, long error_code)
19706 {
19707 +
19708 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19709 + if (!user_mode(regs)) {
19710 + unsigned long cs = regs->cs & 0xFFFF;
19711 + unsigned long ip = ktva_ktla(regs->ip);
19712 +
19713 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19714 + regs->ip = ip;
19715 + }
19716 +#endif
19717 +
19718 nmi_nesting_preprocess(regs);
19719
19720 nmi_enter();
19721 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19722 index 676b8c7..870ba04 100644
19723 --- a/arch/x86/kernel/paravirt-spinlocks.c
19724 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19725 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19726 arch_spin_lock(lock);
19727 }
19728
19729 -struct pv_lock_ops pv_lock_ops = {
19730 +struct pv_lock_ops pv_lock_ops __read_only = {
19731 #ifdef CONFIG_SMP
19732 .spin_is_locked = __ticket_spin_is_locked,
19733 .spin_is_contended = __ticket_spin_is_contended,
19734 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19735 index 17fff18..5cfa0f4 100644
19736 --- a/arch/x86/kernel/paravirt.c
19737 +++ b/arch/x86/kernel/paravirt.c
19738 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19739 {
19740 return x;
19741 }
19742 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19743 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19744 +#endif
19745
19746 void __init default_banner(void)
19747 {
19748 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19749 if (opfunc == NULL)
19750 /* If there's no function, patch it with a ud2a (BUG) */
19751 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19752 - else if (opfunc == _paravirt_nop)
19753 + else if (opfunc == (void *)_paravirt_nop)
19754 /* If the operation is a nop, then nop the callsite */
19755 ret = paravirt_patch_nop();
19756
19757 /* identity functions just return their single argument */
19758 - else if (opfunc == _paravirt_ident_32)
19759 + else if (opfunc == (void *)_paravirt_ident_32)
19760 ret = paravirt_patch_ident_32(insnbuf, len);
19761 - else if (opfunc == _paravirt_ident_64)
19762 + else if (opfunc == (void *)_paravirt_ident_64)
19763 ret = paravirt_patch_ident_64(insnbuf, len);
19764 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19765 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19766 + ret = paravirt_patch_ident_64(insnbuf, len);
19767 +#endif
19768
19769 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19770 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19771 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19772 if (insn_len > len || start == NULL)
19773 insn_len = len;
19774 else
19775 - memcpy(insnbuf, start, insn_len);
19776 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19777
19778 return insn_len;
19779 }
19780 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19781 preempt_enable();
19782 }
19783
19784 -struct pv_info pv_info = {
19785 +struct pv_info pv_info __read_only = {
19786 .name = "bare hardware",
19787 .paravirt_enabled = 0,
19788 .kernel_rpl = 0,
19789 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
19790 #endif
19791 };
19792
19793 -struct pv_init_ops pv_init_ops = {
19794 +struct pv_init_ops pv_init_ops __read_only = {
19795 .patch = native_patch,
19796 };
19797
19798 -struct pv_time_ops pv_time_ops = {
19799 +struct pv_time_ops pv_time_ops __read_only = {
19800 .sched_clock = native_sched_clock,
19801 .steal_clock = native_steal_clock,
19802 };
19803
19804 -struct pv_irq_ops pv_irq_ops = {
19805 +struct pv_irq_ops pv_irq_ops __read_only = {
19806 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19807 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19808 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19809 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
19810 #endif
19811 };
19812
19813 -struct pv_cpu_ops pv_cpu_ops = {
19814 +struct pv_cpu_ops pv_cpu_ops __read_only = {
19815 .cpuid = native_cpuid,
19816 .get_debugreg = native_get_debugreg,
19817 .set_debugreg = native_set_debugreg,
19818 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
19819 .end_context_switch = paravirt_nop,
19820 };
19821
19822 -struct pv_apic_ops pv_apic_ops = {
19823 +struct pv_apic_ops pv_apic_ops __read_only= {
19824 #ifdef CONFIG_X86_LOCAL_APIC
19825 .startup_ipi_hook = paravirt_nop,
19826 #endif
19827 };
19828
19829 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19830 +#ifdef CONFIG_X86_32
19831 +#ifdef CONFIG_X86_PAE
19832 +/* 64-bit pagetable entries */
19833 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19834 +#else
19835 /* 32-bit pagetable entries */
19836 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19837 +#endif
19838 #else
19839 /* 64-bit pagetable entries */
19840 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19841 #endif
19842
19843 -struct pv_mmu_ops pv_mmu_ops = {
19844 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19845
19846 .read_cr2 = native_read_cr2,
19847 .write_cr2 = native_write_cr2,
19848 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19849 .make_pud = PTE_IDENT,
19850
19851 .set_pgd = native_set_pgd,
19852 + .set_pgd_batched = native_set_pgd_batched,
19853 #endif
19854 #endif /* PAGETABLE_LEVELS >= 3 */
19855
19856 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19857 },
19858
19859 .set_fixmap = native_set_fixmap,
19860 +
19861 +#ifdef CONFIG_PAX_KERNEXEC
19862 + .pax_open_kernel = native_pax_open_kernel,
19863 + .pax_close_kernel = native_pax_close_kernel,
19864 +#endif
19865 +
19866 };
19867
19868 EXPORT_SYMBOL_GPL(pv_time_ops);
19869 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19870 index 35ccf75..7a15747 100644
19871 --- a/arch/x86/kernel/pci-iommu_table.c
19872 +++ b/arch/x86/kernel/pci-iommu_table.c
19873 @@ -2,7 +2,7 @@
19874 #include <asm/iommu_table.h>
19875 #include <linux/string.h>
19876 #include <linux/kallsyms.h>
19877 -
19878 +#include <linux/sched.h>
19879
19880 #define DEBUG 1
19881
19882 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19883 index b644e1c..4a6d379 100644
19884 --- a/arch/x86/kernel/process.c
19885 +++ b/arch/x86/kernel/process.c
19886 @@ -36,7 +36,8 @@
19887 * section. Since TSS's are completely CPU-local, we want them
19888 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19889 */
19890 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19891 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19892 +EXPORT_SYMBOL(init_tss);
19893
19894 #ifdef CONFIG_X86_64
19895 static DEFINE_PER_CPU(unsigned char, is_idle);
19896 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19897 task_xstate_cachep =
19898 kmem_cache_create("task_xstate", xstate_size,
19899 __alignof__(union thread_xstate),
19900 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19901 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19902 }
19903
19904 /*
19905 @@ -105,7 +106,7 @@ void exit_thread(void)
19906 unsigned long *bp = t->io_bitmap_ptr;
19907
19908 if (bp) {
19909 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19910 + struct tss_struct *tss = init_tss + get_cpu();
19911
19912 t->io_bitmap_ptr = NULL;
19913 clear_thread_flag(TIF_IO_BITMAP);
19914 @@ -136,7 +137,7 @@ void show_regs_common(void)
19915 board = dmi_get_system_info(DMI_BOARD_NAME);
19916
19917 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19918 - current->pid, current->comm, print_tainted(),
19919 + task_pid_nr(current), current->comm, print_tainted(),
19920 init_utsname()->release,
19921 (int)strcspn(init_utsname()->version, " "),
19922 init_utsname()->version,
19923 @@ -149,6 +150,9 @@ void flush_thread(void)
19924 {
19925 struct task_struct *tsk = current;
19926
19927 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19928 + loadsegment(gs, 0);
19929 +#endif
19930 flush_ptrace_hw_breakpoint(tsk);
19931 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19932 drop_init_fpu(tsk);
19933 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19934 void exit_idle(void)
19935 {
19936 /* idle loop has pid 0 */
19937 - if (current->pid)
19938 + if (task_pid_nr(current))
19939 return;
19940 __exit_idle();
19941 }
19942 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19943
19944 return ret;
19945 }
19946 -void stop_this_cpu(void *dummy)
19947 +__noreturn void stop_this_cpu(void *dummy)
19948 {
19949 local_irq_disable();
19950 /*
19951 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19952 }
19953 early_param("idle", idle_setup);
19954
19955 -unsigned long arch_align_stack(unsigned long sp)
19956 +#ifdef CONFIG_PAX_RANDKSTACK
19957 +void pax_randomize_kstack(struct pt_regs *regs)
19958 {
19959 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19960 - sp -= get_random_int() % 8192;
19961 - return sp & ~0xf;
19962 -}
19963 + struct thread_struct *thread = &current->thread;
19964 + unsigned long time;
19965
19966 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19967 -{
19968 - unsigned long range_end = mm->brk + 0x02000000;
19969 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19970 -}
19971 + if (!randomize_va_space)
19972 + return;
19973 +
19974 + if (v8086_mode(regs))
19975 + return;
19976
19977 + rdtscl(time);
19978 +
19979 + /* P4 seems to return a 0 LSB, ignore it */
19980 +#ifdef CONFIG_MPENTIUM4
19981 + time &= 0x3EUL;
19982 + time <<= 2;
19983 +#elif defined(CONFIG_X86_64)
19984 + time &= 0xFUL;
19985 + time <<= 4;
19986 +#else
19987 + time &= 0x1FUL;
19988 + time <<= 3;
19989 +#endif
19990 +
19991 + thread->sp0 ^= time;
19992 + load_sp0(init_tss + smp_processor_id(), thread);
19993 +
19994 +#ifdef CONFIG_X86_64
19995 + this_cpu_write(kernel_stack, thread->sp0);
19996 +#endif
19997 +}
19998 +#endif
19999 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
20000 index 44e0bff..5ceb99c 100644
20001 --- a/arch/x86/kernel/process_32.c
20002 +++ b/arch/x86/kernel/process_32.c
20003 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
20004 unsigned long thread_saved_pc(struct task_struct *tsk)
20005 {
20006 return ((unsigned long *)tsk->thread.sp)[3];
20007 +//XXX return tsk->thread.eip;
20008 }
20009
20010 void __show_regs(struct pt_regs *regs, int all)
20011 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
20012 unsigned long sp;
20013 unsigned short ss, gs;
20014
20015 - if (user_mode_vm(regs)) {
20016 + if (user_mode(regs)) {
20017 sp = regs->sp;
20018 ss = regs->ss & 0xffff;
20019 - gs = get_user_gs(regs);
20020 } else {
20021 sp = kernel_stack_pointer(regs);
20022 savesegment(ss, ss);
20023 - savesegment(gs, gs);
20024 }
20025 + gs = get_user_gs(regs);
20026
20027 show_regs_common();
20028
20029 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
20030 (u16)regs->cs, regs->ip, regs->flags,
20031 - smp_processor_id());
20032 + raw_smp_processor_id());
20033 print_symbol("EIP is at %s\n", regs->ip);
20034
20035 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
20036 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20037 unsigned long arg,
20038 struct task_struct *p, struct pt_regs *regs)
20039 {
20040 - struct pt_regs *childregs = task_pt_regs(p);
20041 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
20042 struct task_struct *tsk;
20043 int err;
20044
20045 p->thread.sp = (unsigned long) childregs;
20046 p->thread.sp0 = (unsigned long) (childregs+1);
20047 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20048
20049 if (unlikely(!regs)) {
20050 /* kernel thread */
20051 memset(childregs, 0, sizeof(struct pt_regs));
20052 p->thread.ip = (unsigned long) ret_from_kernel_thread;
20053 - task_user_gs(p) = __KERNEL_STACK_CANARY;
20054 - childregs->ds = __USER_DS;
20055 - childregs->es = __USER_DS;
20056 + savesegment(gs, childregs->gs);
20057 + childregs->ds = __KERNEL_DS;
20058 + childregs->es = __KERNEL_DS;
20059 childregs->fs = __KERNEL_PERCPU;
20060 childregs->bx = sp; /* function */
20061 childregs->bp = arg;
20062 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20063 struct thread_struct *prev = &prev_p->thread,
20064 *next = &next_p->thread;
20065 int cpu = smp_processor_id();
20066 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20067 + struct tss_struct *tss = init_tss + cpu;
20068 fpu_switch_t fpu;
20069
20070 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20071 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20072 */
20073 lazy_save_gs(prev->gs);
20074
20075 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20076 + __set_fs(task_thread_info(next_p)->addr_limit);
20077 +#endif
20078 +
20079 /*
20080 * Load the per-thread Thread-Local Storage descriptor.
20081 */
20082 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20083 */
20084 arch_end_context_switch(next_p);
20085
20086 + this_cpu_write(current_task, next_p);
20087 + this_cpu_write(current_tinfo, &next_p->tinfo);
20088 +
20089 /*
20090 * Restore %gs if needed (which is common)
20091 */
20092 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20093
20094 switch_fpu_finish(next_p, fpu);
20095
20096 - this_cpu_write(current_task, next_p);
20097 -
20098 return prev_p;
20099 }
20100
20101 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20102 } while (count++ < 16);
20103 return 0;
20104 }
20105 -
20106 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20107 index 16c6365..5d32218 100644
20108 --- a/arch/x86/kernel/process_64.c
20109 +++ b/arch/x86/kernel/process_64.c
20110 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20111 struct pt_regs *childregs;
20112 struct task_struct *me = current;
20113
20114 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20115 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20116 childregs = task_pt_regs(p);
20117 p->thread.sp = (unsigned long) childregs;
20118 p->thread.usersp = me->thread.usersp;
20119 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20120 set_tsk_thread_flag(p, TIF_FORK);
20121 p->fpu_counter = 0;
20122 p->thread.io_bitmap_ptr = NULL;
20123 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20124 struct thread_struct *prev = &prev_p->thread;
20125 struct thread_struct *next = &next_p->thread;
20126 int cpu = smp_processor_id();
20127 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20128 + struct tss_struct *tss = init_tss + cpu;
20129 unsigned fsindex, gsindex;
20130 fpu_switch_t fpu;
20131
20132 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20133 prev->usersp = this_cpu_read(old_rsp);
20134 this_cpu_write(old_rsp, next->usersp);
20135 this_cpu_write(current_task, next_p);
20136 + this_cpu_write(current_tinfo, &next_p->tinfo);
20137
20138 - this_cpu_write(kernel_stack,
20139 - (unsigned long)task_stack_page(next_p) +
20140 - THREAD_SIZE - KERNEL_STACK_OFFSET);
20141 + this_cpu_write(kernel_stack, next->sp0);
20142
20143 /*
20144 * Now maybe reload the debug registers and handle I/O bitmaps
20145 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20146 if (!p || p == current || p->state == TASK_RUNNING)
20147 return 0;
20148 stack = (unsigned long)task_stack_page(p);
20149 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20150 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20151 return 0;
20152 fp = *(u64 *)(p->thread.sp);
20153 do {
20154 - if (fp < (unsigned long)stack ||
20155 - fp >= (unsigned long)stack+THREAD_SIZE)
20156 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20157 return 0;
20158 ip = *(u64 *)(fp+8);
20159 if (!in_sched_functions(ip))
20160 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20161 index 974b67e..53bdb6c 100644
20162 --- a/arch/x86/kernel/ptrace.c
20163 +++ b/arch/x86/kernel/ptrace.c
20164 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20165 {
20166 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20167 unsigned long sp = (unsigned long)&regs->sp;
20168 - struct thread_info *tinfo;
20169
20170 - if (context == (sp & ~(THREAD_SIZE - 1)))
20171 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20172 return sp;
20173
20174 - tinfo = (struct thread_info *)context;
20175 - if (tinfo->previous_esp)
20176 - return tinfo->previous_esp;
20177 + sp = *(unsigned long *)context;
20178 + if (sp)
20179 + return sp;
20180
20181 return (unsigned long)regs;
20182 }
20183 @@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20184 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20185 {
20186 int i;
20187 - int dr7 = 0;
20188 + unsigned long dr7 = 0;
20189 struct arch_hw_breakpoint *info;
20190
20191 for (i = 0; i < HBP_NUM; i++) {
20192 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20193 unsigned long addr, unsigned long data)
20194 {
20195 int ret;
20196 - unsigned long __user *datap = (unsigned long __user *)data;
20197 + unsigned long __user *datap = (__force unsigned long __user *)data;
20198
20199 switch (request) {
20200 /* read the word at location addr in the USER area. */
20201 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20202 if ((int) addr < 0)
20203 return -EIO;
20204 ret = do_get_thread_area(child, addr,
20205 - (struct user_desc __user *)data);
20206 + (__force struct user_desc __user *) data);
20207 break;
20208
20209 case PTRACE_SET_THREAD_AREA:
20210 if ((int) addr < 0)
20211 return -EIO;
20212 ret = do_set_thread_area(child, addr,
20213 - (struct user_desc __user *)data, 0);
20214 + (__force struct user_desc __user *) data, 0);
20215 break;
20216 #endif
20217
20218 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20219
20220 #ifdef CONFIG_X86_64
20221
20222 -static struct user_regset x86_64_regsets[] __read_mostly = {
20223 +static user_regset_no_const x86_64_regsets[] __read_only = {
20224 [REGSET_GENERAL] = {
20225 .core_note_type = NT_PRSTATUS,
20226 .n = sizeof(struct user_regs_struct) / sizeof(long),
20227 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20228 #endif /* CONFIG_X86_64 */
20229
20230 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20231 -static struct user_regset x86_32_regsets[] __read_mostly = {
20232 +static user_regset_no_const x86_32_regsets[] __read_only = {
20233 [REGSET_GENERAL] = {
20234 .core_note_type = NT_PRSTATUS,
20235 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20236 @@ -1419,7 +1418,7 @@ static const struct user_regset_view user_x86_32_view = {
20237 */
20238 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20239
20240 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20241 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20242 {
20243 #ifdef CONFIG_X86_64
20244 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20245 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20246 memset(info, 0, sizeof(*info));
20247 info->si_signo = SIGTRAP;
20248 info->si_code = si_code;
20249 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20250 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20251 }
20252
20253 void user_single_step_siginfo(struct task_struct *tsk,
20254 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20255 # define IS_IA32 0
20256 #endif
20257
20258 +#ifdef CONFIG_GRKERNSEC_SETXID
20259 +extern void gr_delayed_cred_worker(void);
20260 +#endif
20261 +
20262 /*
20263 * We must return the syscall number to actually look up in the table.
20264 * This can be -1L to skip running any syscall at all.
20265 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20266
20267 rcu_user_exit();
20268
20269 +#ifdef CONFIG_GRKERNSEC_SETXID
20270 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20271 + gr_delayed_cred_worker();
20272 +#endif
20273 +
20274 /*
20275 * If we stepped into a sysenter/syscall insn, it trapped in
20276 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20277 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20278 */
20279 rcu_user_exit();
20280
20281 +#ifdef CONFIG_GRKERNSEC_SETXID
20282 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20283 + gr_delayed_cred_worker();
20284 +#endif
20285 +
20286 audit_syscall_exit(regs);
20287
20288 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20289 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20290 index 42eb330..139955c 100644
20291 --- a/arch/x86/kernel/pvclock.c
20292 +++ b/arch/x86/kernel/pvclock.c
20293 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20294 return pv_tsc_khz;
20295 }
20296
20297 -static atomic64_t last_value = ATOMIC64_INIT(0);
20298 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20299
20300 void pvclock_resume(void)
20301 {
20302 - atomic64_set(&last_value, 0);
20303 + atomic64_set_unchecked(&last_value, 0);
20304 }
20305
20306 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20307 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20308 * updating at the same time, and one of them could be slightly behind,
20309 * making the assumption that last_value always go forward fail to hold.
20310 */
20311 - last = atomic64_read(&last_value);
20312 + last = atomic64_read_unchecked(&last_value);
20313 do {
20314 if (ret < last)
20315 return last;
20316 - last = atomic64_cmpxchg(&last_value, last, ret);
20317 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20318 } while (unlikely(last != ret));
20319
20320 return ret;
20321 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20322 index 76fa1e9..abf09ea 100644
20323 --- a/arch/x86/kernel/reboot.c
20324 +++ b/arch/x86/kernel/reboot.c
20325 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20326 EXPORT_SYMBOL(pm_power_off);
20327
20328 static const struct desc_ptr no_idt = {};
20329 -static int reboot_mode;
20330 +static unsigned short reboot_mode;
20331 enum reboot_type reboot_type = BOOT_ACPI;
20332 int reboot_force;
20333
20334 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20335
20336 void __noreturn machine_real_restart(unsigned int type)
20337 {
20338 +
20339 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20340 + struct desc_struct *gdt;
20341 +#endif
20342 +
20343 local_irq_disable();
20344
20345 /*
20346 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20347
20348 /* Jump to the identity-mapped low memory code */
20349 #ifdef CONFIG_X86_32
20350 - asm volatile("jmpl *%0" : :
20351 +
20352 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20353 + gdt = get_cpu_gdt_table(smp_processor_id());
20354 + pax_open_kernel();
20355 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20356 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20357 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20358 + loadsegment(ds, __KERNEL_DS);
20359 + loadsegment(es, __KERNEL_DS);
20360 + loadsegment(ss, __KERNEL_DS);
20361 +#endif
20362 +#ifdef CONFIG_PAX_KERNEXEC
20363 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20364 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20365 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20366 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20367 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20368 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20369 +#endif
20370 + pax_close_kernel();
20371 +#endif
20372 +
20373 + asm volatile("ljmpl *%0" : :
20374 "rm" (real_mode_header->machine_real_restart_asm),
20375 "a" (type));
20376 #else
20377 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20378 * try to force a triple fault and then cycle between hitting the keyboard
20379 * controller and doing that
20380 */
20381 -static void native_machine_emergency_restart(void)
20382 +static void __noreturn native_machine_emergency_restart(void)
20383 {
20384 int i;
20385 int attempt = 0;
20386 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20387 #endif
20388 }
20389
20390 -static void __machine_emergency_restart(int emergency)
20391 +static void __noreturn __machine_emergency_restart(int emergency)
20392 {
20393 reboot_emergency = emergency;
20394 machine_ops.emergency_restart();
20395 }
20396
20397 -static void native_machine_restart(char *__unused)
20398 +static void __noreturn native_machine_restart(char *__unused)
20399 {
20400 pr_notice("machine restart\n");
20401
20402 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20403 __machine_emergency_restart(0);
20404 }
20405
20406 -static void native_machine_halt(void)
20407 +static void __noreturn native_machine_halt(void)
20408 {
20409 /* Stop other cpus and apics */
20410 machine_shutdown();
20411 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20412 stop_this_cpu(NULL);
20413 }
20414
20415 -static void native_machine_power_off(void)
20416 +static void __noreturn native_machine_power_off(void)
20417 {
20418 if (pm_power_off) {
20419 if (!reboot_force)
20420 @@ -688,9 +715,10 @@ static void native_machine_power_off(void)
20421 }
20422 /* A fallback in case there is no PM info available */
20423 tboot_shutdown(TB_SHUTDOWN_HALT);
20424 + unreachable();
20425 }
20426
20427 -struct machine_ops machine_ops = {
20428 +struct machine_ops machine_ops __read_only = {
20429 .power_off = native_machine_power_off,
20430 .shutdown = native_machine_shutdown,
20431 .emergency_restart = native_machine_emergency_restart,
20432 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20433 index 7a6f3b3..bed145d7 100644
20434 --- a/arch/x86/kernel/relocate_kernel_64.S
20435 +++ b/arch/x86/kernel/relocate_kernel_64.S
20436 @@ -11,6 +11,7 @@
20437 #include <asm/kexec.h>
20438 #include <asm/processor-flags.h>
20439 #include <asm/pgtable_types.h>
20440 +#include <asm/alternative-asm.h>
20441
20442 /*
20443 * Must be relocatable PIC code callable as a C function
20444 @@ -160,13 +161,14 @@ identity_mapped:
20445 xorq %rbp, %rbp
20446 xorq %r8, %r8
20447 xorq %r9, %r9
20448 - xorq %r10, %r9
20449 + xorq %r10, %r10
20450 xorq %r11, %r11
20451 xorq %r12, %r12
20452 xorq %r13, %r13
20453 xorq %r14, %r14
20454 xorq %r15, %r15
20455
20456 + pax_force_retaddr 0, 1
20457 ret
20458
20459 1:
20460 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20461 index aeacb0e..f9d4c02 100644
20462 --- a/arch/x86/kernel/setup.c
20463 +++ b/arch/x86/kernel/setup.c
20464 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20465
20466 switch (data->type) {
20467 case SETUP_E820_EXT:
20468 - parse_e820_ext(data);
20469 + parse_e820_ext((struct setup_data __force_kernel *)data);
20470 break;
20471 case SETUP_DTB:
20472 add_dtb(pa_data);
20473 @@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20474 * area (640->1Mb) as ram even though it is not.
20475 * take them out.
20476 */
20477 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20478 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20479
20480 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20481 }
20482 @@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20483
20484 if (!boot_params.hdr.root_flags)
20485 root_mountflags &= ~MS_RDONLY;
20486 - init_mm.start_code = (unsigned long) _text;
20487 - init_mm.end_code = (unsigned long) _etext;
20488 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20489 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20490 init_mm.end_data = (unsigned long) _edata;
20491 init_mm.brk = _brk_end;
20492
20493 - code_resource.start = virt_to_phys(_text);
20494 - code_resource.end = virt_to_phys(_etext)-1;
20495 - data_resource.start = virt_to_phys(_etext);
20496 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20497 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20498 + data_resource.start = virt_to_phys(_sdata);
20499 data_resource.end = virt_to_phys(_edata)-1;
20500 bss_resource.start = virt_to_phys(&__bss_start);
20501 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20502 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20503 index 5cdff03..5810740 100644
20504 --- a/arch/x86/kernel/setup_percpu.c
20505 +++ b/arch/x86/kernel/setup_percpu.c
20506 @@ -21,19 +21,17 @@
20507 #include <asm/cpu.h>
20508 #include <asm/stackprotector.h>
20509
20510 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20511 +#ifdef CONFIG_SMP
20512 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20513 EXPORT_PER_CPU_SYMBOL(cpu_number);
20514 +#endif
20515
20516 -#ifdef CONFIG_X86_64
20517 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20518 -#else
20519 -#define BOOT_PERCPU_OFFSET 0
20520 -#endif
20521
20522 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20523 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20524
20525 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20526 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20527 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20528 };
20529 EXPORT_SYMBOL(__per_cpu_offset);
20530 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20531 {
20532 #ifdef CONFIG_X86_32
20533 struct desc_struct gdt;
20534 + unsigned long base = per_cpu_offset(cpu);
20535
20536 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20537 - 0x2 | DESCTYPE_S, 0x8);
20538 - gdt.s = 1;
20539 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20540 + 0x83 | DESCTYPE_S, 0xC);
20541 write_gdt_entry(get_cpu_gdt_table(cpu),
20542 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20543 #endif
20544 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20545 /* alrighty, percpu areas up and running */
20546 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20547 for_each_possible_cpu(cpu) {
20548 +#ifdef CONFIG_CC_STACKPROTECTOR
20549 +#ifdef CONFIG_X86_32
20550 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20551 +#endif
20552 +#endif
20553 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20554 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20555 per_cpu(cpu_number, cpu) = cpu;
20556 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20557 */
20558 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20559 #endif
20560 +#ifdef CONFIG_CC_STACKPROTECTOR
20561 +#ifdef CONFIG_X86_32
20562 + if (!cpu)
20563 + per_cpu(stack_canary.canary, cpu) = canary;
20564 +#endif
20565 +#endif
20566 /*
20567 * Up to this point, the boot CPU has been using .init.data
20568 * area. Reload any changed state for the boot CPU.
20569 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20570 index 70b27ee..fcf827f 100644
20571 --- a/arch/x86/kernel/signal.c
20572 +++ b/arch/x86/kernel/signal.c
20573 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20574 * Align the stack pointer according to the i386 ABI,
20575 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20576 */
20577 - sp = ((sp + 4) & -16ul) - 4;
20578 + sp = ((sp - 12) & -16ul) - 4;
20579 #else /* !CONFIG_X86_32 */
20580 sp = round_down(sp, 16) - 8;
20581 #endif
20582 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20583 }
20584
20585 if (current->mm->context.vdso)
20586 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20587 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20588 else
20589 - restorer = &frame->retcode;
20590 + restorer = (void __user *)&frame->retcode;
20591 if (ka->sa.sa_flags & SA_RESTORER)
20592 restorer = ka->sa.sa_restorer;
20593
20594 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20595 * reasons and because gdb uses it as a signature to notice
20596 * signal handler stack frames.
20597 */
20598 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20599 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20600
20601 if (err)
20602 return -EFAULT;
20603 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20604 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20605
20606 /* Set up to return from userspace. */
20607 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20608 + if (current->mm->context.vdso)
20609 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20610 + else
20611 + restorer = (void __user *)&frame->retcode;
20612 if (ka->sa.sa_flags & SA_RESTORER)
20613 restorer = ka->sa.sa_restorer;
20614 put_user_ex(restorer, &frame->pretcode);
20615 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20616 * reasons and because gdb uses it as a signature to notice
20617 * signal handler stack frames.
20618 */
20619 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20620 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20621 } put_user_catch(err);
20622
20623 err |= copy_siginfo_to_user(&frame->info, info);
20624 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
20625 index 48d2b7d..90d328a 100644
20626 --- a/arch/x86/kernel/smp.c
20627 +++ b/arch/x86/kernel/smp.c
20628 @@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
20629
20630 __setup("nonmi_ipi", nonmi_ipi_setup);
20631
20632 -struct smp_ops smp_ops = {
20633 +struct smp_ops smp_ops __read_only = {
20634 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
20635 .smp_prepare_cpus = native_smp_prepare_cpus,
20636 .smp_cpus_done = native_smp_cpus_done,
20637 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20638 index f3e2ec8..ad5287a 100644
20639 --- a/arch/x86/kernel/smpboot.c
20640 +++ b/arch/x86/kernel/smpboot.c
20641 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20642 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20643 (THREAD_SIZE + task_stack_page(idle))) - 1);
20644 per_cpu(current_task, cpu) = idle;
20645 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20646
20647 #ifdef CONFIG_X86_32
20648 /* Stack for startup_32 can be just as for start_secondary onwards */
20649 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20650 #else
20651 clear_tsk_thread_flag(idle, TIF_FORK);
20652 initial_gs = per_cpu_offset(cpu);
20653 - per_cpu(kernel_stack, cpu) =
20654 - (unsigned long)task_stack_page(idle) -
20655 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20656 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20657 #endif
20658 +
20659 + pax_open_kernel();
20660 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20661 + pax_close_kernel();
20662 +
20663 initial_code = (unsigned long)start_secondary;
20664 stack_start = idle->thread.sp;
20665
20666 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20667 /* the FPU context is blank, nobody can own it */
20668 __cpu_disable_lazy_restore(cpu);
20669
20670 +#ifdef CONFIG_PAX_PER_CPU_PGD
20671 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20672 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20673 + KERNEL_PGD_PTRS);
20674 +#endif
20675 +
20676 + /* the FPU context is blank, nobody can own it */
20677 + __cpu_disable_lazy_restore(cpu);
20678 +
20679 err = do_boot_cpu(apicid, cpu, tidle);
20680 if (err) {
20681 pr_debug("do_boot_cpu failed %d\n", err);
20682 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20683 index 9b4d51d..5d28b58 100644
20684 --- a/arch/x86/kernel/step.c
20685 +++ b/arch/x86/kernel/step.c
20686 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20687 struct desc_struct *desc;
20688 unsigned long base;
20689
20690 - seg &= ~7UL;
20691 + seg >>= 3;
20692
20693 mutex_lock(&child->mm->context.lock);
20694 - if (unlikely((seg >> 3) >= child->mm->context.size))
20695 + if (unlikely(seg >= child->mm->context.size))
20696 addr = -1L; /* bogus selector, access would fault */
20697 else {
20698 desc = child->mm->context.ldt + seg;
20699 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20700 addr += base;
20701 }
20702 mutex_unlock(&child->mm->context.lock);
20703 - }
20704 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20705 + addr = ktla_ktva(addr);
20706
20707 return addr;
20708 }
20709 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20710 unsigned char opcode[15];
20711 unsigned long addr = convert_ip_to_linear(child, regs);
20712
20713 + if (addr == -EINVAL)
20714 + return 0;
20715 +
20716 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20717 for (i = 0; i < copied; i++) {
20718 switch (opcode[i]) {
20719 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20720 new file mode 100644
20721 index 0000000..26bb1af
20722 --- /dev/null
20723 +++ b/arch/x86/kernel/sys_i386_32.c
20724 @@ -0,0 +1,249 @@
20725 +/*
20726 + * This file contains various random system calls that
20727 + * have a non-standard calling sequence on the Linux/i386
20728 + * platform.
20729 + */
20730 +
20731 +#include <linux/errno.h>
20732 +#include <linux/sched.h>
20733 +#include <linux/mm.h>
20734 +#include <linux/fs.h>
20735 +#include <linux/smp.h>
20736 +#include <linux/sem.h>
20737 +#include <linux/msg.h>
20738 +#include <linux/shm.h>
20739 +#include <linux/stat.h>
20740 +#include <linux/syscalls.h>
20741 +#include <linux/mman.h>
20742 +#include <linux/file.h>
20743 +#include <linux/utsname.h>
20744 +#include <linux/ipc.h>
20745 +
20746 +#include <linux/uaccess.h>
20747 +#include <linux/unistd.h>
20748 +
20749 +#include <asm/syscalls.h>
20750 +
20751 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20752 +{
20753 + unsigned long pax_task_size = TASK_SIZE;
20754 +
20755 +#ifdef CONFIG_PAX_SEGMEXEC
20756 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20757 + pax_task_size = SEGMEXEC_TASK_SIZE;
20758 +#endif
20759 +
20760 + if (len > pax_task_size || addr > pax_task_size - len)
20761 + return -EINVAL;
20762 +
20763 + return 0;
20764 +}
20765 +
20766 +unsigned long
20767 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20768 + unsigned long len, unsigned long pgoff, unsigned long flags)
20769 +{
20770 + struct mm_struct *mm = current->mm;
20771 + struct vm_area_struct *vma;
20772 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20773 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20774 +
20775 +#ifdef CONFIG_PAX_SEGMEXEC
20776 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20777 + pax_task_size = SEGMEXEC_TASK_SIZE;
20778 +#endif
20779 +
20780 + pax_task_size -= PAGE_SIZE;
20781 +
20782 + if (len > pax_task_size)
20783 + return -ENOMEM;
20784 +
20785 + if (flags & MAP_FIXED)
20786 + return addr;
20787 +
20788 +#ifdef CONFIG_PAX_RANDMMAP
20789 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20790 +#endif
20791 +
20792 + if (addr) {
20793 + addr = PAGE_ALIGN(addr);
20794 + if (pax_task_size - len >= addr) {
20795 + vma = find_vma(mm, addr);
20796 + if (check_heap_stack_gap(vma, addr, len, offset))
20797 + return addr;
20798 + }
20799 + }
20800 + if (len > mm->cached_hole_size) {
20801 + start_addr = addr = mm->free_area_cache;
20802 + } else {
20803 + start_addr = addr = mm->mmap_base;
20804 + mm->cached_hole_size = 0;
20805 + }
20806 +
20807 +#ifdef CONFIG_PAX_PAGEEXEC
20808 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20809 + start_addr = 0x00110000UL;
20810 +
20811 +#ifdef CONFIG_PAX_RANDMMAP
20812 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20813 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20814 +#endif
20815 +
20816 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20817 + start_addr = addr = mm->mmap_base;
20818 + else
20819 + addr = start_addr;
20820 + }
20821 +#endif
20822 +
20823 +full_search:
20824 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20825 + /* At this point: (!vma || addr < vma->vm_end). */
20826 + if (pax_task_size - len < addr) {
20827 + /*
20828 + * Start a new search - just in case we missed
20829 + * some holes.
20830 + */
20831 + if (start_addr != mm->mmap_base) {
20832 + start_addr = addr = mm->mmap_base;
20833 + mm->cached_hole_size = 0;
20834 + goto full_search;
20835 + }
20836 + return -ENOMEM;
20837 + }
20838 + if (check_heap_stack_gap(vma, addr, len, offset))
20839 + break;
20840 + if (addr + mm->cached_hole_size < vma->vm_start)
20841 + mm->cached_hole_size = vma->vm_start - addr;
20842 + addr = vma->vm_end;
20843 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20844 + start_addr = addr = mm->mmap_base;
20845 + mm->cached_hole_size = 0;
20846 + goto full_search;
20847 + }
20848 + }
20849 +
20850 + /*
20851 + * Remember the place where we stopped the search:
20852 + */
20853 + mm->free_area_cache = addr + len;
20854 + return addr;
20855 +}
20856 +
20857 +unsigned long
20858 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20859 + const unsigned long len, const unsigned long pgoff,
20860 + const unsigned long flags)
20861 +{
20862 + struct vm_area_struct *vma;
20863 + struct mm_struct *mm = current->mm;
20864 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20865 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20866 +
20867 +#ifdef CONFIG_PAX_SEGMEXEC
20868 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20869 + pax_task_size = SEGMEXEC_TASK_SIZE;
20870 +#endif
20871 +
20872 + pax_task_size -= PAGE_SIZE;
20873 +
20874 + /* requested length too big for entire address space */
20875 + if (len > pax_task_size)
20876 + return -ENOMEM;
20877 +
20878 + if (flags & MAP_FIXED)
20879 + return addr;
20880 +
20881 +#ifdef CONFIG_PAX_PAGEEXEC
20882 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20883 + goto bottomup;
20884 +#endif
20885 +
20886 +#ifdef CONFIG_PAX_RANDMMAP
20887 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20888 +#endif
20889 +
20890 + /* requesting a specific address */
20891 + if (addr) {
20892 + addr = PAGE_ALIGN(addr);
20893 + if (pax_task_size - len >= addr) {
20894 + vma = find_vma(mm, addr);
20895 + if (check_heap_stack_gap(vma, addr, len, offset))
20896 + return addr;
20897 + }
20898 + }
20899 +
20900 + /* check if free_area_cache is useful for us */
20901 + if (len <= mm->cached_hole_size) {
20902 + mm->cached_hole_size = 0;
20903 + mm->free_area_cache = mm->mmap_base;
20904 + }
20905 +
20906 + /* either no address requested or can't fit in requested address hole */
20907 + addr = mm->free_area_cache;
20908 +
20909 + /* make sure it can fit in the remaining address space */
20910 + if (addr > len) {
20911 + vma = find_vma(mm, addr-len);
20912 + if (check_heap_stack_gap(vma, addr - len, len, offset))
20913 + /* remember the address as a hint for next time */
20914 + return (mm->free_area_cache = addr-len);
20915 + }
20916 +
20917 + if (mm->mmap_base < len)
20918 + goto bottomup;
20919 +
20920 + addr = mm->mmap_base-len;
20921 +
20922 + do {
20923 + /*
20924 + * Lookup failure means no vma is above this address,
20925 + * else if new region fits below vma->vm_start,
20926 + * return with success:
20927 + */
20928 + vma = find_vma(mm, addr);
20929 + if (check_heap_stack_gap(vma, addr, len, offset))
20930 + /* remember the address as a hint for next time */
20931 + return (mm->free_area_cache = addr);
20932 +
20933 + /* remember the largest hole we saw so far */
20934 + if (addr + mm->cached_hole_size < vma->vm_start)
20935 + mm->cached_hole_size = vma->vm_start - addr;
20936 +
20937 + /* try just below the current vma->vm_start */
20938 + addr = skip_heap_stack_gap(vma, len, offset);
20939 + } while (!IS_ERR_VALUE(addr));
20940 +
20941 +bottomup:
20942 + /*
20943 + * A failed mmap() very likely causes application failure,
20944 + * so fall back to the bottom-up function here. This scenario
20945 + * can happen with large stack limits and large mmap()
20946 + * allocations.
20947 + */
20948 +
20949 +#ifdef CONFIG_PAX_SEGMEXEC
20950 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20951 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20952 + else
20953 +#endif
20954 +
20955 + mm->mmap_base = TASK_UNMAPPED_BASE;
20956 +
20957 +#ifdef CONFIG_PAX_RANDMMAP
20958 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20959 + mm->mmap_base += mm->delta_mmap;
20960 +#endif
20961 +
20962 + mm->free_area_cache = mm->mmap_base;
20963 + mm->cached_hole_size = ~0UL;
20964 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20965 + /*
20966 + * Restore the topdown base:
20967 + */
20968 + mm->mmap_base = base;
20969 + mm->free_area_cache = base;
20970 + mm->cached_hole_size = ~0UL;
20971 +
20972 + return addr;
20973 +}
20974 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20975 index b4d3c39..d699d77 100644
20976 --- a/arch/x86/kernel/sys_x86_64.c
20977 +++ b/arch/x86/kernel/sys_x86_64.c
20978 @@ -95,8 +95,8 @@ out:
20979 return error;
20980 }
20981
20982 -static void find_start_end(unsigned long flags, unsigned long *begin,
20983 - unsigned long *end)
20984 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20985 + unsigned long *begin, unsigned long *end)
20986 {
20987 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20988 unsigned long new_begin;
20989 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20990 *begin = new_begin;
20991 }
20992 } else {
20993 - *begin = TASK_UNMAPPED_BASE;
20994 + *begin = mm->mmap_base;
20995 *end = TASK_SIZE;
20996 }
20997 }
20998 @@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20999 struct vm_area_struct *vma;
21000 unsigned long start_addr;
21001 unsigned long begin, end;
21002 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
21003
21004 if (flags & MAP_FIXED)
21005 return addr;
21006
21007 - find_start_end(flags, &begin, &end);
21008 + find_start_end(mm, flags, &begin, &end);
21009
21010 if (len > end)
21011 return -ENOMEM;
21012
21013 +#ifdef CONFIG_PAX_RANDMMAP
21014 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21015 +#endif
21016 +
21017 if (addr) {
21018 addr = PAGE_ALIGN(addr);
21019 vma = find_vma(mm, addr);
21020 - if (end - len >= addr &&
21021 - (!vma || addr + len <= vma->vm_start))
21022 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
21023 return addr;
21024 }
21025 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
21026 @@ -172,7 +176,7 @@ full_search:
21027 }
21028 return -ENOMEM;
21029 }
21030 - if (!vma || addr + len <= vma->vm_start) {
21031 + if (check_heap_stack_gap(vma, addr, len, offset)) {
21032 /*
21033 * Remember the place where we stopped the search:
21034 */
21035 @@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
21036 {
21037 struct vm_area_struct *vma;
21038 struct mm_struct *mm = current->mm;
21039 - unsigned long addr = addr0, start_addr;
21040 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
21041 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
21042
21043 /* requested length too big for entire address space */
21044 if (len > TASK_SIZE)
21045 @@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
21046 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
21047 goto bottomup;
21048
21049 +#ifdef CONFIG_PAX_RANDMMAP
21050 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21051 +#endif
21052 +
21053 /* requesting a specific address */
21054 if (addr) {
21055 addr = PAGE_ALIGN(addr);
21056 - vma = find_vma(mm, addr);
21057 - if (TASK_SIZE - len >= addr &&
21058 - (!vma || addr + len <= vma->vm_start))
21059 - return addr;
21060 + if (TASK_SIZE - len >= addr) {
21061 + vma = find_vma(mm, addr);
21062 + if (check_heap_stack_gap(vma, addr, len, offset))
21063 + return addr;
21064 + }
21065 }
21066
21067 /* check if free_area_cache is useful for us */
21068 @@ -240,7 +250,7 @@ try_again:
21069 * return with success:
21070 */
21071 vma = find_vma(mm, addr);
21072 - if (!vma || addr+len <= vma->vm_start)
21073 + if (check_heap_stack_gap(vma, addr, len, offset))
21074 /* remember the address as a hint for next time */
21075 return mm->free_area_cache = addr;
21076
21077 @@ -249,8 +259,8 @@ try_again:
21078 mm->cached_hole_size = vma->vm_start - addr;
21079
21080 /* try just below the current vma->vm_start */
21081 - addr = vma->vm_start-len;
21082 - } while (len < vma->vm_start);
21083 + addr = skip_heap_stack_gap(vma, len, offset);
21084 + } while (!IS_ERR_VALUE(addr));
21085
21086 fail:
21087 /*
21088 @@ -270,13 +280,21 @@ bottomup:
21089 * can happen with large stack limits and large mmap()
21090 * allocations.
21091 */
21092 + mm->mmap_base = TASK_UNMAPPED_BASE;
21093 +
21094 +#ifdef CONFIG_PAX_RANDMMAP
21095 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21096 + mm->mmap_base += mm->delta_mmap;
21097 +#endif
21098 +
21099 + mm->free_area_cache = mm->mmap_base;
21100 mm->cached_hole_size = ~0UL;
21101 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21102 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21103 /*
21104 * Restore the topdown base:
21105 */
21106 - mm->free_area_cache = mm->mmap_base;
21107 + mm->mmap_base = base;
21108 + mm->free_area_cache = base;
21109 mm->cached_hole_size = ~0UL;
21110
21111 return addr;
21112 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21113 index f84fe00..93fe08f 100644
21114 --- a/arch/x86/kernel/tboot.c
21115 +++ b/arch/x86/kernel/tboot.c
21116 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21117
21118 void tboot_shutdown(u32 shutdown_type)
21119 {
21120 - void (*shutdown)(void);
21121 + void (* __noreturn shutdown)(void);
21122
21123 if (!tboot_enabled())
21124 return;
21125 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21126
21127 switch_to_tboot_pt();
21128
21129 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21130 + shutdown = (void *)tboot->shutdown_entry;
21131 shutdown();
21132
21133 /* should not reach here */
21134 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21135 return 0;
21136 }
21137
21138 -static atomic_t ap_wfs_count;
21139 +static atomic_unchecked_t ap_wfs_count;
21140
21141 static int tboot_wait_for_aps(int num_aps)
21142 {
21143 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21144 {
21145 switch (action) {
21146 case CPU_DYING:
21147 - atomic_inc(&ap_wfs_count);
21148 + atomic_inc_unchecked(&ap_wfs_count);
21149 if (num_online_cpus() == 1)
21150 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21151 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21152 return NOTIFY_BAD;
21153 break;
21154 }
21155 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21156
21157 tboot_create_trampoline();
21158
21159 - atomic_set(&ap_wfs_count, 0);
21160 + atomic_set_unchecked(&ap_wfs_count, 0);
21161 register_hotcpu_notifier(&tboot_cpu_notifier);
21162
21163 acpi_os_set_prepare_sleep(&tboot_sleep);
21164 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21165 index 24d3c91..d06b473 100644
21166 --- a/arch/x86/kernel/time.c
21167 +++ b/arch/x86/kernel/time.c
21168 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21169 {
21170 unsigned long pc = instruction_pointer(regs);
21171
21172 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21173 + if (!user_mode(regs) && in_lock_functions(pc)) {
21174 #ifdef CONFIG_FRAME_POINTER
21175 - return *(unsigned long *)(regs->bp + sizeof(long));
21176 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21177 #else
21178 unsigned long *sp =
21179 (unsigned long *)kernel_stack_pointer(regs);
21180 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21181 * or above a saved flags. Eflags has bits 22-31 zero,
21182 * kernel addresses don't.
21183 */
21184 +
21185 +#ifdef CONFIG_PAX_KERNEXEC
21186 + return ktla_ktva(sp[0]);
21187 +#else
21188 if (sp[0] >> 22)
21189 return sp[0];
21190 if (sp[1] >> 22)
21191 return sp[1];
21192 #endif
21193 +
21194 +#endif
21195 }
21196 return pc;
21197 }
21198 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21199 index 9d9d2f9..cad418a 100644
21200 --- a/arch/x86/kernel/tls.c
21201 +++ b/arch/x86/kernel/tls.c
21202 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21203 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21204 return -EINVAL;
21205
21206 +#ifdef CONFIG_PAX_SEGMEXEC
21207 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21208 + return -EINVAL;
21209 +#endif
21210 +
21211 set_tls_desc(p, idx, &info, 1);
21212
21213 return 0;
21214 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21215
21216 if (kbuf)
21217 info = kbuf;
21218 - else if (__copy_from_user(infobuf, ubuf, count))
21219 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21220 return -EFAULT;
21221 else
21222 info = infobuf;
21223 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21224 index 8276dc6..4ca48a2 100644
21225 --- a/arch/x86/kernel/traps.c
21226 +++ b/arch/x86/kernel/traps.c
21227 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21228
21229 /* Do we ignore FPU interrupts ? */
21230 char ignore_fpu_irq;
21231 -
21232 -/*
21233 - * The IDT has to be page-aligned to simplify the Pentium
21234 - * F0 0F bug workaround.
21235 - */
21236 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21237 #endif
21238
21239 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21240 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21241 }
21242
21243 static int __kprobes
21244 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21245 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21246 struct pt_regs *regs, long error_code)
21247 {
21248 #ifdef CONFIG_X86_32
21249 - if (regs->flags & X86_VM_MASK) {
21250 + if (v8086_mode(regs)) {
21251 /*
21252 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21253 * On nmi (interrupt 2), do_trap should not be called.
21254 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21255 return -1;
21256 }
21257 #endif
21258 - if (!user_mode(regs)) {
21259 + if (!user_mode_novm(regs)) {
21260 if (!fixup_exception(regs)) {
21261 tsk->thread.error_code = error_code;
21262 tsk->thread.trap_nr = trapnr;
21263 +
21264 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21265 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21266 + str = "PAX: suspicious stack segment fault";
21267 +#endif
21268 +
21269 die(str, regs, error_code);
21270 }
21271 +
21272 +#ifdef CONFIG_PAX_REFCOUNT
21273 + if (trapnr == 4)
21274 + pax_report_refcount_overflow(regs);
21275 +#endif
21276 +
21277 return 0;
21278 }
21279
21280 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21281 }
21282
21283 static void __kprobes
21284 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21285 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21286 long error_code, siginfo_t *info)
21287 {
21288 struct task_struct *tsk = current;
21289 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21290 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21291 printk_ratelimit()) {
21292 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21293 - tsk->comm, tsk->pid, str,
21294 + tsk->comm, task_pid_nr(tsk), str,
21295 regs->ip, regs->sp, error_code);
21296 print_vma_addr(" in ", regs->ip);
21297 pr_cont("\n");
21298 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21299 conditional_sti(regs);
21300
21301 #ifdef CONFIG_X86_32
21302 - if (regs->flags & X86_VM_MASK) {
21303 + if (v8086_mode(regs)) {
21304 local_irq_enable();
21305 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21306 goto exit;
21307 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21308 #endif
21309
21310 tsk = current;
21311 - if (!user_mode(regs)) {
21312 + if (!user_mode_novm(regs)) {
21313 if (fixup_exception(regs))
21314 goto exit;
21315
21316 tsk->thread.error_code = error_code;
21317 tsk->thread.trap_nr = X86_TRAP_GP;
21318 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21319 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21320 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21321 +
21322 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21323 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21324 + die("PAX: suspicious general protection fault", regs, error_code);
21325 + else
21326 +#endif
21327 +
21328 die("general protection fault", regs, error_code);
21329 + }
21330 goto exit;
21331 }
21332
21333 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21334 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21335 + struct mm_struct *mm = tsk->mm;
21336 + unsigned long limit;
21337 +
21338 + down_write(&mm->mmap_sem);
21339 + limit = mm->context.user_cs_limit;
21340 + if (limit < TASK_SIZE) {
21341 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21342 + up_write(&mm->mmap_sem);
21343 + return;
21344 + }
21345 + up_write(&mm->mmap_sem);
21346 + }
21347 +#endif
21348 +
21349 tsk->thread.error_code = error_code;
21350 tsk->thread.trap_nr = X86_TRAP_GP;
21351
21352 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21353 /* It's safe to allow irq's after DR6 has been saved */
21354 preempt_conditional_sti(regs);
21355
21356 - if (regs->flags & X86_VM_MASK) {
21357 + if (v8086_mode(regs)) {
21358 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21359 X86_TRAP_DB);
21360 preempt_conditional_cli(regs);
21361 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21362 * We already checked v86 mode above, so we can check for kernel mode
21363 * by just checking the CPL of CS.
21364 */
21365 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21366 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21367 tsk->thread.debugreg6 &= ~DR_STEP;
21368 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21369 regs->flags &= ~X86_EFLAGS_TF;
21370 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21371 return;
21372 conditional_sti(regs);
21373
21374 - if (!user_mode_vm(regs))
21375 + if (!user_mode(regs))
21376 {
21377 if (!fixup_exception(regs)) {
21378 task->thread.error_code = error_code;
21379 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21380 index aafa555..a04691a 100644
21381 --- a/arch/x86/kernel/uprobes.c
21382 +++ b/arch/x86/kernel/uprobes.c
21383 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21384 int ret = NOTIFY_DONE;
21385
21386 /* We are only interested in userspace traps */
21387 - if (regs && !user_mode_vm(regs))
21388 + if (regs && !user_mode(regs))
21389 return NOTIFY_DONE;
21390
21391 switch (val) {
21392 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21393 index b9242ba..50c5edd 100644
21394 --- a/arch/x86/kernel/verify_cpu.S
21395 +++ b/arch/x86/kernel/verify_cpu.S
21396 @@ -20,6 +20,7 @@
21397 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21398 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21399 * arch/x86/kernel/head_32.S: processor startup
21400 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21401 *
21402 * verify_cpu, returns the status of longmode and SSE in register %eax.
21403 * 0: Success 1: Failure
21404 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21405 index 5c9687b..5f857d3 100644
21406 --- a/arch/x86/kernel/vm86_32.c
21407 +++ b/arch/x86/kernel/vm86_32.c
21408 @@ -43,6 +43,7 @@
21409 #include <linux/ptrace.h>
21410 #include <linux/audit.h>
21411 #include <linux/stddef.h>
21412 +#include <linux/grsecurity.h>
21413
21414 #include <asm/uaccess.h>
21415 #include <asm/io.h>
21416 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21417 do_exit(SIGSEGV);
21418 }
21419
21420 - tss = &per_cpu(init_tss, get_cpu());
21421 + tss = init_tss + get_cpu();
21422 current->thread.sp0 = current->thread.saved_sp0;
21423 current->thread.sysenter_cs = __KERNEL_CS;
21424 load_sp0(tss, &current->thread);
21425 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21426 struct task_struct *tsk;
21427 int tmp, ret = -EPERM;
21428
21429 +#ifdef CONFIG_GRKERNSEC_VM86
21430 + if (!capable(CAP_SYS_RAWIO)) {
21431 + gr_handle_vm86();
21432 + goto out;
21433 + }
21434 +#endif
21435 +
21436 tsk = current;
21437 if (tsk->thread.saved_sp0)
21438 goto out;
21439 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21440 int tmp, ret;
21441 struct vm86plus_struct __user *v86;
21442
21443 +#ifdef CONFIG_GRKERNSEC_VM86
21444 + if (!capable(CAP_SYS_RAWIO)) {
21445 + gr_handle_vm86();
21446 + ret = -EPERM;
21447 + goto out;
21448 + }
21449 +#endif
21450 +
21451 tsk = current;
21452 switch (cmd) {
21453 case VM86_REQUEST_IRQ:
21454 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21455 tsk->thread.saved_fs = info->regs32->fs;
21456 tsk->thread.saved_gs = get_user_gs(info->regs32);
21457
21458 - tss = &per_cpu(init_tss, get_cpu());
21459 + tss = init_tss + get_cpu();
21460 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21461 if (cpu_has_sep)
21462 tsk->thread.sysenter_cs = 0;
21463 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21464 goto cannot_handle;
21465 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21466 goto cannot_handle;
21467 - intr_ptr = (unsigned long __user *) (i << 2);
21468 + intr_ptr = (__force unsigned long __user *) (i << 2);
21469 if (get_user(segoffs, intr_ptr))
21470 goto cannot_handle;
21471 if ((segoffs >> 16) == BIOSSEG)
21472 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21473 index 22a1530..8fbaaad 100644
21474 --- a/arch/x86/kernel/vmlinux.lds.S
21475 +++ b/arch/x86/kernel/vmlinux.lds.S
21476 @@ -26,6 +26,13 @@
21477 #include <asm/page_types.h>
21478 #include <asm/cache.h>
21479 #include <asm/boot.h>
21480 +#include <asm/segment.h>
21481 +
21482 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21483 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21484 +#else
21485 +#define __KERNEL_TEXT_OFFSET 0
21486 +#endif
21487
21488 #undef i386 /* in case the preprocessor is a 32bit one */
21489
21490 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21491
21492 PHDRS {
21493 text PT_LOAD FLAGS(5); /* R_E */
21494 +#ifdef CONFIG_X86_32
21495 + module PT_LOAD FLAGS(5); /* R_E */
21496 +#endif
21497 +#ifdef CONFIG_XEN
21498 + rodata PT_LOAD FLAGS(5); /* R_E */
21499 +#else
21500 + rodata PT_LOAD FLAGS(4); /* R__ */
21501 +#endif
21502 data PT_LOAD FLAGS(6); /* RW_ */
21503 -#ifdef CONFIG_X86_64
21504 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21505 #ifdef CONFIG_SMP
21506 percpu PT_LOAD FLAGS(6); /* RW_ */
21507 #endif
21508 + text.init PT_LOAD FLAGS(5); /* R_E */
21509 + text.exit PT_LOAD FLAGS(5); /* R_E */
21510 init PT_LOAD FLAGS(7); /* RWE */
21511 -#endif
21512 note PT_NOTE FLAGS(0); /* ___ */
21513 }
21514
21515 SECTIONS
21516 {
21517 #ifdef CONFIG_X86_32
21518 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21519 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21520 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21521 #else
21522 - . = __START_KERNEL;
21523 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21524 + . = __START_KERNEL;
21525 #endif
21526
21527 /* Text and read-only data */
21528 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21529 - _text = .;
21530 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21531 /* bootstrapping code */
21532 +#ifdef CONFIG_X86_32
21533 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21534 +#else
21535 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21536 +#endif
21537 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21538 + _text = .;
21539 HEAD_TEXT
21540 #ifdef CONFIG_X86_32
21541 . = ALIGN(PAGE_SIZE);
21542 @@ -108,13 +128,48 @@ SECTIONS
21543 IRQENTRY_TEXT
21544 *(.fixup)
21545 *(.gnu.warning)
21546 - /* End of text section */
21547 - _etext = .;
21548 } :text = 0x9090
21549
21550 - NOTES :text :note
21551 + . += __KERNEL_TEXT_OFFSET;
21552
21553 - EXCEPTION_TABLE(16) :text = 0x9090
21554 +#ifdef CONFIG_X86_32
21555 + . = ALIGN(PAGE_SIZE);
21556 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21557 +
21558 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21559 + MODULES_EXEC_VADDR = .;
21560 + BYTE(0)
21561 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21562 + . = ALIGN(HPAGE_SIZE) - 1;
21563 + MODULES_EXEC_END = .;
21564 +#endif
21565 +
21566 + } :module
21567 +#endif
21568 +
21569 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21570 + /* End of text section */
21571 + BYTE(0)
21572 + _etext = . - __KERNEL_TEXT_OFFSET;
21573 + }
21574 +
21575 +#ifdef CONFIG_X86_32
21576 + . = ALIGN(PAGE_SIZE);
21577 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21578 + *(.idt)
21579 + . = ALIGN(PAGE_SIZE);
21580 + *(.empty_zero_page)
21581 + *(.initial_pg_fixmap)
21582 + *(.initial_pg_pmd)
21583 + *(.initial_page_table)
21584 + *(.swapper_pg_dir)
21585 + } :rodata
21586 +#endif
21587 +
21588 + . = ALIGN(PAGE_SIZE);
21589 + NOTES :rodata :note
21590 +
21591 + EXCEPTION_TABLE(16) :rodata
21592
21593 #if defined(CONFIG_DEBUG_RODATA)
21594 /* .text should occupy whole number of pages */
21595 @@ -126,16 +181,20 @@ SECTIONS
21596
21597 /* Data */
21598 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21599 +
21600 +#ifdef CONFIG_PAX_KERNEXEC
21601 + . = ALIGN(HPAGE_SIZE);
21602 +#else
21603 + . = ALIGN(PAGE_SIZE);
21604 +#endif
21605 +
21606 /* Start of data section */
21607 _sdata = .;
21608
21609 /* init_task */
21610 INIT_TASK_DATA(THREAD_SIZE)
21611
21612 -#ifdef CONFIG_X86_32
21613 - /* 32 bit has nosave before _edata */
21614 NOSAVE_DATA
21615 -#endif
21616
21617 PAGE_ALIGNED_DATA(PAGE_SIZE)
21618
21619 @@ -176,12 +235,19 @@ SECTIONS
21620 #endif /* CONFIG_X86_64 */
21621
21622 /* Init code and data - will be freed after init */
21623 - . = ALIGN(PAGE_SIZE);
21624 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21625 + BYTE(0)
21626 +
21627 +#ifdef CONFIG_PAX_KERNEXEC
21628 + . = ALIGN(HPAGE_SIZE);
21629 +#else
21630 + . = ALIGN(PAGE_SIZE);
21631 +#endif
21632 +
21633 __init_begin = .; /* paired with __init_end */
21634 - }
21635 + } :init.begin
21636
21637 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21638 +#ifdef CONFIG_SMP
21639 /*
21640 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21641 * output PHDR, so the next output section - .init.text - should
21642 @@ -190,12 +256,27 @@ SECTIONS
21643 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21644 #endif
21645
21646 - INIT_TEXT_SECTION(PAGE_SIZE)
21647 -#ifdef CONFIG_X86_64
21648 - :init
21649 -#endif
21650 + . = ALIGN(PAGE_SIZE);
21651 + init_begin = .;
21652 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21653 + VMLINUX_SYMBOL(_sinittext) = .;
21654 + INIT_TEXT
21655 + VMLINUX_SYMBOL(_einittext) = .;
21656 + . = ALIGN(PAGE_SIZE);
21657 + } :text.init
21658
21659 - INIT_DATA_SECTION(16)
21660 + /*
21661 + * .exit.text is discard at runtime, not link time, to deal with
21662 + * references from .altinstructions and .eh_frame
21663 + */
21664 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21665 + EXIT_TEXT
21666 + . = ALIGN(16);
21667 + } :text.exit
21668 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21669 +
21670 + . = ALIGN(PAGE_SIZE);
21671 + INIT_DATA_SECTION(16) :init
21672
21673 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21674 __x86_cpu_dev_start = .;
21675 @@ -257,19 +338,12 @@ SECTIONS
21676 }
21677
21678 . = ALIGN(8);
21679 - /*
21680 - * .exit.text is discard at runtime, not link time, to deal with
21681 - * references from .altinstructions and .eh_frame
21682 - */
21683 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21684 - EXIT_TEXT
21685 - }
21686
21687 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21688 EXIT_DATA
21689 }
21690
21691 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21692 +#ifndef CONFIG_SMP
21693 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21694 #endif
21695
21696 @@ -288,16 +362,10 @@ SECTIONS
21697 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21698 __smp_locks = .;
21699 *(.smp_locks)
21700 - . = ALIGN(PAGE_SIZE);
21701 __smp_locks_end = .;
21702 + . = ALIGN(PAGE_SIZE);
21703 }
21704
21705 -#ifdef CONFIG_X86_64
21706 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21707 - NOSAVE_DATA
21708 - }
21709 -#endif
21710 -
21711 /* BSS */
21712 . = ALIGN(PAGE_SIZE);
21713 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21714 @@ -313,6 +381,7 @@ SECTIONS
21715 __brk_base = .;
21716 . += 64 * 1024; /* 64k alignment slop space */
21717 *(.brk_reservation) /* areas brk users have reserved */
21718 + . = ALIGN(HPAGE_SIZE);
21719 __brk_limit = .;
21720 }
21721
21722 @@ -339,13 +408,12 @@ SECTIONS
21723 * for the boot processor.
21724 */
21725 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21726 -INIT_PER_CPU(gdt_page);
21727 INIT_PER_CPU(irq_stack_union);
21728
21729 /*
21730 * Build-time check on the image size:
21731 */
21732 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21733 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21734 "kernel image bigger than KERNEL_IMAGE_SIZE");
21735
21736 #ifdef CONFIG_SMP
21737 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21738 index 3a3e8c9..1af9465 100644
21739 --- a/arch/x86/kernel/vsyscall_64.c
21740 +++ b/arch/x86/kernel/vsyscall_64.c
21741 @@ -56,15 +56,13 @@
21742 DEFINE_VVAR(int, vgetcpu_mode);
21743 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21744
21745 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21746 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21747
21748 static int __init vsyscall_setup(char *str)
21749 {
21750 if (str) {
21751 if (!strcmp("emulate", str))
21752 vsyscall_mode = EMULATE;
21753 - else if (!strcmp("native", str))
21754 - vsyscall_mode = NATIVE;
21755 else if (!strcmp("none", str))
21756 vsyscall_mode = NONE;
21757 else
21758 @@ -315,8 +313,7 @@ done:
21759 return true;
21760
21761 sigsegv:
21762 - force_sig(SIGSEGV, current);
21763 - return true;
21764 + do_group_exit(SIGKILL);
21765 }
21766
21767 /*
21768 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21769 extern char __vvar_page;
21770 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21771
21772 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21773 - vsyscall_mode == NATIVE
21774 - ? PAGE_KERNEL_VSYSCALL
21775 - : PAGE_KERNEL_VVAR);
21776 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21777 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21778 (unsigned long)VSYSCALL_START);
21779
21780 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21781 index 1330dd1..d220b99 100644
21782 --- a/arch/x86/kernel/x8664_ksyms_64.c
21783 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21784 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21785 EXPORT_SYMBOL(copy_user_generic_unrolled);
21786 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21787 EXPORT_SYMBOL(__copy_user_nocache);
21788 -EXPORT_SYMBOL(_copy_from_user);
21789 -EXPORT_SYMBOL(_copy_to_user);
21790
21791 EXPORT_SYMBOL(copy_page);
21792 EXPORT_SYMBOL(clear_page);
21793 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
21794 index 7a3d075..6cb373d 100644
21795 --- a/arch/x86/kernel/x86_init.c
21796 +++ b/arch/x86/kernel/x86_init.c
21797 @@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
21798 },
21799 };
21800
21801 -struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
21802 +struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
21803 .early_percpu_clock_init = x86_init_noop,
21804 .setup_percpu_clockev = setup_secondary_APIC_clock,
21805 };
21806 @@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
21807 static void default_nmi_init(void) { };
21808 static int default_i8042_detect(void) { return 1; };
21809
21810 -struct x86_platform_ops x86_platform = {
21811 +struct x86_platform_ops x86_platform __read_only = {
21812 .calibrate_tsc = native_calibrate_tsc,
21813 .get_wallclock = mach_get_cmos_time,
21814 .set_wallclock = mach_set_rtc_mmss,
21815 @@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
21816 };
21817
21818 EXPORT_SYMBOL_GPL(x86_platform);
21819 -struct x86_msi_ops x86_msi = {
21820 +struct x86_msi_ops x86_msi __read_only = {
21821 .setup_msi_irqs = native_setup_msi_irqs,
21822 .teardown_msi_irq = native_teardown_msi_irq,
21823 .teardown_msi_irqs = default_teardown_msi_irqs,
21824 .restore_msi_irqs = default_restore_msi_irqs,
21825 };
21826
21827 -struct x86_io_apic_ops x86_io_apic_ops = {
21828 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
21829 .init = native_io_apic_init_mappings,
21830 .read = native_io_apic_read,
21831 .write = native_io_apic_write,
21832 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21833 index ada87a3..afea76d 100644
21834 --- a/arch/x86/kernel/xsave.c
21835 +++ b/arch/x86/kernel/xsave.c
21836 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21837 {
21838 int err;
21839
21840 + buf = (struct xsave_struct __user *)____m(buf);
21841 if (use_xsave())
21842 err = xsave_user(buf);
21843 else if (use_fxsr())
21844 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21845 */
21846 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21847 {
21848 + buf = (void __user *)____m(buf);
21849 if (use_xsave()) {
21850 if ((unsigned long)buf % 64 || fx_only) {
21851 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21852 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21853 index ec79e77..420f5cc 100644
21854 --- a/arch/x86/kvm/cpuid.c
21855 +++ b/arch/x86/kvm/cpuid.c
21856 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21857 struct kvm_cpuid2 *cpuid,
21858 struct kvm_cpuid_entry2 __user *entries)
21859 {
21860 - int r;
21861 + int r, i;
21862
21863 r = -E2BIG;
21864 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21865 goto out;
21866 r = -EFAULT;
21867 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21868 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21869 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21870 goto out;
21871 + for (i = 0; i < cpuid->nent; ++i) {
21872 + struct kvm_cpuid_entry2 cpuid_entry;
21873 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21874 + goto out;
21875 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21876 + }
21877 vcpu->arch.cpuid_nent = cpuid->nent;
21878 kvm_apic_set_version(vcpu);
21879 kvm_x86_ops->cpuid_update(vcpu);
21880 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21881 struct kvm_cpuid2 *cpuid,
21882 struct kvm_cpuid_entry2 __user *entries)
21883 {
21884 - int r;
21885 + int r, i;
21886
21887 r = -E2BIG;
21888 if (cpuid->nent < vcpu->arch.cpuid_nent)
21889 goto out;
21890 r = -EFAULT;
21891 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21892 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21893 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21894 goto out;
21895 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21896 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21897 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21898 + goto out;
21899 + }
21900 return 0;
21901
21902 out:
21903 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21904 index bba39bf..296540a 100644
21905 --- a/arch/x86/kvm/emulate.c
21906 +++ b/arch/x86/kvm/emulate.c
21907 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21908
21909 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21910 do { \
21911 + unsigned long _tmp; \
21912 __asm__ __volatile__ ( \
21913 _PRE_EFLAGS("0", "4", "2") \
21914 _op _suffix " %"_x"3,%1; " \
21915 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21916 /* Raw emulation: instruction has two explicit operands. */
21917 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21918 do { \
21919 - unsigned long _tmp; \
21920 - \
21921 switch ((ctxt)->dst.bytes) { \
21922 case 2: \
21923 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21924 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21925
21926 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21927 do { \
21928 - unsigned long _tmp; \
21929 switch ((ctxt)->dst.bytes) { \
21930 case 1: \
21931 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21932 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21933 index 43e9fad..3b7c059 100644
21934 --- a/arch/x86/kvm/lapic.c
21935 +++ b/arch/x86/kvm/lapic.c
21936 @@ -55,7 +55,7 @@
21937 #define APIC_BUS_CYCLE_NS 1
21938
21939 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21940 -#define apic_debug(fmt, arg...)
21941 +#define apic_debug(fmt, arg...) do {} while (0)
21942
21943 #define APIC_LVT_NUM 6
21944 /* 14 is the version for Xeon and Pentium 8.4.8*/
21945 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21946 index 714e2c0..3f7a086 100644
21947 --- a/arch/x86/kvm/paging_tmpl.h
21948 +++ b/arch/x86/kvm/paging_tmpl.h
21949 @@ -208,7 +208,7 @@ retry_walk:
21950 if (unlikely(kvm_is_error_hva(host_addr)))
21951 goto error;
21952
21953 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21954 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21955 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21956 goto error;
21957 walker->ptep_user[walker->level - 1] = ptep_user;
21958 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21959 index d017df3..61ae42e 100644
21960 --- a/arch/x86/kvm/svm.c
21961 +++ b/arch/x86/kvm/svm.c
21962 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21963 int cpu = raw_smp_processor_id();
21964
21965 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21966 +
21967 + pax_open_kernel();
21968 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21969 + pax_close_kernel();
21970 +
21971 load_TR_desc();
21972 }
21973
21974 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21975 #endif
21976 #endif
21977
21978 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21979 + __set_fs(current_thread_info()->addr_limit);
21980 +#endif
21981 +
21982 reload_tss(vcpu);
21983
21984 local_irq_disable();
21985 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21986 index f858159..4ab7dba 100644
21987 --- a/arch/x86/kvm/vmx.c
21988 +++ b/arch/x86/kvm/vmx.c
21989 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21990 struct desc_struct *descs;
21991
21992 descs = (void *)gdt->address;
21993 +
21994 + pax_open_kernel();
21995 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21996 + pax_close_kernel();
21997 +
21998 load_TR_desc();
21999 }
22000
22001 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
22002 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
22003 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
22004
22005 +#ifdef CONFIG_PAX_PER_CPU_PGD
22006 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
22007 +#endif
22008 +
22009 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
22010 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
22011 vmx->loaded_vmcs->cpu = cpu;
22012 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
22013 if (!cpu_has_vmx_flexpriority())
22014 flexpriority_enabled = 0;
22015
22016 - if (!cpu_has_vmx_tpr_shadow())
22017 - kvm_x86_ops->update_cr8_intercept = NULL;
22018 + if (!cpu_has_vmx_tpr_shadow()) {
22019 + pax_open_kernel();
22020 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
22021 + pax_close_kernel();
22022 + }
22023
22024 if (enable_ept && !cpu_has_vmx_ept_2m_page())
22025 kvm_disable_largepages();
22026 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
22027
22028 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
22029 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
22030 +
22031 +#ifndef CONFIG_PAX_PER_CPU_PGD
22032 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
22033 +#endif
22034
22035 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
22036 #ifdef CONFIG_X86_64
22037 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
22038 native_store_idt(&dt);
22039 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
22040
22041 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
22042 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
22043
22044 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
22045 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
22046 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22047 "jmp 2f \n\t"
22048 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
22049 "2: "
22050 +
22051 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22052 + "ljmp %[cs],$3f\n\t"
22053 + "3: "
22054 +#endif
22055 +
22056 /* Save guest registers, load host registers, keep flags */
22057 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
22058 "pop %0 \n\t"
22059 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22060 #endif
22061 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
22062 [wordsize]"i"(sizeof(ulong))
22063 +
22064 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22065 + ,[cs]"i"(__KERNEL_CS)
22066 +#endif
22067 +
22068 : "cc", "memory"
22069 #ifdef CONFIG_X86_64
22070 , "rax", "rbx", "rdi", "rsi"
22071 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22072 if (debugctlmsr)
22073 update_debugctlmsr(debugctlmsr);
22074
22075 -#ifndef CONFIG_X86_64
22076 +#ifdef CONFIG_X86_32
22077 /*
22078 * The sysexit path does not restore ds/es, so we must set them to
22079 * a reasonable value ourselves.
22080 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22081 * may be executed in interrupt context, which saves and restore segments
22082 * around it, nullifying its effect.
22083 */
22084 - loadsegment(ds, __USER_DS);
22085 - loadsegment(es, __USER_DS);
22086 + loadsegment(ds, __KERNEL_DS);
22087 + loadsegment(es, __KERNEL_DS);
22088 + loadsegment(ss, __KERNEL_DS);
22089 +
22090 +#ifdef CONFIG_PAX_KERNEXEC
22091 + loadsegment(fs, __KERNEL_PERCPU);
22092 +#endif
22093 +
22094 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22095 + __set_fs(current_thread_info()->addr_limit);
22096 +#endif
22097 +
22098 #endif
22099
22100 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22101 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22102 index 4f76417..93429b5 100644
22103 --- a/arch/x86/kvm/x86.c
22104 +++ b/arch/x86/kvm/x86.c
22105 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22106 {
22107 struct kvm *kvm = vcpu->kvm;
22108 int lm = is_long_mode(vcpu);
22109 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22110 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22111 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22112 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22113 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22114 : kvm->arch.xen_hvm_config.blob_size_32;
22115 u32 page_num = data & ~PAGE_MASK;
22116 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22117 if (n < msr_list.nmsrs)
22118 goto out;
22119 r = -EFAULT;
22120 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22121 + goto out;
22122 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22123 num_msrs_to_save * sizeof(u32)))
22124 goto out;
22125 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22126 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22127 struct kvm_interrupt *irq)
22128 {
22129 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22130 + if (irq->irq >= KVM_NR_INTERRUPTS)
22131 return -EINVAL;
22132 if (irqchip_in_kernel(vcpu->kvm))
22133 return -ENXIO;
22134 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22135 kvm_mmu_set_mmio_spte_mask(mask);
22136 }
22137
22138 -int kvm_arch_init(void *opaque)
22139 +int kvm_arch_init(const void *opaque)
22140 {
22141 int r;
22142 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22143 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22144 index 642d880..44e0f3f 100644
22145 --- a/arch/x86/lguest/boot.c
22146 +++ b/arch/x86/lguest/boot.c
22147 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22148 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22149 * Launcher to reboot us.
22150 */
22151 -static void lguest_restart(char *reason)
22152 +static __noreturn void lguest_restart(char *reason)
22153 {
22154 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22155 + BUG();
22156 }
22157
22158 /*G:050
22159 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22160 index 00933d5..3a64af9 100644
22161 --- a/arch/x86/lib/atomic64_386_32.S
22162 +++ b/arch/x86/lib/atomic64_386_32.S
22163 @@ -48,6 +48,10 @@ BEGIN(read)
22164 movl (v), %eax
22165 movl 4(v), %edx
22166 RET_ENDP
22167 +BEGIN(read_unchecked)
22168 + movl (v), %eax
22169 + movl 4(v), %edx
22170 +RET_ENDP
22171 #undef v
22172
22173 #define v %esi
22174 @@ -55,6 +59,10 @@ BEGIN(set)
22175 movl %ebx, (v)
22176 movl %ecx, 4(v)
22177 RET_ENDP
22178 +BEGIN(set_unchecked)
22179 + movl %ebx, (v)
22180 + movl %ecx, 4(v)
22181 +RET_ENDP
22182 #undef v
22183
22184 #define v %esi
22185 @@ -70,6 +78,20 @@ RET_ENDP
22186 BEGIN(add)
22187 addl %eax, (v)
22188 adcl %edx, 4(v)
22189 +
22190 +#ifdef CONFIG_PAX_REFCOUNT
22191 + jno 0f
22192 + subl %eax, (v)
22193 + sbbl %edx, 4(v)
22194 + int $4
22195 +0:
22196 + _ASM_EXTABLE(0b, 0b)
22197 +#endif
22198 +
22199 +RET_ENDP
22200 +BEGIN(add_unchecked)
22201 + addl %eax, (v)
22202 + adcl %edx, 4(v)
22203 RET_ENDP
22204 #undef v
22205
22206 @@ -77,6 +99,24 @@ RET_ENDP
22207 BEGIN(add_return)
22208 addl (v), %eax
22209 adcl 4(v), %edx
22210 +
22211 +#ifdef CONFIG_PAX_REFCOUNT
22212 + into
22213 +1234:
22214 + _ASM_EXTABLE(1234b, 2f)
22215 +#endif
22216 +
22217 + movl %eax, (v)
22218 + movl %edx, 4(v)
22219 +
22220 +#ifdef CONFIG_PAX_REFCOUNT
22221 +2:
22222 +#endif
22223 +
22224 +RET_ENDP
22225 +BEGIN(add_return_unchecked)
22226 + addl (v), %eax
22227 + adcl 4(v), %edx
22228 movl %eax, (v)
22229 movl %edx, 4(v)
22230 RET_ENDP
22231 @@ -86,6 +126,20 @@ RET_ENDP
22232 BEGIN(sub)
22233 subl %eax, (v)
22234 sbbl %edx, 4(v)
22235 +
22236 +#ifdef CONFIG_PAX_REFCOUNT
22237 + jno 0f
22238 + addl %eax, (v)
22239 + adcl %edx, 4(v)
22240 + int $4
22241 +0:
22242 + _ASM_EXTABLE(0b, 0b)
22243 +#endif
22244 +
22245 +RET_ENDP
22246 +BEGIN(sub_unchecked)
22247 + subl %eax, (v)
22248 + sbbl %edx, 4(v)
22249 RET_ENDP
22250 #undef v
22251
22252 @@ -96,6 +150,27 @@ BEGIN(sub_return)
22253 sbbl $0, %edx
22254 addl (v), %eax
22255 adcl 4(v), %edx
22256 +
22257 +#ifdef CONFIG_PAX_REFCOUNT
22258 + into
22259 +1234:
22260 + _ASM_EXTABLE(1234b, 2f)
22261 +#endif
22262 +
22263 + movl %eax, (v)
22264 + movl %edx, 4(v)
22265 +
22266 +#ifdef CONFIG_PAX_REFCOUNT
22267 +2:
22268 +#endif
22269 +
22270 +RET_ENDP
22271 +BEGIN(sub_return_unchecked)
22272 + negl %edx
22273 + negl %eax
22274 + sbbl $0, %edx
22275 + addl (v), %eax
22276 + adcl 4(v), %edx
22277 movl %eax, (v)
22278 movl %edx, 4(v)
22279 RET_ENDP
22280 @@ -105,6 +180,20 @@ RET_ENDP
22281 BEGIN(inc)
22282 addl $1, (v)
22283 adcl $0, 4(v)
22284 +
22285 +#ifdef CONFIG_PAX_REFCOUNT
22286 + jno 0f
22287 + subl $1, (v)
22288 + sbbl $0, 4(v)
22289 + int $4
22290 +0:
22291 + _ASM_EXTABLE(0b, 0b)
22292 +#endif
22293 +
22294 +RET_ENDP
22295 +BEGIN(inc_unchecked)
22296 + addl $1, (v)
22297 + adcl $0, 4(v)
22298 RET_ENDP
22299 #undef v
22300
22301 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22302 movl 4(v), %edx
22303 addl $1, %eax
22304 adcl $0, %edx
22305 +
22306 +#ifdef CONFIG_PAX_REFCOUNT
22307 + into
22308 +1234:
22309 + _ASM_EXTABLE(1234b, 2f)
22310 +#endif
22311 +
22312 + movl %eax, (v)
22313 + movl %edx, 4(v)
22314 +
22315 +#ifdef CONFIG_PAX_REFCOUNT
22316 +2:
22317 +#endif
22318 +
22319 +RET_ENDP
22320 +BEGIN(inc_return_unchecked)
22321 + movl (v), %eax
22322 + movl 4(v), %edx
22323 + addl $1, %eax
22324 + adcl $0, %edx
22325 movl %eax, (v)
22326 movl %edx, 4(v)
22327 RET_ENDP
22328 @@ -123,6 +232,20 @@ RET_ENDP
22329 BEGIN(dec)
22330 subl $1, (v)
22331 sbbl $0, 4(v)
22332 +
22333 +#ifdef CONFIG_PAX_REFCOUNT
22334 + jno 0f
22335 + addl $1, (v)
22336 + adcl $0, 4(v)
22337 + int $4
22338 +0:
22339 + _ASM_EXTABLE(0b, 0b)
22340 +#endif
22341 +
22342 +RET_ENDP
22343 +BEGIN(dec_unchecked)
22344 + subl $1, (v)
22345 + sbbl $0, 4(v)
22346 RET_ENDP
22347 #undef v
22348
22349 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22350 movl 4(v), %edx
22351 subl $1, %eax
22352 sbbl $0, %edx
22353 +
22354 +#ifdef CONFIG_PAX_REFCOUNT
22355 + into
22356 +1234:
22357 + _ASM_EXTABLE(1234b, 2f)
22358 +#endif
22359 +
22360 + movl %eax, (v)
22361 + movl %edx, 4(v)
22362 +
22363 +#ifdef CONFIG_PAX_REFCOUNT
22364 +2:
22365 +#endif
22366 +
22367 +RET_ENDP
22368 +BEGIN(dec_return_unchecked)
22369 + movl (v), %eax
22370 + movl 4(v), %edx
22371 + subl $1, %eax
22372 + sbbl $0, %edx
22373 movl %eax, (v)
22374 movl %edx, 4(v)
22375 RET_ENDP
22376 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22377 adcl %edx, %edi
22378 addl (v), %eax
22379 adcl 4(v), %edx
22380 +
22381 +#ifdef CONFIG_PAX_REFCOUNT
22382 + into
22383 +1234:
22384 + _ASM_EXTABLE(1234b, 2f)
22385 +#endif
22386 +
22387 cmpl %eax, %ecx
22388 je 3f
22389 1:
22390 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22391 1:
22392 addl $1, %eax
22393 adcl $0, %edx
22394 +
22395 +#ifdef CONFIG_PAX_REFCOUNT
22396 + into
22397 +1234:
22398 + _ASM_EXTABLE(1234b, 2f)
22399 +#endif
22400 +
22401 movl %eax, (v)
22402 movl %edx, 4(v)
22403 movl $1, %eax
22404 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22405 movl 4(v), %edx
22406 subl $1, %eax
22407 sbbl $0, %edx
22408 +
22409 +#ifdef CONFIG_PAX_REFCOUNT
22410 + into
22411 +1234:
22412 + _ASM_EXTABLE(1234b, 1f)
22413 +#endif
22414 +
22415 js 1f
22416 movl %eax, (v)
22417 movl %edx, 4(v)
22418 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22419 index f5cc9eb..51fa319 100644
22420 --- a/arch/x86/lib/atomic64_cx8_32.S
22421 +++ b/arch/x86/lib/atomic64_cx8_32.S
22422 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22423 CFI_STARTPROC
22424
22425 read64 %ecx
22426 + pax_force_retaddr
22427 ret
22428 CFI_ENDPROC
22429 ENDPROC(atomic64_read_cx8)
22430
22431 +ENTRY(atomic64_read_unchecked_cx8)
22432 + CFI_STARTPROC
22433 +
22434 + read64 %ecx
22435 + pax_force_retaddr
22436 + ret
22437 + CFI_ENDPROC
22438 +ENDPROC(atomic64_read_unchecked_cx8)
22439 +
22440 ENTRY(atomic64_set_cx8)
22441 CFI_STARTPROC
22442
22443 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22444 cmpxchg8b (%esi)
22445 jne 1b
22446
22447 + pax_force_retaddr
22448 ret
22449 CFI_ENDPROC
22450 ENDPROC(atomic64_set_cx8)
22451
22452 +ENTRY(atomic64_set_unchecked_cx8)
22453 + CFI_STARTPROC
22454 +
22455 +1:
22456 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22457 + * are atomic on 586 and newer */
22458 + cmpxchg8b (%esi)
22459 + jne 1b
22460 +
22461 + pax_force_retaddr
22462 + ret
22463 + CFI_ENDPROC
22464 +ENDPROC(atomic64_set_unchecked_cx8)
22465 +
22466 ENTRY(atomic64_xchg_cx8)
22467 CFI_STARTPROC
22468
22469 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22470 cmpxchg8b (%esi)
22471 jne 1b
22472
22473 + pax_force_retaddr
22474 ret
22475 CFI_ENDPROC
22476 ENDPROC(atomic64_xchg_cx8)
22477
22478 -.macro addsub_return func ins insc
22479 -ENTRY(atomic64_\func\()_return_cx8)
22480 +.macro addsub_return func ins insc unchecked=""
22481 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22482 CFI_STARTPROC
22483 SAVE ebp
22484 SAVE ebx
22485 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22486 movl %edx, %ecx
22487 \ins\()l %esi, %ebx
22488 \insc\()l %edi, %ecx
22489 +
22490 +.ifb \unchecked
22491 +#ifdef CONFIG_PAX_REFCOUNT
22492 + into
22493 +2:
22494 + _ASM_EXTABLE(2b, 3f)
22495 +#endif
22496 +.endif
22497 +
22498 LOCK_PREFIX
22499 cmpxchg8b (%ebp)
22500 jne 1b
22501 -
22502 -10:
22503 movl %ebx, %eax
22504 movl %ecx, %edx
22505 +
22506 +.ifb \unchecked
22507 +#ifdef CONFIG_PAX_REFCOUNT
22508 +3:
22509 +#endif
22510 +.endif
22511 +
22512 RESTORE edi
22513 RESTORE esi
22514 RESTORE ebx
22515 RESTORE ebp
22516 + pax_force_retaddr
22517 ret
22518 CFI_ENDPROC
22519 -ENDPROC(atomic64_\func\()_return_cx8)
22520 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22521 .endm
22522
22523 addsub_return add add adc
22524 addsub_return sub sub sbb
22525 +addsub_return add add adc _unchecked
22526 +addsub_return sub sub sbb _unchecked
22527
22528 -.macro incdec_return func ins insc
22529 -ENTRY(atomic64_\func\()_return_cx8)
22530 +.macro incdec_return func ins insc unchecked=""
22531 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22532 CFI_STARTPROC
22533 SAVE ebx
22534
22535 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22536 movl %edx, %ecx
22537 \ins\()l $1, %ebx
22538 \insc\()l $0, %ecx
22539 +
22540 +.ifb \unchecked
22541 +#ifdef CONFIG_PAX_REFCOUNT
22542 + into
22543 +2:
22544 + _ASM_EXTABLE(2b, 3f)
22545 +#endif
22546 +.endif
22547 +
22548 LOCK_PREFIX
22549 cmpxchg8b (%esi)
22550 jne 1b
22551
22552 -10:
22553 movl %ebx, %eax
22554 movl %ecx, %edx
22555 +
22556 +.ifb \unchecked
22557 +#ifdef CONFIG_PAX_REFCOUNT
22558 +3:
22559 +#endif
22560 +.endif
22561 +
22562 RESTORE ebx
22563 + pax_force_retaddr
22564 ret
22565 CFI_ENDPROC
22566 -ENDPROC(atomic64_\func\()_return_cx8)
22567 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22568 .endm
22569
22570 incdec_return inc add adc
22571 incdec_return dec sub sbb
22572 +incdec_return inc add adc _unchecked
22573 +incdec_return dec sub sbb _unchecked
22574
22575 ENTRY(atomic64_dec_if_positive_cx8)
22576 CFI_STARTPROC
22577 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22578 movl %edx, %ecx
22579 subl $1, %ebx
22580 sbb $0, %ecx
22581 +
22582 +#ifdef CONFIG_PAX_REFCOUNT
22583 + into
22584 +1234:
22585 + _ASM_EXTABLE(1234b, 2f)
22586 +#endif
22587 +
22588 js 2f
22589 LOCK_PREFIX
22590 cmpxchg8b (%esi)
22591 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22592 movl %ebx, %eax
22593 movl %ecx, %edx
22594 RESTORE ebx
22595 + pax_force_retaddr
22596 ret
22597 CFI_ENDPROC
22598 ENDPROC(atomic64_dec_if_positive_cx8)
22599 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22600 movl %edx, %ecx
22601 addl %ebp, %ebx
22602 adcl %edi, %ecx
22603 +
22604 +#ifdef CONFIG_PAX_REFCOUNT
22605 + into
22606 +1234:
22607 + _ASM_EXTABLE(1234b, 3f)
22608 +#endif
22609 +
22610 LOCK_PREFIX
22611 cmpxchg8b (%esi)
22612 jne 1b
22613 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22614 CFI_ADJUST_CFA_OFFSET -8
22615 RESTORE ebx
22616 RESTORE ebp
22617 + pax_force_retaddr
22618 ret
22619 4:
22620 cmpl %edx, 4(%esp)
22621 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22622 xorl %ecx, %ecx
22623 addl $1, %ebx
22624 adcl %edx, %ecx
22625 +
22626 +#ifdef CONFIG_PAX_REFCOUNT
22627 + into
22628 +1234:
22629 + _ASM_EXTABLE(1234b, 3f)
22630 +#endif
22631 +
22632 LOCK_PREFIX
22633 cmpxchg8b (%esi)
22634 jne 1b
22635 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22636 movl $1, %eax
22637 3:
22638 RESTORE ebx
22639 + pax_force_retaddr
22640 ret
22641 CFI_ENDPROC
22642 ENDPROC(atomic64_inc_not_zero_cx8)
22643 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22644 index 2af5df3..62b1a5a 100644
22645 --- a/arch/x86/lib/checksum_32.S
22646 +++ b/arch/x86/lib/checksum_32.S
22647 @@ -29,7 +29,8 @@
22648 #include <asm/dwarf2.h>
22649 #include <asm/errno.h>
22650 #include <asm/asm.h>
22651 -
22652 +#include <asm/segment.h>
22653 +
22654 /*
22655 * computes a partial checksum, e.g. for TCP/UDP fragments
22656 */
22657 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22658
22659 #define ARGBASE 16
22660 #define FP 12
22661 -
22662 -ENTRY(csum_partial_copy_generic)
22663 +
22664 +ENTRY(csum_partial_copy_generic_to_user)
22665 CFI_STARTPROC
22666 +
22667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22668 + pushl_cfi %gs
22669 + popl_cfi %es
22670 + jmp csum_partial_copy_generic
22671 +#endif
22672 +
22673 +ENTRY(csum_partial_copy_generic_from_user)
22674 +
22675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22676 + pushl_cfi %gs
22677 + popl_cfi %ds
22678 +#endif
22679 +
22680 +ENTRY(csum_partial_copy_generic)
22681 subl $4,%esp
22682 CFI_ADJUST_CFA_OFFSET 4
22683 pushl_cfi %edi
22684 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22685 jmp 4f
22686 SRC(1: movw (%esi), %bx )
22687 addl $2, %esi
22688 -DST( movw %bx, (%edi) )
22689 +DST( movw %bx, %es:(%edi) )
22690 addl $2, %edi
22691 addw %bx, %ax
22692 adcl $0, %eax
22693 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22694 SRC(1: movl (%esi), %ebx )
22695 SRC( movl 4(%esi), %edx )
22696 adcl %ebx, %eax
22697 -DST( movl %ebx, (%edi) )
22698 +DST( movl %ebx, %es:(%edi) )
22699 adcl %edx, %eax
22700 -DST( movl %edx, 4(%edi) )
22701 +DST( movl %edx, %es:4(%edi) )
22702
22703 SRC( movl 8(%esi), %ebx )
22704 SRC( movl 12(%esi), %edx )
22705 adcl %ebx, %eax
22706 -DST( movl %ebx, 8(%edi) )
22707 +DST( movl %ebx, %es:8(%edi) )
22708 adcl %edx, %eax
22709 -DST( movl %edx, 12(%edi) )
22710 +DST( movl %edx, %es:12(%edi) )
22711
22712 SRC( movl 16(%esi), %ebx )
22713 SRC( movl 20(%esi), %edx )
22714 adcl %ebx, %eax
22715 -DST( movl %ebx, 16(%edi) )
22716 +DST( movl %ebx, %es:16(%edi) )
22717 adcl %edx, %eax
22718 -DST( movl %edx, 20(%edi) )
22719 +DST( movl %edx, %es:20(%edi) )
22720
22721 SRC( movl 24(%esi), %ebx )
22722 SRC( movl 28(%esi), %edx )
22723 adcl %ebx, %eax
22724 -DST( movl %ebx, 24(%edi) )
22725 +DST( movl %ebx, %es:24(%edi) )
22726 adcl %edx, %eax
22727 -DST( movl %edx, 28(%edi) )
22728 +DST( movl %edx, %es:28(%edi) )
22729
22730 lea 32(%esi), %esi
22731 lea 32(%edi), %edi
22732 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22733 shrl $2, %edx # This clears CF
22734 SRC(3: movl (%esi), %ebx )
22735 adcl %ebx, %eax
22736 -DST( movl %ebx, (%edi) )
22737 +DST( movl %ebx, %es:(%edi) )
22738 lea 4(%esi), %esi
22739 lea 4(%edi), %edi
22740 dec %edx
22741 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22742 jb 5f
22743 SRC( movw (%esi), %cx )
22744 leal 2(%esi), %esi
22745 -DST( movw %cx, (%edi) )
22746 +DST( movw %cx, %es:(%edi) )
22747 leal 2(%edi), %edi
22748 je 6f
22749 shll $16,%ecx
22750 SRC(5: movb (%esi), %cl )
22751 -DST( movb %cl, (%edi) )
22752 +DST( movb %cl, %es:(%edi) )
22753 6: addl %ecx, %eax
22754 adcl $0, %eax
22755 7:
22756 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22757
22758 6001:
22759 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22760 - movl $-EFAULT, (%ebx)
22761 + movl $-EFAULT, %ss:(%ebx)
22762
22763 # zero the complete destination - computing the rest
22764 # is too much work
22765 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22766
22767 6002:
22768 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22769 - movl $-EFAULT,(%ebx)
22770 + movl $-EFAULT,%ss:(%ebx)
22771 jmp 5000b
22772
22773 .previous
22774
22775 + pushl_cfi %ss
22776 + popl_cfi %ds
22777 + pushl_cfi %ss
22778 + popl_cfi %es
22779 popl_cfi %ebx
22780 CFI_RESTORE ebx
22781 popl_cfi %esi
22782 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22783 popl_cfi %ecx # equivalent to addl $4,%esp
22784 ret
22785 CFI_ENDPROC
22786 -ENDPROC(csum_partial_copy_generic)
22787 +ENDPROC(csum_partial_copy_generic_to_user)
22788
22789 #else
22790
22791 /* Version for PentiumII/PPro */
22792
22793 #define ROUND1(x) \
22794 + nop; nop; nop; \
22795 SRC(movl x(%esi), %ebx ) ; \
22796 addl %ebx, %eax ; \
22797 - DST(movl %ebx, x(%edi) ) ;
22798 + DST(movl %ebx, %es:x(%edi)) ;
22799
22800 #define ROUND(x) \
22801 + nop; nop; nop; \
22802 SRC(movl x(%esi), %ebx ) ; \
22803 adcl %ebx, %eax ; \
22804 - DST(movl %ebx, x(%edi) ) ;
22805 + DST(movl %ebx, %es:x(%edi)) ;
22806
22807 #define ARGBASE 12
22808 -
22809 -ENTRY(csum_partial_copy_generic)
22810 +
22811 +ENTRY(csum_partial_copy_generic_to_user)
22812 CFI_STARTPROC
22813 +
22814 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22815 + pushl_cfi %gs
22816 + popl_cfi %es
22817 + jmp csum_partial_copy_generic
22818 +#endif
22819 +
22820 +ENTRY(csum_partial_copy_generic_from_user)
22821 +
22822 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22823 + pushl_cfi %gs
22824 + popl_cfi %ds
22825 +#endif
22826 +
22827 +ENTRY(csum_partial_copy_generic)
22828 pushl_cfi %ebx
22829 CFI_REL_OFFSET ebx, 0
22830 pushl_cfi %edi
22831 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22832 subl %ebx, %edi
22833 lea -1(%esi),%edx
22834 andl $-32,%edx
22835 - lea 3f(%ebx,%ebx), %ebx
22836 + lea 3f(%ebx,%ebx,2), %ebx
22837 testl %esi, %esi
22838 jmp *%ebx
22839 1: addl $64,%esi
22840 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22841 jb 5f
22842 SRC( movw (%esi), %dx )
22843 leal 2(%esi), %esi
22844 -DST( movw %dx, (%edi) )
22845 +DST( movw %dx, %es:(%edi) )
22846 leal 2(%edi), %edi
22847 je 6f
22848 shll $16,%edx
22849 5:
22850 SRC( movb (%esi), %dl )
22851 -DST( movb %dl, (%edi) )
22852 +DST( movb %dl, %es:(%edi) )
22853 6: addl %edx, %eax
22854 adcl $0, %eax
22855 7:
22856 .section .fixup, "ax"
22857 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22858 - movl $-EFAULT, (%ebx)
22859 + movl $-EFAULT, %ss:(%ebx)
22860 # zero the complete destination (computing the rest is too much work)
22861 movl ARGBASE+8(%esp),%edi # dst
22862 movl ARGBASE+12(%esp),%ecx # len
22863 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22864 rep; stosb
22865 jmp 7b
22866 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22867 - movl $-EFAULT, (%ebx)
22868 + movl $-EFAULT, %ss:(%ebx)
22869 jmp 7b
22870 .previous
22871
22872 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22873 + pushl_cfi %ss
22874 + popl_cfi %ds
22875 + pushl_cfi %ss
22876 + popl_cfi %es
22877 +#endif
22878 +
22879 popl_cfi %esi
22880 CFI_RESTORE esi
22881 popl_cfi %edi
22882 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22883 CFI_RESTORE ebx
22884 ret
22885 CFI_ENDPROC
22886 -ENDPROC(csum_partial_copy_generic)
22887 +ENDPROC(csum_partial_copy_generic_to_user)
22888
22889 #undef ROUND
22890 #undef ROUND1
22891 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22892 index f2145cf..cea889d 100644
22893 --- a/arch/x86/lib/clear_page_64.S
22894 +++ b/arch/x86/lib/clear_page_64.S
22895 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22896 movl $4096/8,%ecx
22897 xorl %eax,%eax
22898 rep stosq
22899 + pax_force_retaddr
22900 ret
22901 CFI_ENDPROC
22902 ENDPROC(clear_page_c)
22903 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22904 movl $4096,%ecx
22905 xorl %eax,%eax
22906 rep stosb
22907 + pax_force_retaddr
22908 ret
22909 CFI_ENDPROC
22910 ENDPROC(clear_page_c_e)
22911 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22912 leaq 64(%rdi),%rdi
22913 jnz .Lloop
22914 nop
22915 + pax_force_retaddr
22916 ret
22917 CFI_ENDPROC
22918 .Lclear_page_end:
22919 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22920
22921 #include <asm/cpufeature.h>
22922
22923 - .section .altinstr_replacement,"ax"
22924 + .section .altinstr_replacement,"a"
22925 1: .byte 0xeb /* jmp <disp8> */
22926 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22927 2: .byte 0xeb /* jmp <disp8> */
22928 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22929 index 1e572c5..2a162cd 100644
22930 --- a/arch/x86/lib/cmpxchg16b_emu.S
22931 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22932 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22933
22934 popf
22935 mov $1, %al
22936 + pax_force_retaddr
22937 ret
22938
22939 not_same:
22940 popf
22941 xor %al,%al
22942 + pax_force_retaddr
22943 ret
22944
22945 CFI_ENDPROC
22946 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22947 index 6b34d04..dccb07f 100644
22948 --- a/arch/x86/lib/copy_page_64.S
22949 +++ b/arch/x86/lib/copy_page_64.S
22950 @@ -9,6 +9,7 @@ copy_page_c:
22951 CFI_STARTPROC
22952 movl $4096/8,%ecx
22953 rep movsq
22954 + pax_force_retaddr
22955 ret
22956 CFI_ENDPROC
22957 ENDPROC(copy_page_c)
22958 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22959
22960 ENTRY(copy_page)
22961 CFI_STARTPROC
22962 - subq $2*8,%rsp
22963 - CFI_ADJUST_CFA_OFFSET 2*8
22964 + subq $3*8,%rsp
22965 + CFI_ADJUST_CFA_OFFSET 3*8
22966 movq %rbx,(%rsp)
22967 CFI_REL_OFFSET rbx, 0
22968 movq %r12,1*8(%rsp)
22969 CFI_REL_OFFSET r12, 1*8
22970 + movq %r13,2*8(%rsp)
22971 + CFI_REL_OFFSET r13, 2*8
22972
22973 movl $(4096/64)-5,%ecx
22974 .p2align 4
22975 @@ -37,7 +40,7 @@ ENTRY(copy_page)
22976 movq 16 (%rsi), %rdx
22977 movq 24 (%rsi), %r8
22978 movq 32 (%rsi), %r9
22979 - movq 40 (%rsi), %r10
22980 + movq 40 (%rsi), %r13
22981 movq 48 (%rsi), %r11
22982 movq 56 (%rsi), %r12
22983
22984 @@ -48,7 +51,7 @@ ENTRY(copy_page)
22985 movq %rdx, 16 (%rdi)
22986 movq %r8, 24 (%rdi)
22987 movq %r9, 32 (%rdi)
22988 - movq %r10, 40 (%rdi)
22989 + movq %r13, 40 (%rdi)
22990 movq %r11, 48 (%rdi)
22991 movq %r12, 56 (%rdi)
22992
22993 @@ -67,7 +70,7 @@ ENTRY(copy_page)
22994 movq 16 (%rsi), %rdx
22995 movq 24 (%rsi), %r8
22996 movq 32 (%rsi), %r9
22997 - movq 40 (%rsi), %r10
22998 + movq 40 (%rsi), %r13
22999 movq 48 (%rsi), %r11
23000 movq 56 (%rsi), %r12
23001
23002 @@ -76,7 +79,7 @@ ENTRY(copy_page)
23003 movq %rdx, 16 (%rdi)
23004 movq %r8, 24 (%rdi)
23005 movq %r9, 32 (%rdi)
23006 - movq %r10, 40 (%rdi)
23007 + movq %r13, 40 (%rdi)
23008 movq %r11, 48 (%rdi)
23009 movq %r12, 56 (%rdi)
23010
23011 @@ -89,8 +92,11 @@ ENTRY(copy_page)
23012 CFI_RESTORE rbx
23013 movq 1*8(%rsp),%r12
23014 CFI_RESTORE r12
23015 - addq $2*8,%rsp
23016 - CFI_ADJUST_CFA_OFFSET -2*8
23017 + movq 2*8(%rsp),%r13
23018 + CFI_RESTORE r13
23019 + addq $3*8,%rsp
23020 + CFI_ADJUST_CFA_OFFSET -3*8
23021 + pax_force_retaddr
23022 ret
23023 .Lcopy_page_end:
23024 CFI_ENDPROC
23025 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
23026
23027 #include <asm/cpufeature.h>
23028
23029 - .section .altinstr_replacement,"ax"
23030 + .section .altinstr_replacement,"a"
23031 1: .byte 0xeb /* jmp <disp8> */
23032 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23033 2:
23034 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23035 index a30ca15..d25fab6 100644
23036 --- a/arch/x86/lib/copy_user_64.S
23037 +++ b/arch/x86/lib/copy_user_64.S
23038 @@ -18,6 +18,7 @@
23039 #include <asm/alternative-asm.h>
23040 #include <asm/asm.h>
23041 #include <asm/smap.h>
23042 +#include <asm/pgtable.h>
23043
23044 /*
23045 * By placing feature2 after feature1 in altinstructions section, we logically
23046 @@ -31,7 +32,7 @@
23047 .byte 0xe9 /* 32bit jump */
23048 .long \orig-1f /* by default jump to orig */
23049 1:
23050 - .section .altinstr_replacement,"ax"
23051 + .section .altinstr_replacement,"a"
23052 2: .byte 0xe9 /* near jump with 32bit immediate */
23053 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23054 3: .byte 0xe9 /* near jump with 32bit immediate */
23055 @@ -70,47 +71,20 @@
23056 #endif
23057 .endm
23058
23059 -/* Standard copy_to_user with segment limit checking */
23060 -ENTRY(_copy_to_user)
23061 - CFI_STARTPROC
23062 - GET_THREAD_INFO(%rax)
23063 - movq %rdi,%rcx
23064 - addq %rdx,%rcx
23065 - jc bad_to_user
23066 - cmpq TI_addr_limit(%rax),%rcx
23067 - ja bad_to_user
23068 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23069 - copy_user_generic_unrolled,copy_user_generic_string, \
23070 - copy_user_enhanced_fast_string
23071 - CFI_ENDPROC
23072 -ENDPROC(_copy_to_user)
23073 -
23074 -/* Standard copy_from_user with segment limit checking */
23075 -ENTRY(_copy_from_user)
23076 - CFI_STARTPROC
23077 - GET_THREAD_INFO(%rax)
23078 - movq %rsi,%rcx
23079 - addq %rdx,%rcx
23080 - jc bad_from_user
23081 - cmpq TI_addr_limit(%rax),%rcx
23082 - ja bad_from_user
23083 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23084 - copy_user_generic_unrolled,copy_user_generic_string, \
23085 - copy_user_enhanced_fast_string
23086 - CFI_ENDPROC
23087 -ENDPROC(_copy_from_user)
23088 -
23089 .section .fixup,"ax"
23090 /* must zero dest */
23091 ENTRY(bad_from_user)
23092 bad_from_user:
23093 CFI_STARTPROC
23094 + testl %edx,%edx
23095 + js bad_to_user
23096 movl %edx,%ecx
23097 xorl %eax,%eax
23098 rep
23099 stosb
23100 bad_to_user:
23101 movl %edx,%eax
23102 + pax_force_retaddr
23103 ret
23104 CFI_ENDPROC
23105 ENDPROC(bad_from_user)
23106 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23107 jz 17f
23108 1: movq (%rsi),%r8
23109 2: movq 1*8(%rsi),%r9
23110 -3: movq 2*8(%rsi),%r10
23111 +3: movq 2*8(%rsi),%rax
23112 4: movq 3*8(%rsi),%r11
23113 5: movq %r8,(%rdi)
23114 6: movq %r9,1*8(%rdi)
23115 -7: movq %r10,2*8(%rdi)
23116 +7: movq %rax,2*8(%rdi)
23117 8: movq %r11,3*8(%rdi)
23118 9: movq 4*8(%rsi),%r8
23119 10: movq 5*8(%rsi),%r9
23120 -11: movq 6*8(%rsi),%r10
23121 +11: movq 6*8(%rsi),%rax
23122 12: movq 7*8(%rsi),%r11
23123 13: movq %r8,4*8(%rdi)
23124 14: movq %r9,5*8(%rdi)
23125 -15: movq %r10,6*8(%rdi)
23126 +15: movq %rax,6*8(%rdi)
23127 16: movq %r11,7*8(%rdi)
23128 leaq 64(%rsi),%rsi
23129 leaq 64(%rdi),%rdi
23130 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23131 jnz 21b
23132 23: xor %eax,%eax
23133 ASM_CLAC
23134 + pax_force_retaddr
23135 ret
23136
23137 .section .fixup,"ax"
23138 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23139 movsb
23140 4: xorl %eax,%eax
23141 ASM_CLAC
23142 + pax_force_retaddr
23143 ret
23144
23145 .section .fixup,"ax"
23146 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23147 movsb
23148 2: xorl %eax,%eax
23149 ASM_CLAC
23150 + pax_force_retaddr
23151 ret
23152
23153 .section .fixup,"ax"
23154 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23155 index 6a4f43c..f5f9e26 100644
23156 --- a/arch/x86/lib/copy_user_nocache_64.S
23157 +++ b/arch/x86/lib/copy_user_nocache_64.S
23158 @@ -8,6 +8,7 @@
23159
23160 #include <linux/linkage.h>
23161 #include <asm/dwarf2.h>
23162 +#include <asm/alternative-asm.h>
23163
23164 #define FIX_ALIGNMENT 1
23165
23166 @@ -16,6 +17,7 @@
23167 #include <asm/thread_info.h>
23168 #include <asm/asm.h>
23169 #include <asm/smap.h>
23170 +#include <asm/pgtable.h>
23171
23172 .macro ALIGN_DESTINATION
23173 #ifdef FIX_ALIGNMENT
23174 @@ -49,6 +51,15 @@
23175 */
23176 ENTRY(__copy_user_nocache)
23177 CFI_STARTPROC
23178 +
23179 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23180 + mov $PAX_USER_SHADOW_BASE,%rcx
23181 + cmp %rcx,%rsi
23182 + jae 1f
23183 + add %rcx,%rsi
23184 +1:
23185 +#endif
23186 +
23187 ASM_STAC
23188 cmpl $8,%edx
23189 jb 20f /* less then 8 bytes, go to byte copy loop */
23190 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23191 jz 17f
23192 1: movq (%rsi),%r8
23193 2: movq 1*8(%rsi),%r9
23194 -3: movq 2*8(%rsi),%r10
23195 +3: movq 2*8(%rsi),%rax
23196 4: movq 3*8(%rsi),%r11
23197 5: movnti %r8,(%rdi)
23198 6: movnti %r9,1*8(%rdi)
23199 -7: movnti %r10,2*8(%rdi)
23200 +7: movnti %rax,2*8(%rdi)
23201 8: movnti %r11,3*8(%rdi)
23202 9: movq 4*8(%rsi),%r8
23203 10: movq 5*8(%rsi),%r9
23204 -11: movq 6*8(%rsi),%r10
23205 +11: movq 6*8(%rsi),%rax
23206 12: movq 7*8(%rsi),%r11
23207 13: movnti %r8,4*8(%rdi)
23208 14: movnti %r9,5*8(%rdi)
23209 -15: movnti %r10,6*8(%rdi)
23210 +15: movnti %rax,6*8(%rdi)
23211 16: movnti %r11,7*8(%rdi)
23212 leaq 64(%rsi),%rsi
23213 leaq 64(%rdi),%rdi
23214 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23215 23: xorl %eax,%eax
23216 ASM_CLAC
23217 sfence
23218 + pax_force_retaddr
23219 ret
23220
23221 .section .fixup,"ax"
23222 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23223 index 2419d5f..953ee51 100644
23224 --- a/arch/x86/lib/csum-copy_64.S
23225 +++ b/arch/x86/lib/csum-copy_64.S
23226 @@ -9,6 +9,7 @@
23227 #include <asm/dwarf2.h>
23228 #include <asm/errno.h>
23229 #include <asm/asm.h>
23230 +#include <asm/alternative-asm.h>
23231
23232 /*
23233 * Checksum copy with exception handling.
23234 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23235 CFI_RESTORE rbp
23236 addq $7*8, %rsp
23237 CFI_ADJUST_CFA_OFFSET -7*8
23238 + pax_force_retaddr 0, 1
23239 ret
23240 CFI_RESTORE_STATE
23241
23242 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23243 index 25b7ae8..169fafc 100644
23244 --- a/arch/x86/lib/csum-wrappers_64.c
23245 +++ b/arch/x86/lib/csum-wrappers_64.c
23246 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23247 len -= 2;
23248 }
23249 }
23250 - isum = csum_partial_copy_generic((__force const void *)src,
23251 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23252 dst, len, isum, errp, NULL);
23253 if (unlikely(*errp))
23254 goto out_err;
23255 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23256 }
23257
23258 *errp = 0;
23259 - return csum_partial_copy_generic(src, (void __force *)dst,
23260 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23261 len, isum, NULL, errp);
23262 }
23263 EXPORT_SYMBOL(csum_partial_copy_to_user);
23264 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23265 index 156b9c8..b144132 100644
23266 --- a/arch/x86/lib/getuser.S
23267 +++ b/arch/x86/lib/getuser.S
23268 @@ -34,17 +34,40 @@
23269 #include <asm/thread_info.h>
23270 #include <asm/asm.h>
23271 #include <asm/smap.h>
23272 +#include <asm/segment.h>
23273 +#include <asm/pgtable.h>
23274 +#include <asm/alternative-asm.h>
23275 +
23276 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23277 +#define __copyuser_seg gs;
23278 +#else
23279 +#define __copyuser_seg
23280 +#endif
23281
23282 .text
23283 ENTRY(__get_user_1)
23284 CFI_STARTPROC
23285 +
23286 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23287 GET_THREAD_INFO(%_ASM_DX)
23288 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23289 jae bad_get_user
23290 ASM_STAC
23291 -1: movzb (%_ASM_AX),%edx
23292 +
23293 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23294 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23295 + cmp %_ASM_DX,%_ASM_AX
23296 + jae 1234f
23297 + add %_ASM_DX,%_ASM_AX
23298 +1234:
23299 +#endif
23300 +
23301 +#endif
23302 +
23303 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23304 xor %eax,%eax
23305 ASM_CLAC
23306 + pax_force_retaddr
23307 ret
23308 CFI_ENDPROC
23309 ENDPROC(__get_user_1)
23310 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23311 ENTRY(__get_user_2)
23312 CFI_STARTPROC
23313 add $1,%_ASM_AX
23314 +
23315 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23316 jc bad_get_user
23317 GET_THREAD_INFO(%_ASM_DX)
23318 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23319 jae bad_get_user
23320 ASM_STAC
23321 -2: movzwl -1(%_ASM_AX),%edx
23322 +
23323 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23324 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23325 + cmp %_ASM_DX,%_ASM_AX
23326 + jae 1234f
23327 + add %_ASM_DX,%_ASM_AX
23328 +1234:
23329 +#endif
23330 +
23331 +#endif
23332 +
23333 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23334 xor %eax,%eax
23335 ASM_CLAC
23336 + pax_force_retaddr
23337 ret
23338 CFI_ENDPROC
23339 ENDPROC(__get_user_2)
23340 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23341 ENTRY(__get_user_4)
23342 CFI_STARTPROC
23343 add $3,%_ASM_AX
23344 +
23345 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23346 jc bad_get_user
23347 GET_THREAD_INFO(%_ASM_DX)
23348 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23349 jae bad_get_user
23350 ASM_STAC
23351 -3: mov -3(%_ASM_AX),%edx
23352 +
23353 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23354 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23355 + cmp %_ASM_DX,%_ASM_AX
23356 + jae 1234f
23357 + add %_ASM_DX,%_ASM_AX
23358 +1234:
23359 +#endif
23360 +
23361 +#endif
23362 +
23363 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23364 xor %eax,%eax
23365 ASM_CLAC
23366 + pax_force_retaddr
23367 ret
23368 CFI_ENDPROC
23369 ENDPROC(__get_user_4)
23370 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23371 GET_THREAD_INFO(%_ASM_DX)
23372 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23373 jae bad_get_user
23374 +
23375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23376 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23377 + cmp %_ASM_DX,%_ASM_AX
23378 + jae 1234f
23379 + add %_ASM_DX,%_ASM_AX
23380 +1234:
23381 +#endif
23382 +
23383 ASM_STAC
23384 4: movq -7(%_ASM_AX),%_ASM_DX
23385 xor %eax,%eax
23386 ASM_CLAC
23387 + pax_force_retaddr
23388 ret
23389 CFI_ENDPROC
23390 ENDPROC(__get_user_8)
23391 @@ -101,6 +162,7 @@ bad_get_user:
23392 xor %edx,%edx
23393 mov $(-EFAULT),%_ASM_AX
23394 ASM_CLAC
23395 + pax_force_retaddr
23396 ret
23397 CFI_ENDPROC
23398 END(bad_get_user)
23399 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23400 index 54fcffe..7be149e 100644
23401 --- a/arch/x86/lib/insn.c
23402 +++ b/arch/x86/lib/insn.c
23403 @@ -20,8 +20,10 @@
23404
23405 #ifdef __KERNEL__
23406 #include <linux/string.h>
23407 +#include <asm/pgtable_types.h>
23408 #else
23409 #include <string.h>
23410 +#define ktla_ktva(addr) addr
23411 #endif
23412 #include <asm/inat.h>
23413 #include <asm/insn.h>
23414 @@ -53,8 +55,8 @@
23415 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23416 {
23417 memset(insn, 0, sizeof(*insn));
23418 - insn->kaddr = kaddr;
23419 - insn->next_byte = kaddr;
23420 + insn->kaddr = ktla_ktva(kaddr);
23421 + insn->next_byte = ktla_ktva(kaddr);
23422 insn->x86_64 = x86_64 ? 1 : 0;
23423 insn->opnd_bytes = 4;
23424 if (x86_64)
23425 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23426 index 05a95e7..326f2fa 100644
23427 --- a/arch/x86/lib/iomap_copy_64.S
23428 +++ b/arch/x86/lib/iomap_copy_64.S
23429 @@ -17,6 +17,7 @@
23430
23431 #include <linux/linkage.h>
23432 #include <asm/dwarf2.h>
23433 +#include <asm/alternative-asm.h>
23434
23435 /*
23436 * override generic version in lib/iomap_copy.c
23437 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23438 CFI_STARTPROC
23439 movl %edx,%ecx
23440 rep movsd
23441 + pax_force_retaddr
23442 ret
23443 CFI_ENDPROC
23444 ENDPROC(__iowrite32_copy)
23445 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23446 index 1c273be..da9cc0e 100644
23447 --- a/arch/x86/lib/memcpy_64.S
23448 +++ b/arch/x86/lib/memcpy_64.S
23449 @@ -33,6 +33,7 @@
23450 rep movsq
23451 movl %edx, %ecx
23452 rep movsb
23453 + pax_force_retaddr
23454 ret
23455 .Lmemcpy_e:
23456 .previous
23457 @@ -49,6 +50,7 @@
23458 movq %rdi, %rax
23459 movq %rdx, %rcx
23460 rep movsb
23461 + pax_force_retaddr
23462 ret
23463 .Lmemcpy_e_e:
23464 .previous
23465 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23466 */
23467 movq 0*8(%rsi), %r8
23468 movq 1*8(%rsi), %r9
23469 - movq 2*8(%rsi), %r10
23470 + movq 2*8(%rsi), %rcx
23471 movq 3*8(%rsi), %r11
23472 leaq 4*8(%rsi), %rsi
23473
23474 movq %r8, 0*8(%rdi)
23475 movq %r9, 1*8(%rdi)
23476 - movq %r10, 2*8(%rdi)
23477 + movq %rcx, 2*8(%rdi)
23478 movq %r11, 3*8(%rdi)
23479 leaq 4*8(%rdi), %rdi
23480 jae .Lcopy_forward_loop
23481 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23482 subq $0x20, %rdx
23483 movq -1*8(%rsi), %r8
23484 movq -2*8(%rsi), %r9
23485 - movq -3*8(%rsi), %r10
23486 + movq -3*8(%rsi), %rcx
23487 movq -4*8(%rsi), %r11
23488 leaq -4*8(%rsi), %rsi
23489 movq %r8, -1*8(%rdi)
23490 movq %r9, -2*8(%rdi)
23491 - movq %r10, -3*8(%rdi)
23492 + movq %rcx, -3*8(%rdi)
23493 movq %r11, -4*8(%rdi)
23494 leaq -4*8(%rdi), %rdi
23495 jae .Lcopy_backward_loop
23496 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23497 */
23498 movq 0*8(%rsi), %r8
23499 movq 1*8(%rsi), %r9
23500 - movq -2*8(%rsi, %rdx), %r10
23501 + movq -2*8(%rsi, %rdx), %rcx
23502 movq -1*8(%rsi, %rdx), %r11
23503 movq %r8, 0*8(%rdi)
23504 movq %r9, 1*8(%rdi)
23505 - movq %r10, -2*8(%rdi, %rdx)
23506 + movq %rcx, -2*8(%rdi, %rdx)
23507 movq %r11, -1*8(%rdi, %rdx)
23508 + pax_force_retaddr
23509 retq
23510 .p2align 4
23511 .Lless_16bytes:
23512 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23513 movq -1*8(%rsi, %rdx), %r9
23514 movq %r8, 0*8(%rdi)
23515 movq %r9, -1*8(%rdi, %rdx)
23516 + pax_force_retaddr
23517 retq
23518 .p2align 4
23519 .Lless_8bytes:
23520 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23521 movl -4(%rsi, %rdx), %r8d
23522 movl %ecx, (%rdi)
23523 movl %r8d, -4(%rdi, %rdx)
23524 + pax_force_retaddr
23525 retq
23526 .p2align 4
23527 .Lless_3bytes:
23528 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23529 movb %cl, (%rdi)
23530
23531 .Lend:
23532 + pax_force_retaddr
23533 retq
23534 CFI_ENDPROC
23535 ENDPROC(memcpy)
23536 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23537 index ee16461..c39c199 100644
23538 --- a/arch/x86/lib/memmove_64.S
23539 +++ b/arch/x86/lib/memmove_64.S
23540 @@ -61,13 +61,13 @@ ENTRY(memmove)
23541 5:
23542 sub $0x20, %rdx
23543 movq 0*8(%rsi), %r11
23544 - movq 1*8(%rsi), %r10
23545 + movq 1*8(%rsi), %rcx
23546 movq 2*8(%rsi), %r9
23547 movq 3*8(%rsi), %r8
23548 leaq 4*8(%rsi), %rsi
23549
23550 movq %r11, 0*8(%rdi)
23551 - movq %r10, 1*8(%rdi)
23552 + movq %rcx, 1*8(%rdi)
23553 movq %r9, 2*8(%rdi)
23554 movq %r8, 3*8(%rdi)
23555 leaq 4*8(%rdi), %rdi
23556 @@ -81,10 +81,10 @@ ENTRY(memmove)
23557 4:
23558 movq %rdx, %rcx
23559 movq -8(%rsi, %rdx), %r11
23560 - lea -8(%rdi, %rdx), %r10
23561 + lea -8(%rdi, %rdx), %r9
23562 shrq $3, %rcx
23563 rep movsq
23564 - movq %r11, (%r10)
23565 + movq %r11, (%r9)
23566 jmp 13f
23567 .Lmemmove_end_forward:
23568
23569 @@ -95,14 +95,14 @@ ENTRY(memmove)
23570 7:
23571 movq %rdx, %rcx
23572 movq (%rsi), %r11
23573 - movq %rdi, %r10
23574 + movq %rdi, %r9
23575 leaq -8(%rsi, %rdx), %rsi
23576 leaq -8(%rdi, %rdx), %rdi
23577 shrq $3, %rcx
23578 std
23579 rep movsq
23580 cld
23581 - movq %r11, (%r10)
23582 + movq %r11, (%r9)
23583 jmp 13f
23584
23585 /*
23586 @@ -127,13 +127,13 @@ ENTRY(memmove)
23587 8:
23588 subq $0x20, %rdx
23589 movq -1*8(%rsi), %r11
23590 - movq -2*8(%rsi), %r10
23591 + movq -2*8(%rsi), %rcx
23592 movq -3*8(%rsi), %r9
23593 movq -4*8(%rsi), %r8
23594 leaq -4*8(%rsi), %rsi
23595
23596 movq %r11, -1*8(%rdi)
23597 - movq %r10, -2*8(%rdi)
23598 + movq %rcx, -2*8(%rdi)
23599 movq %r9, -3*8(%rdi)
23600 movq %r8, -4*8(%rdi)
23601 leaq -4*8(%rdi), %rdi
23602 @@ -151,11 +151,11 @@ ENTRY(memmove)
23603 * Move data from 16 bytes to 31 bytes.
23604 */
23605 movq 0*8(%rsi), %r11
23606 - movq 1*8(%rsi), %r10
23607 + movq 1*8(%rsi), %rcx
23608 movq -2*8(%rsi, %rdx), %r9
23609 movq -1*8(%rsi, %rdx), %r8
23610 movq %r11, 0*8(%rdi)
23611 - movq %r10, 1*8(%rdi)
23612 + movq %rcx, 1*8(%rdi)
23613 movq %r9, -2*8(%rdi, %rdx)
23614 movq %r8, -1*8(%rdi, %rdx)
23615 jmp 13f
23616 @@ -167,9 +167,9 @@ ENTRY(memmove)
23617 * Move data from 8 bytes to 15 bytes.
23618 */
23619 movq 0*8(%rsi), %r11
23620 - movq -1*8(%rsi, %rdx), %r10
23621 + movq -1*8(%rsi, %rdx), %r9
23622 movq %r11, 0*8(%rdi)
23623 - movq %r10, -1*8(%rdi, %rdx)
23624 + movq %r9, -1*8(%rdi, %rdx)
23625 jmp 13f
23626 10:
23627 cmpq $4, %rdx
23628 @@ -178,9 +178,9 @@ ENTRY(memmove)
23629 * Move data from 4 bytes to 7 bytes.
23630 */
23631 movl (%rsi), %r11d
23632 - movl -4(%rsi, %rdx), %r10d
23633 + movl -4(%rsi, %rdx), %r9d
23634 movl %r11d, (%rdi)
23635 - movl %r10d, -4(%rdi, %rdx)
23636 + movl %r9d, -4(%rdi, %rdx)
23637 jmp 13f
23638 11:
23639 cmp $2, %rdx
23640 @@ -189,9 +189,9 @@ ENTRY(memmove)
23641 * Move data from 2 bytes to 3 bytes.
23642 */
23643 movw (%rsi), %r11w
23644 - movw -2(%rsi, %rdx), %r10w
23645 + movw -2(%rsi, %rdx), %r9w
23646 movw %r11w, (%rdi)
23647 - movw %r10w, -2(%rdi, %rdx)
23648 + movw %r9w, -2(%rdi, %rdx)
23649 jmp 13f
23650 12:
23651 cmp $1, %rdx
23652 @@ -202,6 +202,7 @@ ENTRY(memmove)
23653 movb (%rsi), %r11b
23654 movb %r11b, (%rdi)
23655 13:
23656 + pax_force_retaddr
23657 retq
23658 CFI_ENDPROC
23659
23660 @@ -210,6 +211,7 @@ ENTRY(memmove)
23661 /* Forward moving data. */
23662 movq %rdx, %rcx
23663 rep movsb
23664 + pax_force_retaddr
23665 retq
23666 .Lmemmove_end_forward_efs:
23667 .previous
23668 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23669 index 2dcb380..963660a 100644
23670 --- a/arch/x86/lib/memset_64.S
23671 +++ b/arch/x86/lib/memset_64.S
23672 @@ -30,6 +30,7 @@
23673 movl %edx,%ecx
23674 rep stosb
23675 movq %r9,%rax
23676 + pax_force_retaddr
23677 ret
23678 .Lmemset_e:
23679 .previous
23680 @@ -52,6 +53,7 @@
23681 movq %rdx,%rcx
23682 rep stosb
23683 movq %r9,%rax
23684 + pax_force_retaddr
23685 ret
23686 .Lmemset_e_e:
23687 .previous
23688 @@ -59,7 +61,7 @@
23689 ENTRY(memset)
23690 ENTRY(__memset)
23691 CFI_STARTPROC
23692 - movq %rdi,%r10
23693 + movq %rdi,%r11
23694
23695 /* expand byte value */
23696 movzbl %sil,%ecx
23697 @@ -117,7 +119,8 @@ ENTRY(__memset)
23698 jnz .Lloop_1
23699
23700 .Lende:
23701 - movq %r10,%rax
23702 + movq %r11,%rax
23703 + pax_force_retaddr
23704 ret
23705
23706 CFI_RESTORE_STATE
23707 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23708 index c9f2d9b..e7fd2c0 100644
23709 --- a/arch/x86/lib/mmx_32.c
23710 +++ b/arch/x86/lib/mmx_32.c
23711 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23712 {
23713 void *p;
23714 int i;
23715 + unsigned long cr0;
23716
23717 if (unlikely(in_interrupt()))
23718 return __memcpy(to, from, len);
23719 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23720 kernel_fpu_begin();
23721
23722 __asm__ __volatile__ (
23723 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23724 - " prefetch 64(%0)\n"
23725 - " prefetch 128(%0)\n"
23726 - " prefetch 192(%0)\n"
23727 - " prefetch 256(%0)\n"
23728 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23729 + " prefetch 64(%1)\n"
23730 + " prefetch 128(%1)\n"
23731 + " prefetch 192(%1)\n"
23732 + " prefetch 256(%1)\n"
23733 "2: \n"
23734 ".section .fixup, \"ax\"\n"
23735 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23736 + "3: \n"
23737 +
23738 +#ifdef CONFIG_PAX_KERNEXEC
23739 + " movl %%cr0, %0\n"
23740 + " movl %0, %%eax\n"
23741 + " andl $0xFFFEFFFF, %%eax\n"
23742 + " movl %%eax, %%cr0\n"
23743 +#endif
23744 +
23745 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23746 +
23747 +#ifdef CONFIG_PAX_KERNEXEC
23748 + " movl %0, %%cr0\n"
23749 +#endif
23750 +
23751 " jmp 2b\n"
23752 ".previous\n"
23753 _ASM_EXTABLE(1b, 3b)
23754 - : : "r" (from));
23755 + : "=&r" (cr0) : "r" (from) : "ax");
23756
23757 for ( ; i > 5; i--) {
23758 __asm__ __volatile__ (
23759 - "1: prefetch 320(%0)\n"
23760 - "2: movq (%0), %%mm0\n"
23761 - " movq 8(%0), %%mm1\n"
23762 - " movq 16(%0), %%mm2\n"
23763 - " movq 24(%0), %%mm3\n"
23764 - " movq %%mm0, (%1)\n"
23765 - " movq %%mm1, 8(%1)\n"
23766 - " movq %%mm2, 16(%1)\n"
23767 - " movq %%mm3, 24(%1)\n"
23768 - " movq 32(%0), %%mm0\n"
23769 - " movq 40(%0), %%mm1\n"
23770 - " movq 48(%0), %%mm2\n"
23771 - " movq 56(%0), %%mm3\n"
23772 - " movq %%mm0, 32(%1)\n"
23773 - " movq %%mm1, 40(%1)\n"
23774 - " movq %%mm2, 48(%1)\n"
23775 - " movq %%mm3, 56(%1)\n"
23776 + "1: prefetch 320(%1)\n"
23777 + "2: movq (%1), %%mm0\n"
23778 + " movq 8(%1), %%mm1\n"
23779 + " movq 16(%1), %%mm2\n"
23780 + " movq 24(%1), %%mm3\n"
23781 + " movq %%mm0, (%2)\n"
23782 + " movq %%mm1, 8(%2)\n"
23783 + " movq %%mm2, 16(%2)\n"
23784 + " movq %%mm3, 24(%2)\n"
23785 + " movq 32(%1), %%mm0\n"
23786 + " movq 40(%1), %%mm1\n"
23787 + " movq 48(%1), %%mm2\n"
23788 + " movq 56(%1), %%mm3\n"
23789 + " movq %%mm0, 32(%2)\n"
23790 + " movq %%mm1, 40(%2)\n"
23791 + " movq %%mm2, 48(%2)\n"
23792 + " movq %%mm3, 56(%2)\n"
23793 ".section .fixup, \"ax\"\n"
23794 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23795 + "3:\n"
23796 +
23797 +#ifdef CONFIG_PAX_KERNEXEC
23798 + " movl %%cr0, %0\n"
23799 + " movl %0, %%eax\n"
23800 + " andl $0xFFFEFFFF, %%eax\n"
23801 + " movl %%eax, %%cr0\n"
23802 +#endif
23803 +
23804 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23805 +
23806 +#ifdef CONFIG_PAX_KERNEXEC
23807 + " movl %0, %%cr0\n"
23808 +#endif
23809 +
23810 " jmp 2b\n"
23811 ".previous\n"
23812 _ASM_EXTABLE(1b, 3b)
23813 - : : "r" (from), "r" (to) : "memory");
23814 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23815
23816 from += 64;
23817 to += 64;
23818 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23819 static void fast_copy_page(void *to, void *from)
23820 {
23821 int i;
23822 + unsigned long cr0;
23823
23824 kernel_fpu_begin();
23825
23826 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23827 * but that is for later. -AV
23828 */
23829 __asm__ __volatile__(
23830 - "1: prefetch (%0)\n"
23831 - " prefetch 64(%0)\n"
23832 - " prefetch 128(%0)\n"
23833 - " prefetch 192(%0)\n"
23834 - " prefetch 256(%0)\n"
23835 + "1: prefetch (%1)\n"
23836 + " prefetch 64(%1)\n"
23837 + " prefetch 128(%1)\n"
23838 + " prefetch 192(%1)\n"
23839 + " prefetch 256(%1)\n"
23840 "2: \n"
23841 ".section .fixup, \"ax\"\n"
23842 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23843 + "3: \n"
23844 +
23845 +#ifdef CONFIG_PAX_KERNEXEC
23846 + " movl %%cr0, %0\n"
23847 + " movl %0, %%eax\n"
23848 + " andl $0xFFFEFFFF, %%eax\n"
23849 + " movl %%eax, %%cr0\n"
23850 +#endif
23851 +
23852 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23853 +
23854 +#ifdef CONFIG_PAX_KERNEXEC
23855 + " movl %0, %%cr0\n"
23856 +#endif
23857 +
23858 " jmp 2b\n"
23859 ".previous\n"
23860 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23861 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23862
23863 for (i = 0; i < (4096-320)/64; i++) {
23864 __asm__ __volatile__ (
23865 - "1: prefetch 320(%0)\n"
23866 - "2: movq (%0), %%mm0\n"
23867 - " movntq %%mm0, (%1)\n"
23868 - " movq 8(%0), %%mm1\n"
23869 - " movntq %%mm1, 8(%1)\n"
23870 - " movq 16(%0), %%mm2\n"
23871 - " movntq %%mm2, 16(%1)\n"
23872 - " movq 24(%0), %%mm3\n"
23873 - " movntq %%mm3, 24(%1)\n"
23874 - " movq 32(%0), %%mm4\n"
23875 - " movntq %%mm4, 32(%1)\n"
23876 - " movq 40(%0), %%mm5\n"
23877 - " movntq %%mm5, 40(%1)\n"
23878 - " movq 48(%0), %%mm6\n"
23879 - " movntq %%mm6, 48(%1)\n"
23880 - " movq 56(%0), %%mm7\n"
23881 - " movntq %%mm7, 56(%1)\n"
23882 + "1: prefetch 320(%1)\n"
23883 + "2: movq (%1), %%mm0\n"
23884 + " movntq %%mm0, (%2)\n"
23885 + " movq 8(%1), %%mm1\n"
23886 + " movntq %%mm1, 8(%2)\n"
23887 + " movq 16(%1), %%mm2\n"
23888 + " movntq %%mm2, 16(%2)\n"
23889 + " movq 24(%1), %%mm3\n"
23890 + " movntq %%mm3, 24(%2)\n"
23891 + " movq 32(%1), %%mm4\n"
23892 + " movntq %%mm4, 32(%2)\n"
23893 + " movq 40(%1), %%mm5\n"
23894 + " movntq %%mm5, 40(%2)\n"
23895 + " movq 48(%1), %%mm6\n"
23896 + " movntq %%mm6, 48(%2)\n"
23897 + " movq 56(%1), %%mm7\n"
23898 + " movntq %%mm7, 56(%2)\n"
23899 ".section .fixup, \"ax\"\n"
23900 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23901 + "3:\n"
23902 +
23903 +#ifdef CONFIG_PAX_KERNEXEC
23904 + " movl %%cr0, %0\n"
23905 + " movl %0, %%eax\n"
23906 + " andl $0xFFFEFFFF, %%eax\n"
23907 + " movl %%eax, %%cr0\n"
23908 +#endif
23909 +
23910 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23911 +
23912 +#ifdef CONFIG_PAX_KERNEXEC
23913 + " movl %0, %%cr0\n"
23914 +#endif
23915 +
23916 " jmp 2b\n"
23917 ".previous\n"
23918 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23919 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23920
23921 from += 64;
23922 to += 64;
23923 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23924 static void fast_copy_page(void *to, void *from)
23925 {
23926 int i;
23927 + unsigned long cr0;
23928
23929 kernel_fpu_begin();
23930
23931 __asm__ __volatile__ (
23932 - "1: prefetch (%0)\n"
23933 - " prefetch 64(%0)\n"
23934 - " prefetch 128(%0)\n"
23935 - " prefetch 192(%0)\n"
23936 - " prefetch 256(%0)\n"
23937 + "1: prefetch (%1)\n"
23938 + " prefetch 64(%1)\n"
23939 + " prefetch 128(%1)\n"
23940 + " prefetch 192(%1)\n"
23941 + " prefetch 256(%1)\n"
23942 "2: \n"
23943 ".section .fixup, \"ax\"\n"
23944 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23945 + "3: \n"
23946 +
23947 +#ifdef CONFIG_PAX_KERNEXEC
23948 + " movl %%cr0, %0\n"
23949 + " movl %0, %%eax\n"
23950 + " andl $0xFFFEFFFF, %%eax\n"
23951 + " movl %%eax, %%cr0\n"
23952 +#endif
23953 +
23954 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23955 +
23956 +#ifdef CONFIG_PAX_KERNEXEC
23957 + " movl %0, %%cr0\n"
23958 +#endif
23959 +
23960 " jmp 2b\n"
23961 ".previous\n"
23962 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23963 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23964
23965 for (i = 0; i < 4096/64; i++) {
23966 __asm__ __volatile__ (
23967 - "1: prefetch 320(%0)\n"
23968 - "2: movq (%0), %%mm0\n"
23969 - " movq 8(%0), %%mm1\n"
23970 - " movq 16(%0), %%mm2\n"
23971 - " movq 24(%0), %%mm3\n"
23972 - " movq %%mm0, (%1)\n"
23973 - " movq %%mm1, 8(%1)\n"
23974 - " movq %%mm2, 16(%1)\n"
23975 - " movq %%mm3, 24(%1)\n"
23976 - " movq 32(%0), %%mm0\n"
23977 - " movq 40(%0), %%mm1\n"
23978 - " movq 48(%0), %%mm2\n"
23979 - " movq 56(%0), %%mm3\n"
23980 - " movq %%mm0, 32(%1)\n"
23981 - " movq %%mm1, 40(%1)\n"
23982 - " movq %%mm2, 48(%1)\n"
23983 - " movq %%mm3, 56(%1)\n"
23984 + "1: prefetch 320(%1)\n"
23985 + "2: movq (%1), %%mm0\n"
23986 + " movq 8(%1), %%mm1\n"
23987 + " movq 16(%1), %%mm2\n"
23988 + " movq 24(%1), %%mm3\n"
23989 + " movq %%mm0, (%2)\n"
23990 + " movq %%mm1, 8(%2)\n"
23991 + " movq %%mm2, 16(%2)\n"
23992 + " movq %%mm3, 24(%2)\n"
23993 + " movq 32(%1), %%mm0\n"
23994 + " movq 40(%1), %%mm1\n"
23995 + " movq 48(%1), %%mm2\n"
23996 + " movq 56(%1), %%mm3\n"
23997 + " movq %%mm0, 32(%2)\n"
23998 + " movq %%mm1, 40(%2)\n"
23999 + " movq %%mm2, 48(%2)\n"
24000 + " movq %%mm3, 56(%2)\n"
24001 ".section .fixup, \"ax\"\n"
24002 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24003 + "3:\n"
24004 +
24005 +#ifdef CONFIG_PAX_KERNEXEC
24006 + " movl %%cr0, %0\n"
24007 + " movl %0, %%eax\n"
24008 + " andl $0xFFFEFFFF, %%eax\n"
24009 + " movl %%eax, %%cr0\n"
24010 +#endif
24011 +
24012 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24013 +
24014 +#ifdef CONFIG_PAX_KERNEXEC
24015 + " movl %0, %%cr0\n"
24016 +#endif
24017 +
24018 " jmp 2b\n"
24019 ".previous\n"
24020 _ASM_EXTABLE(1b, 3b)
24021 - : : "r" (from), "r" (to) : "memory");
24022 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24023
24024 from += 64;
24025 to += 64;
24026 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24027 index f6d13ee..aca5f0b 100644
24028 --- a/arch/x86/lib/msr-reg.S
24029 +++ b/arch/x86/lib/msr-reg.S
24030 @@ -3,6 +3,7 @@
24031 #include <asm/dwarf2.h>
24032 #include <asm/asm.h>
24033 #include <asm/msr.h>
24034 +#include <asm/alternative-asm.h>
24035
24036 #ifdef CONFIG_X86_64
24037 /*
24038 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24039 CFI_STARTPROC
24040 pushq_cfi %rbx
24041 pushq_cfi %rbp
24042 - movq %rdi, %r10 /* Save pointer */
24043 + movq %rdi, %r9 /* Save pointer */
24044 xorl %r11d, %r11d /* Return value */
24045 movl (%rdi), %eax
24046 movl 4(%rdi), %ecx
24047 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24048 movl 28(%rdi), %edi
24049 CFI_REMEMBER_STATE
24050 1: \op
24051 -2: movl %eax, (%r10)
24052 +2: movl %eax, (%r9)
24053 movl %r11d, %eax /* Return value */
24054 - movl %ecx, 4(%r10)
24055 - movl %edx, 8(%r10)
24056 - movl %ebx, 12(%r10)
24057 - movl %ebp, 20(%r10)
24058 - movl %esi, 24(%r10)
24059 - movl %edi, 28(%r10)
24060 + movl %ecx, 4(%r9)
24061 + movl %edx, 8(%r9)
24062 + movl %ebx, 12(%r9)
24063 + movl %ebp, 20(%r9)
24064 + movl %esi, 24(%r9)
24065 + movl %edi, 28(%r9)
24066 popq_cfi %rbp
24067 popq_cfi %rbx
24068 + pax_force_retaddr
24069 ret
24070 3:
24071 CFI_RESTORE_STATE
24072 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24073 index fc6ba17..04471c5 100644
24074 --- a/arch/x86/lib/putuser.S
24075 +++ b/arch/x86/lib/putuser.S
24076 @@ -16,7 +16,9 @@
24077 #include <asm/errno.h>
24078 #include <asm/asm.h>
24079 #include <asm/smap.h>
24080 -
24081 +#include <asm/segment.h>
24082 +#include <asm/pgtable.h>
24083 +#include <asm/alternative-asm.h>
24084
24085 /*
24086 * __put_user_X
24087 @@ -30,57 +32,125 @@
24088 * as they get called from within inline assembly.
24089 */
24090
24091 -#define ENTER CFI_STARTPROC ; \
24092 - GET_THREAD_INFO(%_ASM_BX)
24093 -#define EXIT ASM_CLAC ; \
24094 - ret ; \
24095 +#define ENTER CFI_STARTPROC
24096 +#define EXIT ASM_CLAC ; \
24097 + pax_force_retaddr ; \
24098 + ret ; \
24099 CFI_ENDPROC
24100
24101 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24102 +#define _DEST %_ASM_CX,%_ASM_BX
24103 +#else
24104 +#define _DEST %_ASM_CX
24105 +#endif
24106 +
24107 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24108 +#define __copyuser_seg gs;
24109 +#else
24110 +#define __copyuser_seg
24111 +#endif
24112 +
24113 .text
24114 ENTRY(__put_user_1)
24115 ENTER
24116 +
24117 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24118 + GET_THREAD_INFO(%_ASM_BX)
24119 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24120 jae bad_put_user
24121 ASM_STAC
24122 -1: movb %al,(%_ASM_CX)
24123 +
24124 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24125 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24126 + cmp %_ASM_BX,%_ASM_CX
24127 + jb 1234f
24128 + xor %ebx,%ebx
24129 +1234:
24130 +#endif
24131 +
24132 +#endif
24133 +
24134 +1: __copyuser_seg movb %al,(_DEST)
24135 xor %eax,%eax
24136 EXIT
24137 ENDPROC(__put_user_1)
24138
24139 ENTRY(__put_user_2)
24140 ENTER
24141 +
24142 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24143 + GET_THREAD_INFO(%_ASM_BX)
24144 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24145 sub $1,%_ASM_BX
24146 cmp %_ASM_BX,%_ASM_CX
24147 jae bad_put_user
24148 ASM_STAC
24149 -2: movw %ax,(%_ASM_CX)
24150 +
24151 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24152 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24153 + cmp %_ASM_BX,%_ASM_CX
24154 + jb 1234f
24155 + xor %ebx,%ebx
24156 +1234:
24157 +#endif
24158 +
24159 +#endif
24160 +
24161 +2: __copyuser_seg movw %ax,(_DEST)
24162 xor %eax,%eax
24163 EXIT
24164 ENDPROC(__put_user_2)
24165
24166 ENTRY(__put_user_4)
24167 ENTER
24168 +
24169 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24170 + GET_THREAD_INFO(%_ASM_BX)
24171 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24172 sub $3,%_ASM_BX
24173 cmp %_ASM_BX,%_ASM_CX
24174 jae bad_put_user
24175 ASM_STAC
24176 -3: movl %eax,(%_ASM_CX)
24177 +
24178 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24179 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24180 + cmp %_ASM_BX,%_ASM_CX
24181 + jb 1234f
24182 + xor %ebx,%ebx
24183 +1234:
24184 +#endif
24185 +
24186 +#endif
24187 +
24188 +3: __copyuser_seg movl %eax,(_DEST)
24189 xor %eax,%eax
24190 EXIT
24191 ENDPROC(__put_user_4)
24192
24193 ENTRY(__put_user_8)
24194 ENTER
24195 +
24196 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24197 + GET_THREAD_INFO(%_ASM_BX)
24198 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24199 sub $7,%_ASM_BX
24200 cmp %_ASM_BX,%_ASM_CX
24201 jae bad_put_user
24202 ASM_STAC
24203 -4: mov %_ASM_AX,(%_ASM_CX)
24204 +
24205 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24206 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24207 + cmp %_ASM_BX,%_ASM_CX
24208 + jb 1234f
24209 + xor %ebx,%ebx
24210 +1234:
24211 +#endif
24212 +
24213 +#endif
24214 +
24215 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
24216 #ifdef CONFIG_X86_32
24217 -5: movl %edx,4(%_ASM_CX)
24218 +5: __copyuser_seg movl %edx,4(_DEST)
24219 #endif
24220 xor %eax,%eax
24221 EXIT
24222 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24223 index 1cad221..de671ee 100644
24224 --- a/arch/x86/lib/rwlock.S
24225 +++ b/arch/x86/lib/rwlock.S
24226 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24227 FRAME
24228 0: LOCK_PREFIX
24229 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24230 +
24231 +#ifdef CONFIG_PAX_REFCOUNT
24232 + jno 1234f
24233 + LOCK_PREFIX
24234 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24235 + int $4
24236 +1234:
24237 + _ASM_EXTABLE(1234b, 1234b)
24238 +#endif
24239 +
24240 1: rep; nop
24241 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24242 jne 1b
24243 LOCK_PREFIX
24244 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24245 +
24246 +#ifdef CONFIG_PAX_REFCOUNT
24247 + jno 1234f
24248 + LOCK_PREFIX
24249 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24250 + int $4
24251 +1234:
24252 + _ASM_EXTABLE(1234b, 1234b)
24253 +#endif
24254 +
24255 jnz 0b
24256 ENDFRAME
24257 + pax_force_retaddr
24258 ret
24259 CFI_ENDPROC
24260 END(__write_lock_failed)
24261 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24262 FRAME
24263 0: LOCK_PREFIX
24264 READ_LOCK_SIZE(inc) (%__lock_ptr)
24265 +
24266 +#ifdef CONFIG_PAX_REFCOUNT
24267 + jno 1234f
24268 + LOCK_PREFIX
24269 + READ_LOCK_SIZE(dec) (%__lock_ptr)
24270 + int $4
24271 +1234:
24272 + _ASM_EXTABLE(1234b, 1234b)
24273 +#endif
24274 +
24275 1: rep; nop
24276 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24277 js 1b
24278 LOCK_PREFIX
24279 READ_LOCK_SIZE(dec) (%__lock_ptr)
24280 +
24281 +#ifdef CONFIG_PAX_REFCOUNT
24282 + jno 1234f
24283 + LOCK_PREFIX
24284 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24285 + int $4
24286 +1234:
24287 + _ASM_EXTABLE(1234b, 1234b)
24288 +#endif
24289 +
24290 js 0b
24291 ENDFRAME
24292 + pax_force_retaddr
24293 ret
24294 CFI_ENDPROC
24295 END(__read_lock_failed)
24296 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24297 index 5dff5f0..cadebf4 100644
24298 --- a/arch/x86/lib/rwsem.S
24299 +++ b/arch/x86/lib/rwsem.S
24300 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24301 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24302 CFI_RESTORE __ASM_REG(dx)
24303 restore_common_regs
24304 + pax_force_retaddr
24305 ret
24306 CFI_ENDPROC
24307 ENDPROC(call_rwsem_down_read_failed)
24308 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24309 movq %rax,%rdi
24310 call rwsem_down_write_failed
24311 restore_common_regs
24312 + pax_force_retaddr
24313 ret
24314 CFI_ENDPROC
24315 ENDPROC(call_rwsem_down_write_failed)
24316 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24317 movq %rax,%rdi
24318 call rwsem_wake
24319 restore_common_regs
24320 -1: ret
24321 +1: pax_force_retaddr
24322 + ret
24323 CFI_ENDPROC
24324 ENDPROC(call_rwsem_wake)
24325
24326 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24327 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24328 CFI_RESTORE __ASM_REG(dx)
24329 restore_common_regs
24330 + pax_force_retaddr
24331 ret
24332 CFI_ENDPROC
24333 ENDPROC(call_rwsem_downgrade_wake)
24334 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24335 index a63efd6..ccecad8 100644
24336 --- a/arch/x86/lib/thunk_64.S
24337 +++ b/arch/x86/lib/thunk_64.S
24338 @@ -8,6 +8,7 @@
24339 #include <linux/linkage.h>
24340 #include <asm/dwarf2.h>
24341 #include <asm/calling.h>
24342 +#include <asm/alternative-asm.h>
24343
24344 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24345 .macro THUNK name, func, put_ret_addr_in_rdi=0
24346 @@ -41,5 +42,6 @@
24347 SAVE_ARGS
24348 restore:
24349 RESTORE_ARGS
24350 + pax_force_retaddr
24351 ret
24352 CFI_ENDPROC
24353 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24354 index 98f6d6b6..d27f045 100644
24355 --- a/arch/x86/lib/usercopy_32.c
24356 +++ b/arch/x86/lib/usercopy_32.c
24357 @@ -42,11 +42,13 @@ do { \
24358 int __d0; \
24359 might_fault(); \
24360 __asm__ __volatile__( \
24361 + __COPYUSER_SET_ES \
24362 ASM_STAC "\n" \
24363 "0: rep; stosl\n" \
24364 " movl %2,%0\n" \
24365 "1: rep; stosb\n" \
24366 "2: " ASM_CLAC "\n" \
24367 + __COPYUSER_RESTORE_ES \
24368 ".section .fixup,\"ax\"\n" \
24369 "3: lea 0(%2,%0,4),%0\n" \
24370 " jmp 2b\n" \
24371 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24372
24373 #ifdef CONFIG_X86_INTEL_USERCOPY
24374 static unsigned long
24375 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24376 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24377 {
24378 int d0, d1;
24379 __asm__ __volatile__(
24380 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24381 " .align 2,0x90\n"
24382 "3: movl 0(%4), %%eax\n"
24383 "4: movl 4(%4), %%edx\n"
24384 - "5: movl %%eax, 0(%3)\n"
24385 - "6: movl %%edx, 4(%3)\n"
24386 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24387 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24388 "7: movl 8(%4), %%eax\n"
24389 "8: movl 12(%4),%%edx\n"
24390 - "9: movl %%eax, 8(%3)\n"
24391 - "10: movl %%edx, 12(%3)\n"
24392 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24393 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24394 "11: movl 16(%4), %%eax\n"
24395 "12: movl 20(%4), %%edx\n"
24396 - "13: movl %%eax, 16(%3)\n"
24397 - "14: movl %%edx, 20(%3)\n"
24398 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24399 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24400 "15: movl 24(%4), %%eax\n"
24401 "16: movl 28(%4), %%edx\n"
24402 - "17: movl %%eax, 24(%3)\n"
24403 - "18: movl %%edx, 28(%3)\n"
24404 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24405 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24406 "19: movl 32(%4), %%eax\n"
24407 "20: movl 36(%4), %%edx\n"
24408 - "21: movl %%eax, 32(%3)\n"
24409 - "22: movl %%edx, 36(%3)\n"
24410 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24411 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24412 "23: movl 40(%4), %%eax\n"
24413 "24: movl 44(%4), %%edx\n"
24414 - "25: movl %%eax, 40(%3)\n"
24415 - "26: movl %%edx, 44(%3)\n"
24416 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24417 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24418 "27: movl 48(%4), %%eax\n"
24419 "28: movl 52(%4), %%edx\n"
24420 - "29: movl %%eax, 48(%3)\n"
24421 - "30: movl %%edx, 52(%3)\n"
24422 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24423 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24424 "31: movl 56(%4), %%eax\n"
24425 "32: movl 60(%4), %%edx\n"
24426 - "33: movl %%eax, 56(%3)\n"
24427 - "34: movl %%edx, 60(%3)\n"
24428 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24429 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24430 " addl $-64, %0\n"
24431 " addl $64, %4\n"
24432 " addl $64, %3\n"
24433 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24434 " shrl $2, %0\n"
24435 " andl $3, %%eax\n"
24436 " cld\n"
24437 + __COPYUSER_SET_ES
24438 "99: rep; movsl\n"
24439 "36: movl %%eax, %0\n"
24440 "37: rep; movsb\n"
24441 "100:\n"
24442 + __COPYUSER_RESTORE_ES
24443 ".section .fixup,\"ax\"\n"
24444 "101: lea 0(%%eax,%0,4),%0\n"
24445 " jmp 100b\n"
24446 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24447 }
24448
24449 static unsigned long
24450 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24451 +{
24452 + int d0, d1;
24453 + __asm__ __volatile__(
24454 + " .align 2,0x90\n"
24455 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24456 + " cmpl $67, %0\n"
24457 + " jbe 3f\n"
24458 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24459 + " .align 2,0x90\n"
24460 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24461 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24462 + "5: movl %%eax, 0(%3)\n"
24463 + "6: movl %%edx, 4(%3)\n"
24464 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24465 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24466 + "9: movl %%eax, 8(%3)\n"
24467 + "10: movl %%edx, 12(%3)\n"
24468 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24469 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24470 + "13: movl %%eax, 16(%3)\n"
24471 + "14: movl %%edx, 20(%3)\n"
24472 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24473 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24474 + "17: movl %%eax, 24(%3)\n"
24475 + "18: movl %%edx, 28(%3)\n"
24476 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24477 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24478 + "21: movl %%eax, 32(%3)\n"
24479 + "22: movl %%edx, 36(%3)\n"
24480 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24481 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24482 + "25: movl %%eax, 40(%3)\n"
24483 + "26: movl %%edx, 44(%3)\n"
24484 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24485 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24486 + "29: movl %%eax, 48(%3)\n"
24487 + "30: movl %%edx, 52(%3)\n"
24488 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24489 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24490 + "33: movl %%eax, 56(%3)\n"
24491 + "34: movl %%edx, 60(%3)\n"
24492 + " addl $-64, %0\n"
24493 + " addl $64, %4\n"
24494 + " addl $64, %3\n"
24495 + " cmpl $63, %0\n"
24496 + " ja 1b\n"
24497 + "35: movl %0, %%eax\n"
24498 + " shrl $2, %0\n"
24499 + " andl $3, %%eax\n"
24500 + " cld\n"
24501 + "99: rep; "__copyuser_seg" movsl\n"
24502 + "36: movl %%eax, %0\n"
24503 + "37: rep; "__copyuser_seg" movsb\n"
24504 + "100:\n"
24505 + ".section .fixup,\"ax\"\n"
24506 + "101: lea 0(%%eax,%0,4),%0\n"
24507 + " jmp 100b\n"
24508 + ".previous\n"
24509 + _ASM_EXTABLE(1b,100b)
24510 + _ASM_EXTABLE(2b,100b)
24511 + _ASM_EXTABLE(3b,100b)
24512 + _ASM_EXTABLE(4b,100b)
24513 + _ASM_EXTABLE(5b,100b)
24514 + _ASM_EXTABLE(6b,100b)
24515 + _ASM_EXTABLE(7b,100b)
24516 + _ASM_EXTABLE(8b,100b)
24517 + _ASM_EXTABLE(9b,100b)
24518 + _ASM_EXTABLE(10b,100b)
24519 + _ASM_EXTABLE(11b,100b)
24520 + _ASM_EXTABLE(12b,100b)
24521 + _ASM_EXTABLE(13b,100b)
24522 + _ASM_EXTABLE(14b,100b)
24523 + _ASM_EXTABLE(15b,100b)
24524 + _ASM_EXTABLE(16b,100b)
24525 + _ASM_EXTABLE(17b,100b)
24526 + _ASM_EXTABLE(18b,100b)
24527 + _ASM_EXTABLE(19b,100b)
24528 + _ASM_EXTABLE(20b,100b)
24529 + _ASM_EXTABLE(21b,100b)
24530 + _ASM_EXTABLE(22b,100b)
24531 + _ASM_EXTABLE(23b,100b)
24532 + _ASM_EXTABLE(24b,100b)
24533 + _ASM_EXTABLE(25b,100b)
24534 + _ASM_EXTABLE(26b,100b)
24535 + _ASM_EXTABLE(27b,100b)
24536 + _ASM_EXTABLE(28b,100b)
24537 + _ASM_EXTABLE(29b,100b)
24538 + _ASM_EXTABLE(30b,100b)
24539 + _ASM_EXTABLE(31b,100b)
24540 + _ASM_EXTABLE(32b,100b)
24541 + _ASM_EXTABLE(33b,100b)
24542 + _ASM_EXTABLE(34b,100b)
24543 + _ASM_EXTABLE(35b,100b)
24544 + _ASM_EXTABLE(36b,100b)
24545 + _ASM_EXTABLE(37b,100b)
24546 + _ASM_EXTABLE(99b,101b)
24547 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24548 + : "1"(to), "2"(from), "0"(size)
24549 + : "eax", "edx", "memory");
24550 + return size;
24551 +}
24552 +
24553 +static unsigned long __size_overflow(3)
24554 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24555 {
24556 int d0, d1;
24557 __asm__ __volatile__(
24558 " .align 2,0x90\n"
24559 - "0: movl 32(%4), %%eax\n"
24560 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24561 " cmpl $67, %0\n"
24562 " jbe 2f\n"
24563 - "1: movl 64(%4), %%eax\n"
24564 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24565 " .align 2,0x90\n"
24566 - "2: movl 0(%4), %%eax\n"
24567 - "21: movl 4(%4), %%edx\n"
24568 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24569 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24570 " movl %%eax, 0(%3)\n"
24571 " movl %%edx, 4(%3)\n"
24572 - "3: movl 8(%4), %%eax\n"
24573 - "31: movl 12(%4),%%edx\n"
24574 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24575 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24576 " movl %%eax, 8(%3)\n"
24577 " movl %%edx, 12(%3)\n"
24578 - "4: movl 16(%4), %%eax\n"
24579 - "41: movl 20(%4), %%edx\n"
24580 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24581 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24582 " movl %%eax, 16(%3)\n"
24583 " movl %%edx, 20(%3)\n"
24584 - "10: movl 24(%4), %%eax\n"
24585 - "51: movl 28(%4), %%edx\n"
24586 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24587 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24588 " movl %%eax, 24(%3)\n"
24589 " movl %%edx, 28(%3)\n"
24590 - "11: movl 32(%4), %%eax\n"
24591 - "61: movl 36(%4), %%edx\n"
24592 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24593 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24594 " movl %%eax, 32(%3)\n"
24595 " movl %%edx, 36(%3)\n"
24596 - "12: movl 40(%4), %%eax\n"
24597 - "71: movl 44(%4), %%edx\n"
24598 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24599 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24600 " movl %%eax, 40(%3)\n"
24601 " movl %%edx, 44(%3)\n"
24602 - "13: movl 48(%4), %%eax\n"
24603 - "81: movl 52(%4), %%edx\n"
24604 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24605 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24606 " movl %%eax, 48(%3)\n"
24607 " movl %%edx, 52(%3)\n"
24608 - "14: movl 56(%4), %%eax\n"
24609 - "91: movl 60(%4), %%edx\n"
24610 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24611 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24612 " movl %%eax, 56(%3)\n"
24613 " movl %%edx, 60(%3)\n"
24614 " addl $-64, %0\n"
24615 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24616 " shrl $2, %0\n"
24617 " andl $3, %%eax\n"
24618 " cld\n"
24619 - "6: rep; movsl\n"
24620 + "6: rep; "__copyuser_seg" movsl\n"
24621 " movl %%eax,%0\n"
24622 - "7: rep; movsb\n"
24623 + "7: rep; "__copyuser_seg" movsb\n"
24624 "8:\n"
24625 ".section .fixup,\"ax\"\n"
24626 "9: lea 0(%%eax,%0,4),%0\n"
24627 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24628 * hyoshiok@miraclelinux.com
24629 */
24630
24631 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24632 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24633 const void __user *from, unsigned long size)
24634 {
24635 int d0, d1;
24636
24637 __asm__ __volatile__(
24638 " .align 2,0x90\n"
24639 - "0: movl 32(%4), %%eax\n"
24640 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24641 " cmpl $67, %0\n"
24642 " jbe 2f\n"
24643 - "1: movl 64(%4), %%eax\n"
24644 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24645 " .align 2,0x90\n"
24646 - "2: movl 0(%4), %%eax\n"
24647 - "21: movl 4(%4), %%edx\n"
24648 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24649 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24650 " movnti %%eax, 0(%3)\n"
24651 " movnti %%edx, 4(%3)\n"
24652 - "3: movl 8(%4), %%eax\n"
24653 - "31: movl 12(%4),%%edx\n"
24654 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24655 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24656 " movnti %%eax, 8(%3)\n"
24657 " movnti %%edx, 12(%3)\n"
24658 - "4: movl 16(%4), %%eax\n"
24659 - "41: movl 20(%4), %%edx\n"
24660 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24661 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24662 " movnti %%eax, 16(%3)\n"
24663 " movnti %%edx, 20(%3)\n"
24664 - "10: movl 24(%4), %%eax\n"
24665 - "51: movl 28(%4), %%edx\n"
24666 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24667 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24668 " movnti %%eax, 24(%3)\n"
24669 " movnti %%edx, 28(%3)\n"
24670 - "11: movl 32(%4), %%eax\n"
24671 - "61: movl 36(%4), %%edx\n"
24672 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24673 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24674 " movnti %%eax, 32(%3)\n"
24675 " movnti %%edx, 36(%3)\n"
24676 - "12: movl 40(%4), %%eax\n"
24677 - "71: movl 44(%4), %%edx\n"
24678 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24679 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24680 " movnti %%eax, 40(%3)\n"
24681 " movnti %%edx, 44(%3)\n"
24682 - "13: movl 48(%4), %%eax\n"
24683 - "81: movl 52(%4), %%edx\n"
24684 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24685 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24686 " movnti %%eax, 48(%3)\n"
24687 " movnti %%edx, 52(%3)\n"
24688 - "14: movl 56(%4), %%eax\n"
24689 - "91: movl 60(%4), %%edx\n"
24690 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24691 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24692 " movnti %%eax, 56(%3)\n"
24693 " movnti %%edx, 60(%3)\n"
24694 " addl $-64, %0\n"
24695 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24696 " shrl $2, %0\n"
24697 " andl $3, %%eax\n"
24698 " cld\n"
24699 - "6: rep; movsl\n"
24700 + "6: rep; "__copyuser_seg" movsl\n"
24701 " movl %%eax,%0\n"
24702 - "7: rep; movsb\n"
24703 + "7: rep; "__copyuser_seg" movsb\n"
24704 "8:\n"
24705 ".section .fixup,\"ax\"\n"
24706 "9: lea 0(%%eax,%0,4),%0\n"
24707 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24708 return size;
24709 }
24710
24711 -static unsigned long __copy_user_intel_nocache(void *to,
24712 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24713 const void __user *from, unsigned long size)
24714 {
24715 int d0, d1;
24716
24717 __asm__ __volatile__(
24718 " .align 2,0x90\n"
24719 - "0: movl 32(%4), %%eax\n"
24720 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24721 " cmpl $67, %0\n"
24722 " jbe 2f\n"
24723 - "1: movl 64(%4), %%eax\n"
24724 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24725 " .align 2,0x90\n"
24726 - "2: movl 0(%4), %%eax\n"
24727 - "21: movl 4(%4), %%edx\n"
24728 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24729 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24730 " movnti %%eax, 0(%3)\n"
24731 " movnti %%edx, 4(%3)\n"
24732 - "3: movl 8(%4), %%eax\n"
24733 - "31: movl 12(%4),%%edx\n"
24734 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24735 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24736 " movnti %%eax, 8(%3)\n"
24737 " movnti %%edx, 12(%3)\n"
24738 - "4: movl 16(%4), %%eax\n"
24739 - "41: movl 20(%4), %%edx\n"
24740 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24741 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24742 " movnti %%eax, 16(%3)\n"
24743 " movnti %%edx, 20(%3)\n"
24744 - "10: movl 24(%4), %%eax\n"
24745 - "51: movl 28(%4), %%edx\n"
24746 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24747 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24748 " movnti %%eax, 24(%3)\n"
24749 " movnti %%edx, 28(%3)\n"
24750 - "11: movl 32(%4), %%eax\n"
24751 - "61: movl 36(%4), %%edx\n"
24752 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24753 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24754 " movnti %%eax, 32(%3)\n"
24755 " movnti %%edx, 36(%3)\n"
24756 - "12: movl 40(%4), %%eax\n"
24757 - "71: movl 44(%4), %%edx\n"
24758 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24759 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24760 " movnti %%eax, 40(%3)\n"
24761 " movnti %%edx, 44(%3)\n"
24762 - "13: movl 48(%4), %%eax\n"
24763 - "81: movl 52(%4), %%edx\n"
24764 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24765 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24766 " movnti %%eax, 48(%3)\n"
24767 " movnti %%edx, 52(%3)\n"
24768 - "14: movl 56(%4), %%eax\n"
24769 - "91: movl 60(%4), %%edx\n"
24770 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24771 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24772 " movnti %%eax, 56(%3)\n"
24773 " movnti %%edx, 60(%3)\n"
24774 " addl $-64, %0\n"
24775 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24776 " shrl $2, %0\n"
24777 " andl $3, %%eax\n"
24778 " cld\n"
24779 - "6: rep; movsl\n"
24780 + "6: rep; "__copyuser_seg" movsl\n"
24781 " movl %%eax,%0\n"
24782 - "7: rep; movsb\n"
24783 + "7: rep; "__copyuser_seg" movsb\n"
24784 "8:\n"
24785 ".section .fixup,\"ax\"\n"
24786 "9: lea 0(%%eax,%0,4),%0\n"
24787 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24788 */
24789 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24790 unsigned long size);
24791 -unsigned long __copy_user_intel(void __user *to, const void *from,
24792 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24793 + unsigned long size);
24794 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24795 unsigned long size);
24796 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24797 const void __user *from, unsigned long size);
24798 #endif /* CONFIG_X86_INTEL_USERCOPY */
24799
24800 /* Generic arbitrary sized copy. */
24801 -#define __copy_user(to, from, size) \
24802 +#define __copy_user(to, from, size, prefix, set, restore) \
24803 do { \
24804 int __d0, __d1, __d2; \
24805 __asm__ __volatile__( \
24806 + set \
24807 " cmp $7,%0\n" \
24808 " jbe 1f\n" \
24809 " movl %1,%0\n" \
24810 " negl %0\n" \
24811 " andl $7,%0\n" \
24812 " subl %0,%3\n" \
24813 - "4: rep; movsb\n" \
24814 + "4: rep; "prefix"movsb\n" \
24815 " movl %3,%0\n" \
24816 " shrl $2,%0\n" \
24817 " andl $3,%3\n" \
24818 " .align 2,0x90\n" \
24819 - "0: rep; movsl\n" \
24820 + "0: rep; "prefix"movsl\n" \
24821 " movl %3,%0\n" \
24822 - "1: rep; movsb\n" \
24823 + "1: rep; "prefix"movsb\n" \
24824 "2:\n" \
24825 + restore \
24826 ".section .fixup,\"ax\"\n" \
24827 "5: addl %3,%0\n" \
24828 " jmp 2b\n" \
24829 @@ -538,14 +650,14 @@ do { \
24830 " negl %0\n" \
24831 " andl $7,%0\n" \
24832 " subl %0,%3\n" \
24833 - "4: rep; movsb\n" \
24834 + "4: rep; "__copyuser_seg"movsb\n" \
24835 " movl %3,%0\n" \
24836 " shrl $2,%0\n" \
24837 " andl $3,%3\n" \
24838 " .align 2,0x90\n" \
24839 - "0: rep; movsl\n" \
24840 + "0: rep; "__copyuser_seg"movsl\n" \
24841 " movl %3,%0\n" \
24842 - "1: rep; movsb\n" \
24843 + "1: rep; "__copyuser_seg"movsb\n" \
24844 "2:\n" \
24845 ".section .fixup,\"ax\"\n" \
24846 "5: addl %3,%0\n" \
24847 @@ -629,9 +741,9 @@ survive:
24848 #endif
24849 stac();
24850 if (movsl_is_ok(to, from, n))
24851 - __copy_user(to, from, n);
24852 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24853 else
24854 - n = __copy_user_intel(to, from, n);
24855 + n = __generic_copy_to_user_intel(to, from, n);
24856 clac();
24857 return n;
24858 }
24859 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24860 {
24861 stac();
24862 if (movsl_is_ok(to, from, n))
24863 - __copy_user(to, from, n);
24864 + __copy_user(to, from, n, __copyuser_seg, "", "");
24865 else
24866 - n = __copy_user_intel((void __user *)to,
24867 - (const void *)from, n);
24868 + n = __generic_copy_from_user_intel(to, from, n);
24869 clac();
24870 return n;
24871 }
24872 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24873 if (n > 64 && cpu_has_xmm2)
24874 n = __copy_user_intel_nocache(to, from, n);
24875 else
24876 - __copy_user(to, from, n);
24877 + __copy_user(to, from, n, __copyuser_seg, "", "");
24878 #else
24879 - __copy_user(to, from, n);
24880 + __copy_user(to, from, n, __copyuser_seg, "", "");
24881 #endif
24882 clac();
24883 return n;
24884 }
24885 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24886
24887 -/**
24888 - * copy_to_user: - Copy a block of data into user space.
24889 - * @to: Destination address, in user space.
24890 - * @from: Source address, in kernel space.
24891 - * @n: Number of bytes to copy.
24892 - *
24893 - * Context: User context only. This function may sleep.
24894 - *
24895 - * Copy data from kernel space to user space.
24896 - *
24897 - * Returns number of bytes that could not be copied.
24898 - * On success, this will be zero.
24899 - */
24900 -unsigned long
24901 -copy_to_user(void __user *to, const void *from, unsigned long n)
24902 -{
24903 - if (access_ok(VERIFY_WRITE, to, n))
24904 - n = __copy_to_user(to, from, n);
24905 - return n;
24906 -}
24907 -EXPORT_SYMBOL(copy_to_user);
24908 -
24909 -/**
24910 - * copy_from_user: - Copy a block of data from user space.
24911 - * @to: Destination address, in kernel space.
24912 - * @from: Source address, in user space.
24913 - * @n: Number of bytes to copy.
24914 - *
24915 - * Context: User context only. This function may sleep.
24916 - *
24917 - * Copy data from user space to kernel space.
24918 - *
24919 - * Returns number of bytes that could not be copied.
24920 - * On success, this will be zero.
24921 - *
24922 - * If some data could not be copied, this function will pad the copied
24923 - * data to the requested size using zero bytes.
24924 - */
24925 -unsigned long
24926 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24927 -{
24928 - if (access_ok(VERIFY_READ, from, n))
24929 - n = __copy_from_user(to, from, n);
24930 - else
24931 - memset(to, 0, n);
24932 - return n;
24933 -}
24934 -EXPORT_SYMBOL(_copy_from_user);
24935 -
24936 void copy_from_user_overflow(void)
24937 {
24938 WARN(1, "Buffer overflow detected!\n");
24939 }
24940 EXPORT_SYMBOL(copy_from_user_overflow);
24941 +
24942 +void copy_to_user_overflow(void)
24943 +{
24944 + WARN(1, "Buffer overflow detected!\n");
24945 +}
24946 +EXPORT_SYMBOL(copy_to_user_overflow);
24947 +
24948 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24949 +void __set_fs(mm_segment_t x)
24950 +{
24951 + switch (x.seg) {
24952 + case 0:
24953 + loadsegment(gs, 0);
24954 + break;
24955 + case TASK_SIZE_MAX:
24956 + loadsegment(gs, __USER_DS);
24957 + break;
24958 + case -1UL:
24959 + loadsegment(gs, __KERNEL_DS);
24960 + break;
24961 + default:
24962 + BUG();
24963 + }
24964 + return;
24965 +}
24966 +EXPORT_SYMBOL(__set_fs);
24967 +
24968 +void set_fs(mm_segment_t x)
24969 +{
24970 + current_thread_info()->addr_limit = x;
24971 + __set_fs(x);
24972 +}
24973 +EXPORT_SYMBOL(set_fs);
24974 +#endif
24975 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
24976 index 05928aa..b33dea1 100644
24977 --- a/arch/x86/lib/usercopy_64.c
24978 +++ b/arch/x86/lib/usercopy_64.c
24979 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
24980 _ASM_EXTABLE(0b,3b)
24981 _ASM_EXTABLE(1b,2b)
24982 : [size8] "=&c"(size), [dst] "=&D" (__d0)
24983 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
24984 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
24985 [zero] "r" (0UL), [eight] "r" (8UL));
24986 clac();
24987 return size;
24988 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
24989 }
24990 EXPORT_SYMBOL(clear_user);
24991
24992 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
24993 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
24994 {
24995 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24996 - return copy_user_generic((__force void *)to, (__force void *)from, len);
24997 - }
24998 - return len;
24999 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25000 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25001 + return len;
25002 }
25003 EXPORT_SYMBOL(copy_in_user);
25004
25005 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25006 * it is not necessary to optimize tail handling.
25007 */
25008 unsigned long
25009 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25010 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25011 {
25012 char c;
25013 unsigned zero_len;
25014 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25015 clac();
25016 return len;
25017 }
25018 +
25019 +void copy_from_user_overflow(void)
25020 +{
25021 + WARN(1, "Buffer overflow detected!\n");
25022 +}
25023 +EXPORT_SYMBOL(copy_from_user_overflow);
25024 +
25025 +void copy_to_user_overflow(void)
25026 +{
25027 + WARN(1, "Buffer overflow detected!\n");
25028 +}
25029 +EXPORT_SYMBOL(copy_to_user_overflow);
25030 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25031 index 903ec1e..c4166b2 100644
25032 --- a/arch/x86/mm/extable.c
25033 +++ b/arch/x86/mm/extable.c
25034 @@ -6,12 +6,24 @@
25035 static inline unsigned long
25036 ex_insn_addr(const struct exception_table_entry *x)
25037 {
25038 - return (unsigned long)&x->insn + x->insn;
25039 + unsigned long reloc = 0;
25040 +
25041 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25042 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25043 +#endif
25044 +
25045 + return (unsigned long)&x->insn + x->insn + reloc;
25046 }
25047 static inline unsigned long
25048 ex_fixup_addr(const struct exception_table_entry *x)
25049 {
25050 - return (unsigned long)&x->fixup + x->fixup;
25051 + unsigned long reloc = 0;
25052 +
25053 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25054 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25055 +#endif
25056 +
25057 + return (unsigned long)&x->fixup + x->fixup + reloc;
25058 }
25059
25060 int fixup_exception(struct pt_regs *regs)
25061 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25062 unsigned long new_ip;
25063
25064 #ifdef CONFIG_PNPBIOS
25065 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25066 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25067 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25068 extern u32 pnp_bios_is_utter_crap;
25069 pnp_bios_is_utter_crap = 1;
25070 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25071 i += 4;
25072 p->fixup -= i;
25073 i += 4;
25074 +
25075 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25076 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25077 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25078 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25079 +#endif
25080 +
25081 }
25082 }
25083
25084 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25085 index 79ff7da..610cf70 100644
25086 --- a/arch/x86/mm/fault.c
25087 +++ b/arch/x86/mm/fault.c
25088 @@ -13,12 +13,19 @@
25089 #include <linux/perf_event.h> /* perf_sw_event */
25090 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25091 #include <linux/prefetch.h> /* prefetchw */
25092 +#include <linux/unistd.h>
25093 +#include <linux/compiler.h>
25094
25095 #include <asm/traps.h> /* dotraplinkage, ... */
25096 #include <asm/pgalloc.h> /* pgd_*(), ... */
25097 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25098 #include <asm/fixmap.h> /* VSYSCALL_START */
25099 #include <asm/rcu.h> /* exception_enter(), ... */
25100 +#include <asm/tlbflush.h>
25101 +
25102 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25103 +#include <asm/stacktrace.h>
25104 +#endif
25105
25106 /*
25107 * Page fault error code bits:
25108 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25109 int ret = 0;
25110
25111 /* kprobe_running() needs smp_processor_id() */
25112 - if (kprobes_built_in() && !user_mode_vm(regs)) {
25113 + if (kprobes_built_in() && !user_mode(regs)) {
25114 preempt_disable();
25115 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25116 ret = 1;
25117 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25118 return !instr_lo || (instr_lo>>1) == 1;
25119 case 0x00:
25120 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25121 - if (probe_kernel_address(instr, opcode))
25122 + if (user_mode(regs)) {
25123 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25124 + return 0;
25125 + } else if (probe_kernel_address(instr, opcode))
25126 return 0;
25127
25128 *prefetch = (instr_lo == 0xF) &&
25129 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25130 while (instr < max_instr) {
25131 unsigned char opcode;
25132
25133 - if (probe_kernel_address(instr, opcode))
25134 + if (user_mode(regs)) {
25135 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25136 + break;
25137 + } else if (probe_kernel_address(instr, opcode))
25138 break;
25139
25140 instr++;
25141 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25142 force_sig_info(si_signo, &info, tsk);
25143 }
25144
25145 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25146 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25147 +#endif
25148 +
25149 +#ifdef CONFIG_PAX_EMUTRAMP
25150 +static int pax_handle_fetch_fault(struct pt_regs *regs);
25151 +#endif
25152 +
25153 +#ifdef CONFIG_PAX_PAGEEXEC
25154 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25155 +{
25156 + pgd_t *pgd;
25157 + pud_t *pud;
25158 + pmd_t *pmd;
25159 +
25160 + pgd = pgd_offset(mm, address);
25161 + if (!pgd_present(*pgd))
25162 + return NULL;
25163 + pud = pud_offset(pgd, address);
25164 + if (!pud_present(*pud))
25165 + return NULL;
25166 + pmd = pmd_offset(pud, address);
25167 + if (!pmd_present(*pmd))
25168 + return NULL;
25169 + return pmd;
25170 +}
25171 +#endif
25172 +
25173 DEFINE_SPINLOCK(pgd_lock);
25174 LIST_HEAD(pgd_list);
25175
25176 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25177 for (address = VMALLOC_START & PMD_MASK;
25178 address >= TASK_SIZE && address < FIXADDR_TOP;
25179 address += PMD_SIZE) {
25180 +
25181 +#ifdef CONFIG_PAX_PER_CPU_PGD
25182 + unsigned long cpu;
25183 +#else
25184 struct page *page;
25185 +#endif
25186
25187 spin_lock(&pgd_lock);
25188 +
25189 +#ifdef CONFIG_PAX_PER_CPU_PGD
25190 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25191 + pgd_t *pgd = get_cpu_pgd(cpu);
25192 + pmd_t *ret;
25193 +#else
25194 list_for_each_entry(page, &pgd_list, lru) {
25195 + pgd_t *pgd = page_address(page);
25196 spinlock_t *pgt_lock;
25197 pmd_t *ret;
25198
25199 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25200 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25201
25202 spin_lock(pgt_lock);
25203 - ret = vmalloc_sync_one(page_address(page), address);
25204 +#endif
25205 +
25206 + ret = vmalloc_sync_one(pgd, address);
25207 +
25208 +#ifndef CONFIG_PAX_PER_CPU_PGD
25209 spin_unlock(pgt_lock);
25210 +#endif
25211
25212 if (!ret)
25213 break;
25214 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25215 * an interrupt in the middle of a task switch..
25216 */
25217 pgd_paddr = read_cr3();
25218 +
25219 +#ifdef CONFIG_PAX_PER_CPU_PGD
25220 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25221 +#endif
25222 +
25223 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25224 if (!pmd_k)
25225 return -1;
25226 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25227 * happen within a race in page table update. In the later
25228 * case just flush:
25229 */
25230 +
25231 +#ifdef CONFIG_PAX_PER_CPU_PGD
25232 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25233 + pgd = pgd_offset_cpu(smp_processor_id(), address);
25234 +#else
25235 pgd = pgd_offset(current->active_mm, address);
25236 +#endif
25237 +
25238 pgd_ref = pgd_offset_k(address);
25239 if (pgd_none(*pgd_ref))
25240 return -1;
25241 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25242 static int is_errata100(struct pt_regs *regs, unsigned long address)
25243 {
25244 #ifdef CONFIG_X86_64
25245 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25246 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25247 return 1;
25248 #endif
25249 return 0;
25250 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25251 }
25252
25253 static const char nx_warning[] = KERN_CRIT
25254 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25255 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25256
25257 static void
25258 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25259 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25260 if (!oops_may_print())
25261 return;
25262
25263 - if (error_code & PF_INSTR) {
25264 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25265 unsigned int level;
25266
25267 pte_t *pte = lookup_address(address, &level);
25268
25269 if (pte && pte_present(*pte) && !pte_exec(*pte))
25270 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25271 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25272 }
25273
25274 +#ifdef CONFIG_PAX_KERNEXEC
25275 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25276 + if (current->signal->curr_ip)
25277 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25278 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
25279 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25280 + else
25281 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25282 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25283 + }
25284 +#endif
25285 +
25286 printk(KERN_ALERT "BUG: unable to handle kernel ");
25287 if (address < PAGE_SIZE)
25288 printk(KERN_CONT "NULL pointer dereference");
25289 @@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25290 return;
25291 }
25292 #endif
25293 +
25294 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25295 + if (pax_is_fetch_fault(regs, error_code, address)) {
25296 +
25297 +#ifdef CONFIG_PAX_EMUTRAMP
25298 + switch (pax_handle_fetch_fault(regs)) {
25299 + case 2:
25300 + return;
25301 + }
25302 +#endif
25303 +
25304 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25305 + do_group_exit(SIGKILL);
25306 + }
25307 +#endif
25308 +
25309 /* Kernel addresses are always protection faults: */
25310 if (address >= TASK_SIZE)
25311 error_code |= PF_PROT;
25312 @@ -847,7 +945,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25313 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25314 printk(KERN_ERR
25315 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25316 - tsk->comm, tsk->pid, address);
25317 + tsk->comm, task_pid_nr(tsk), address);
25318 code = BUS_MCEERR_AR;
25319 }
25320 #endif
25321 @@ -903,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25322 return 1;
25323 }
25324
25325 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25326 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25327 +{
25328 + pte_t *pte;
25329 + pmd_t *pmd;
25330 + spinlock_t *ptl;
25331 + unsigned char pte_mask;
25332 +
25333 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25334 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25335 + return 0;
25336 +
25337 + /* PaX: it's our fault, let's handle it if we can */
25338 +
25339 + /* PaX: take a look at read faults before acquiring any locks */
25340 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25341 + /* instruction fetch attempt from a protected page in user mode */
25342 + up_read(&mm->mmap_sem);
25343 +
25344 +#ifdef CONFIG_PAX_EMUTRAMP
25345 + switch (pax_handle_fetch_fault(regs)) {
25346 + case 2:
25347 + return 1;
25348 + }
25349 +#endif
25350 +
25351 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25352 + do_group_exit(SIGKILL);
25353 + }
25354 +
25355 + pmd = pax_get_pmd(mm, address);
25356 + if (unlikely(!pmd))
25357 + return 0;
25358 +
25359 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25360 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25361 + pte_unmap_unlock(pte, ptl);
25362 + return 0;
25363 + }
25364 +
25365 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25366 + /* write attempt to a protected page in user mode */
25367 + pte_unmap_unlock(pte, ptl);
25368 + return 0;
25369 + }
25370 +
25371 +#ifdef CONFIG_SMP
25372 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25373 +#else
25374 + if (likely(address > get_limit(regs->cs)))
25375 +#endif
25376 + {
25377 + set_pte(pte, pte_mkread(*pte));
25378 + __flush_tlb_one(address);
25379 + pte_unmap_unlock(pte, ptl);
25380 + up_read(&mm->mmap_sem);
25381 + return 1;
25382 + }
25383 +
25384 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25385 +
25386 + /*
25387 + * PaX: fill DTLB with user rights and retry
25388 + */
25389 + __asm__ __volatile__ (
25390 + "orb %2,(%1)\n"
25391 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25392 +/*
25393 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25394 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25395 + * page fault when examined during a TLB load attempt. this is true not only
25396 + * for PTEs holding a non-present entry but also present entries that will
25397 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25398 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25399 + * for our target pages since their PTEs are simply not in the TLBs at all.
25400 +
25401 + * the best thing in omitting it is that we gain around 15-20% speed in the
25402 + * fast path of the page fault handler and can get rid of tracing since we
25403 + * can no longer flush unintended entries.
25404 + */
25405 + "invlpg (%0)\n"
25406 +#endif
25407 + __copyuser_seg"testb $0,(%0)\n"
25408 + "xorb %3,(%1)\n"
25409 + :
25410 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25411 + : "memory", "cc");
25412 + pte_unmap_unlock(pte, ptl);
25413 + up_read(&mm->mmap_sem);
25414 + return 1;
25415 +}
25416 +#endif
25417 +
25418 /*
25419 * Handle a spurious fault caused by a stale TLB entry.
25420 *
25421 @@ -975,6 +1166,9 @@ int show_unhandled_signals = 1;
25422 static inline int
25423 access_error(unsigned long error_code, struct vm_area_struct *vma)
25424 {
25425 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25426 + return 1;
25427 +
25428 if (error_code & PF_WRITE) {
25429 /* write, present and write, not present: */
25430 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25431 @@ -1003,7 +1197,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25432 if (error_code & PF_USER)
25433 return false;
25434
25435 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25436 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25437 return false;
25438
25439 return true;
25440 @@ -1019,18 +1213,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25441 {
25442 struct vm_area_struct *vma;
25443 struct task_struct *tsk;
25444 - unsigned long address;
25445 struct mm_struct *mm;
25446 int fault;
25447 int write = error_code & PF_WRITE;
25448 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25449 (write ? FAULT_FLAG_WRITE : 0);
25450
25451 - tsk = current;
25452 - mm = tsk->mm;
25453 -
25454 /* Get the faulting address: */
25455 - address = read_cr2();
25456 + unsigned long address = read_cr2();
25457 +
25458 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25459 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25460 + if (!search_exception_tables(regs->ip)) {
25461 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25462 + bad_area_nosemaphore(regs, error_code, address);
25463 + return;
25464 + }
25465 + if (address < PAX_USER_SHADOW_BASE) {
25466 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25467 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25468 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25469 + } else
25470 + address -= PAX_USER_SHADOW_BASE;
25471 + }
25472 +#endif
25473 +
25474 + tsk = current;
25475 + mm = tsk->mm;
25476
25477 /*
25478 * Detect and handle instructions that would cause a page fault for
25479 @@ -1091,7 +1300,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25480 * User-mode registers count as a user access even for any
25481 * potential system fault or CPU buglet:
25482 */
25483 - if (user_mode_vm(regs)) {
25484 + if (user_mode(regs)) {
25485 local_irq_enable();
25486 error_code |= PF_USER;
25487 } else {
25488 @@ -1153,6 +1362,11 @@ retry:
25489 might_sleep();
25490 }
25491
25492 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25493 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25494 + return;
25495 +#endif
25496 +
25497 vma = find_vma(mm, address);
25498 if (unlikely(!vma)) {
25499 bad_area(regs, error_code, address);
25500 @@ -1164,18 +1378,24 @@ retry:
25501 bad_area(regs, error_code, address);
25502 return;
25503 }
25504 - if (error_code & PF_USER) {
25505 - /*
25506 - * Accessing the stack below %sp is always a bug.
25507 - * The large cushion allows instructions like enter
25508 - * and pusha to work. ("enter $65535, $31" pushes
25509 - * 32 pointers and then decrements %sp by 65535.)
25510 - */
25511 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25512 - bad_area(regs, error_code, address);
25513 - return;
25514 - }
25515 + /*
25516 + * Accessing the stack below %sp is always a bug.
25517 + * The large cushion allows instructions like enter
25518 + * and pusha to work. ("enter $65535, $31" pushes
25519 + * 32 pointers and then decrements %sp by 65535.)
25520 + */
25521 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25522 + bad_area(regs, error_code, address);
25523 + return;
25524 }
25525 +
25526 +#ifdef CONFIG_PAX_SEGMEXEC
25527 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25528 + bad_area(regs, error_code, address);
25529 + return;
25530 + }
25531 +#endif
25532 +
25533 if (unlikely(expand_stack(vma, address))) {
25534 bad_area(regs, error_code, address);
25535 return;
25536 @@ -1239,3 +1459,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25537 __do_page_fault(regs, error_code);
25538 exception_exit(regs);
25539 }
25540 +
25541 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25542 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25543 +{
25544 + struct mm_struct *mm = current->mm;
25545 + unsigned long ip = regs->ip;
25546 +
25547 + if (v8086_mode(regs))
25548 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25549 +
25550 +#ifdef CONFIG_PAX_PAGEEXEC
25551 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25552 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25553 + return true;
25554 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25555 + return true;
25556 + return false;
25557 + }
25558 +#endif
25559 +
25560 +#ifdef CONFIG_PAX_SEGMEXEC
25561 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25562 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25563 + return true;
25564 + return false;
25565 + }
25566 +#endif
25567 +
25568 + return false;
25569 +}
25570 +#endif
25571 +
25572 +#ifdef CONFIG_PAX_EMUTRAMP
25573 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25574 +{
25575 + int err;
25576 +
25577 + do { /* PaX: libffi trampoline emulation */
25578 + unsigned char mov, jmp;
25579 + unsigned int addr1, addr2;
25580 +
25581 +#ifdef CONFIG_X86_64
25582 + if ((regs->ip + 9) >> 32)
25583 + break;
25584 +#endif
25585 +
25586 + err = get_user(mov, (unsigned char __user *)regs->ip);
25587 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25588 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25589 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25590 +
25591 + if (err)
25592 + break;
25593 +
25594 + if (mov == 0xB8 && jmp == 0xE9) {
25595 + regs->ax = addr1;
25596 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25597 + return 2;
25598 + }
25599 + } while (0);
25600 +
25601 + do { /* PaX: gcc trampoline emulation #1 */
25602 + unsigned char mov1, mov2;
25603 + unsigned short jmp;
25604 + unsigned int addr1, addr2;
25605 +
25606 +#ifdef CONFIG_X86_64
25607 + if ((regs->ip + 11) >> 32)
25608 + break;
25609 +#endif
25610 +
25611 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25612 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25613 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25614 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25615 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25616 +
25617 + if (err)
25618 + break;
25619 +
25620 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25621 + regs->cx = addr1;
25622 + regs->ax = addr2;
25623 + regs->ip = addr2;
25624 + return 2;
25625 + }
25626 + } while (0);
25627 +
25628 + do { /* PaX: gcc trampoline emulation #2 */
25629 + unsigned char mov, jmp;
25630 + unsigned int addr1, addr2;
25631 +
25632 +#ifdef CONFIG_X86_64
25633 + if ((regs->ip + 9) >> 32)
25634 + break;
25635 +#endif
25636 +
25637 + err = get_user(mov, (unsigned char __user *)regs->ip);
25638 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25639 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25640 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25641 +
25642 + if (err)
25643 + break;
25644 +
25645 + if (mov == 0xB9 && jmp == 0xE9) {
25646 + regs->cx = addr1;
25647 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25648 + return 2;
25649 + }
25650 + } while (0);
25651 +
25652 + return 1; /* PaX in action */
25653 +}
25654 +
25655 +#ifdef CONFIG_X86_64
25656 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25657 +{
25658 + int err;
25659 +
25660 + do { /* PaX: libffi trampoline emulation */
25661 + unsigned short mov1, mov2, jmp1;
25662 + unsigned char stcclc, jmp2;
25663 + unsigned long addr1, addr2;
25664 +
25665 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25666 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25667 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25668 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25669 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25670 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25671 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25672 +
25673 + if (err)
25674 + break;
25675 +
25676 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25677 + regs->r11 = addr1;
25678 + regs->r10 = addr2;
25679 + if (stcclc == 0xF8)
25680 + regs->flags &= ~X86_EFLAGS_CF;
25681 + else
25682 + regs->flags |= X86_EFLAGS_CF;
25683 + regs->ip = addr1;
25684 + return 2;
25685 + }
25686 + } while (0);
25687 +
25688 + do { /* PaX: gcc trampoline emulation #1 */
25689 + unsigned short mov1, mov2, jmp1;
25690 + unsigned char jmp2;
25691 + unsigned int addr1;
25692 + unsigned long addr2;
25693 +
25694 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25695 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25696 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25697 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25698 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25699 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25700 +
25701 + if (err)
25702 + break;
25703 +
25704 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25705 + regs->r11 = addr1;
25706 + regs->r10 = addr2;
25707 + regs->ip = addr1;
25708 + return 2;
25709 + }
25710 + } while (0);
25711 +
25712 + do { /* PaX: gcc trampoline emulation #2 */
25713 + unsigned short mov1, mov2, jmp1;
25714 + unsigned char jmp2;
25715 + unsigned long addr1, addr2;
25716 +
25717 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25718 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25719 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25720 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25721 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25722 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25723 +
25724 + if (err)
25725 + break;
25726 +
25727 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25728 + regs->r11 = addr1;
25729 + regs->r10 = addr2;
25730 + regs->ip = addr1;
25731 + return 2;
25732 + }
25733 + } while (0);
25734 +
25735 + return 1; /* PaX in action */
25736 +}
25737 +#endif
25738 +
25739 +/*
25740 + * PaX: decide what to do with offenders (regs->ip = fault address)
25741 + *
25742 + * returns 1 when task should be killed
25743 + * 2 when gcc trampoline was detected
25744 + */
25745 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25746 +{
25747 + if (v8086_mode(regs))
25748 + return 1;
25749 +
25750 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25751 + return 1;
25752 +
25753 +#ifdef CONFIG_X86_32
25754 + return pax_handle_fetch_fault_32(regs);
25755 +#else
25756 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25757 + return pax_handle_fetch_fault_32(regs);
25758 + else
25759 + return pax_handle_fetch_fault_64(regs);
25760 +#endif
25761 +}
25762 +#endif
25763 +
25764 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25765 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25766 +{
25767 + long i;
25768 +
25769 + printk(KERN_ERR "PAX: bytes at PC: ");
25770 + for (i = 0; i < 20; i++) {
25771 + unsigned char c;
25772 + if (get_user(c, (unsigned char __force_user *)pc+i))
25773 + printk(KERN_CONT "?? ");
25774 + else
25775 + printk(KERN_CONT "%02x ", c);
25776 + }
25777 + printk("\n");
25778 +
25779 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25780 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25781 + unsigned long c;
25782 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25783 +#ifdef CONFIG_X86_32
25784 + printk(KERN_CONT "???????? ");
25785 +#else
25786 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25787 + printk(KERN_CONT "???????? ???????? ");
25788 + else
25789 + printk(KERN_CONT "???????????????? ");
25790 +#endif
25791 + } else {
25792 +#ifdef CONFIG_X86_64
25793 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25794 + printk(KERN_CONT "%08x ", (unsigned int)c);
25795 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25796 + } else
25797 +#endif
25798 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25799 + }
25800 + }
25801 + printk("\n");
25802 +}
25803 +#endif
25804 +
25805 +/**
25806 + * probe_kernel_write(): safely attempt to write to a location
25807 + * @dst: address to write to
25808 + * @src: pointer to the data that shall be written
25809 + * @size: size of the data chunk
25810 + *
25811 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25812 + * happens, handle that and return -EFAULT.
25813 + */
25814 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25815 +{
25816 + long ret;
25817 + mm_segment_t old_fs = get_fs();
25818 +
25819 + set_fs(KERNEL_DS);
25820 + pagefault_disable();
25821 + pax_open_kernel();
25822 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25823 + pax_close_kernel();
25824 + pagefault_enable();
25825 + set_fs(old_fs);
25826 +
25827 + return ret ? -EFAULT : 0;
25828 +}
25829 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25830 index dd74e46..7d26398 100644
25831 --- a/arch/x86/mm/gup.c
25832 +++ b/arch/x86/mm/gup.c
25833 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25834 addr = start;
25835 len = (unsigned long) nr_pages << PAGE_SHIFT;
25836 end = start + len;
25837 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25838 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25839 (void __user *)start, len)))
25840 return 0;
25841
25842 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25843 index 6f31ee5..8ee4164 100644
25844 --- a/arch/x86/mm/highmem_32.c
25845 +++ b/arch/x86/mm/highmem_32.c
25846 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25847 idx = type + KM_TYPE_NR*smp_processor_id();
25848 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25849 BUG_ON(!pte_none(*(kmap_pte-idx)));
25850 +
25851 + pax_open_kernel();
25852 set_pte(kmap_pte-idx, mk_pte(page, prot));
25853 + pax_close_kernel();
25854 +
25855 arch_flush_lazy_mmu_mode();
25856
25857 return (void *)vaddr;
25858 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25859 index 937bff5..dce75ff 100644
25860 --- a/arch/x86/mm/hugetlbpage.c
25861 +++ b/arch/x86/mm/hugetlbpage.c
25862 @@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25863 struct hstate *h = hstate_file(file);
25864 struct mm_struct *mm = current->mm;
25865 struct vm_area_struct *vma;
25866 - unsigned long start_addr;
25867 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25868 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25869 +
25870 +#ifdef CONFIG_PAX_SEGMEXEC
25871 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25872 + pax_task_size = SEGMEXEC_TASK_SIZE;
25873 +#endif
25874 +
25875 + pax_task_size -= PAGE_SIZE;
25876
25877 if (len > mm->cached_hole_size) {
25878 - start_addr = mm->free_area_cache;
25879 + start_addr = mm->free_area_cache;
25880 } else {
25881 - start_addr = TASK_UNMAPPED_BASE;
25882 - mm->cached_hole_size = 0;
25883 + start_addr = mm->mmap_base;
25884 + mm->cached_hole_size = 0;
25885 }
25886
25887 full_search:
25888 @@ -290,26 +298,27 @@ full_search:
25889
25890 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25891 /* At this point: (!vma || addr < vma->vm_end). */
25892 - if (TASK_SIZE - len < addr) {
25893 + if (pax_task_size - len < addr) {
25894 /*
25895 * Start a new search - just in case we missed
25896 * some holes.
25897 */
25898 - if (start_addr != TASK_UNMAPPED_BASE) {
25899 - start_addr = TASK_UNMAPPED_BASE;
25900 + if (start_addr != mm->mmap_base) {
25901 + start_addr = mm->mmap_base;
25902 mm->cached_hole_size = 0;
25903 goto full_search;
25904 }
25905 return -ENOMEM;
25906 }
25907 - if (!vma || addr + len <= vma->vm_start) {
25908 - mm->free_area_cache = addr + len;
25909 - return addr;
25910 - }
25911 + if (check_heap_stack_gap(vma, addr, len, offset))
25912 + break;
25913 if (addr + mm->cached_hole_size < vma->vm_start)
25914 mm->cached_hole_size = vma->vm_start - addr;
25915 addr = ALIGN(vma->vm_end, huge_page_size(h));
25916 }
25917 +
25918 + mm->free_area_cache = addr + len;
25919 + return addr;
25920 }
25921
25922 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25923 @@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25924 struct mm_struct *mm = current->mm;
25925 struct vm_area_struct *vma;
25926 unsigned long base = mm->mmap_base;
25927 - unsigned long addr = addr0;
25928 + unsigned long addr;
25929 unsigned long largest_hole = mm->cached_hole_size;
25930 - unsigned long start_addr;
25931 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25932
25933 /* don't allow allocations above current base */
25934 if (mm->free_area_cache > base)
25935 @@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25936 largest_hole = 0;
25937 mm->free_area_cache = base;
25938 }
25939 -try_again:
25940 - start_addr = mm->free_area_cache;
25941
25942 /* make sure it can fit in the remaining address space */
25943 if (mm->free_area_cache < len)
25944 goto fail;
25945
25946 /* either no address requested or can't fit in requested address hole */
25947 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
25948 + addr = mm->free_area_cache - len;
25949 do {
25950 + addr &= huge_page_mask(h);
25951 /*
25952 * Lookup failure means no vma is above this address,
25953 * i.e. return with success:
25954 @@ -350,10 +358,10 @@ try_again:
25955 if (!vma)
25956 return addr;
25957
25958 - if (addr + len <= vma->vm_start) {
25959 + if (check_heap_stack_gap(vma, addr, len, offset)) {
25960 /* remember the address as a hint for next time */
25961 - mm->cached_hole_size = largest_hole;
25962 - return (mm->free_area_cache = addr);
25963 + mm->cached_hole_size = largest_hole;
25964 + return (mm->free_area_cache = addr);
25965 } else if (mm->free_area_cache == vma->vm_end) {
25966 /* pull free_area_cache down to the first hole */
25967 mm->free_area_cache = vma->vm_start;
25968 @@ -362,29 +370,34 @@ try_again:
25969
25970 /* remember the largest hole we saw so far */
25971 if (addr + largest_hole < vma->vm_start)
25972 - largest_hole = vma->vm_start - addr;
25973 + largest_hole = vma->vm_start - addr;
25974
25975 /* try just below the current vma->vm_start */
25976 - addr = (vma->vm_start - len) & huge_page_mask(h);
25977 - } while (len <= vma->vm_start);
25978 + addr = skip_heap_stack_gap(vma, len, offset);
25979 + } while (!IS_ERR_VALUE(addr));
25980
25981 fail:
25982 /*
25983 - * if hint left us with no space for the requested
25984 - * mapping then try again:
25985 - */
25986 - if (start_addr != base) {
25987 - mm->free_area_cache = base;
25988 - largest_hole = 0;
25989 - goto try_again;
25990 - }
25991 - /*
25992 * A failed mmap() very likely causes application failure,
25993 * so fall back to the bottom-up function here. This scenario
25994 * can happen with large stack limits and large mmap()
25995 * allocations.
25996 */
25997 - mm->free_area_cache = TASK_UNMAPPED_BASE;
25998 +
25999 +#ifdef CONFIG_PAX_SEGMEXEC
26000 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26001 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26002 + else
26003 +#endif
26004 +
26005 + mm->mmap_base = TASK_UNMAPPED_BASE;
26006 +
26007 +#ifdef CONFIG_PAX_RANDMMAP
26008 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26009 + mm->mmap_base += mm->delta_mmap;
26010 +#endif
26011 +
26012 + mm->free_area_cache = mm->mmap_base;
26013 mm->cached_hole_size = ~0UL;
26014 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26015 len, pgoff, flags);
26016 @@ -392,6 +405,7 @@ fail:
26017 /*
26018 * Restore the topdown base:
26019 */
26020 + mm->mmap_base = base;
26021 mm->free_area_cache = base;
26022 mm->cached_hole_size = ~0UL;
26023
26024 @@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26025 struct hstate *h = hstate_file(file);
26026 struct mm_struct *mm = current->mm;
26027 struct vm_area_struct *vma;
26028 + unsigned long pax_task_size = TASK_SIZE;
26029 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26030
26031 if (len & ~huge_page_mask(h))
26032 return -EINVAL;
26033 - if (len > TASK_SIZE)
26034 +
26035 +#ifdef CONFIG_PAX_SEGMEXEC
26036 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26037 + pax_task_size = SEGMEXEC_TASK_SIZE;
26038 +#endif
26039 +
26040 + pax_task_size -= PAGE_SIZE;
26041 +
26042 + if (len > pax_task_size)
26043 return -ENOMEM;
26044
26045 if (flags & MAP_FIXED) {
26046 @@ -417,11 +441,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26047 return addr;
26048 }
26049
26050 +#ifdef CONFIG_PAX_RANDMMAP
26051 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26052 +#endif
26053 +
26054 if (addr) {
26055 addr = ALIGN(addr, huge_page_size(h));
26056 vma = find_vma(mm, addr);
26057 - if (TASK_SIZE - len >= addr &&
26058 - (!vma || addr + len <= vma->vm_start))
26059 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26060 return addr;
26061 }
26062 if (mm->get_unmapped_area == arch_get_unmapped_area)
26063 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26064 index d7aea41..0fc945b 100644
26065 --- a/arch/x86/mm/init.c
26066 +++ b/arch/x86/mm/init.c
26067 @@ -4,6 +4,7 @@
26068 #include <linux/swap.h>
26069 #include <linux/memblock.h>
26070 #include <linux/bootmem.h> /* for max_low_pfn */
26071 +#include <linux/tboot.h>
26072
26073 #include <asm/cacheflush.h>
26074 #include <asm/e820.h>
26075 @@ -16,6 +17,8 @@
26076 #include <asm/tlb.h>
26077 #include <asm/proto.h>
26078 #include <asm/dma.h> /* for MAX_DMA_PFN */
26079 +#include <asm/desc.h>
26080 +#include <asm/bios_ebda.h>
26081
26082 unsigned long __initdata pgt_buf_start;
26083 unsigned long __meminitdata pgt_buf_end;
26084 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26085 {
26086 int i;
26087 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26088 - unsigned long start = 0, good_end;
26089 + unsigned long start = 0x100000, good_end;
26090 phys_addr_t base;
26091
26092 for (i = 0; i < nr_range; i++) {
26093 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26094 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26095 * mmio resources as well as potential bios/acpi data regions.
26096 */
26097 +
26098 +#ifdef CONFIG_GRKERNSEC_KMEM
26099 +static unsigned int ebda_start __read_only;
26100 +static unsigned int ebda_end __read_only;
26101 +#endif
26102 +
26103 int devmem_is_allowed(unsigned long pagenr)
26104 {
26105 - if (pagenr < 256)
26106 +#ifdef CONFIG_GRKERNSEC_KMEM
26107 + /* allow BDA */
26108 + if (!pagenr)
26109 return 1;
26110 + /* allow EBDA */
26111 + if (pagenr >= ebda_start && pagenr < ebda_end)
26112 + return 1;
26113 + /* if tboot is in use, allow access to its hardcoded serial log range */
26114 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26115 + return 1;
26116 +#else
26117 + if (!pagenr)
26118 + return 1;
26119 +#ifdef CONFIG_VM86
26120 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26121 + return 1;
26122 +#endif
26123 +#endif
26124 +
26125 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26126 + return 1;
26127 +#ifdef CONFIG_GRKERNSEC_KMEM
26128 + /* throw out everything else below 1MB */
26129 + if (pagenr <= 256)
26130 + return 0;
26131 +#endif
26132 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26133 return 0;
26134 if (!page_is_ram(pagenr))
26135 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26136 #endif
26137 }
26138
26139 +#ifdef CONFIG_GRKERNSEC_KMEM
26140 +static inline void gr_init_ebda(void)
26141 +{
26142 + unsigned int ebda_addr;
26143 + unsigned int ebda_size = 0;
26144 +
26145 + ebda_addr = get_bios_ebda();
26146 + if (ebda_addr) {
26147 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26148 + ebda_size <<= 10;
26149 + }
26150 + if (ebda_addr && ebda_size) {
26151 + ebda_start = ebda_addr >> PAGE_SHIFT;
26152 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26153 + } else {
26154 + ebda_start = 0x9f000 >> PAGE_SHIFT;
26155 + ebda_end = 0xa0000 >> PAGE_SHIFT;
26156 + }
26157 +}
26158 +#else
26159 +static inline void gr_init_ebda(void) { }
26160 +#endif
26161 +
26162 void free_initmem(void)
26163 {
26164 +#ifdef CONFIG_PAX_KERNEXEC
26165 +#ifdef CONFIG_X86_32
26166 + /* PaX: limit KERNEL_CS to actual size */
26167 + unsigned long addr, limit;
26168 + struct desc_struct d;
26169 + int cpu;
26170 +#else
26171 + pgd_t *pgd;
26172 + pud_t *pud;
26173 + pmd_t *pmd;
26174 + unsigned long addr, end;
26175 +#endif
26176 +#endif
26177 +
26178 + gr_init_ebda();
26179 +
26180 +#ifdef CONFIG_PAX_KERNEXEC
26181 +#ifdef CONFIG_X86_32
26182 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26183 + limit = (limit - 1UL) >> PAGE_SHIFT;
26184 +
26185 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26186 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26187 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26188 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26189 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26190 + }
26191 +
26192 + /* PaX: make KERNEL_CS read-only */
26193 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26194 + if (!paravirt_enabled())
26195 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26196 +/*
26197 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26198 + pgd = pgd_offset_k(addr);
26199 + pud = pud_offset(pgd, addr);
26200 + pmd = pmd_offset(pud, addr);
26201 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26202 + }
26203 +*/
26204 +#ifdef CONFIG_X86_PAE
26205 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26206 +/*
26207 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26208 + pgd = pgd_offset_k(addr);
26209 + pud = pud_offset(pgd, addr);
26210 + pmd = pmd_offset(pud, addr);
26211 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26212 + }
26213 +*/
26214 +#endif
26215 +
26216 +#ifdef CONFIG_MODULES
26217 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26218 +#endif
26219 +
26220 +#else
26221 + /* PaX: make kernel code/rodata read-only, rest non-executable */
26222 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26223 + pgd = pgd_offset_k(addr);
26224 + pud = pud_offset(pgd, addr);
26225 + pmd = pmd_offset(pud, addr);
26226 + if (!pmd_present(*pmd))
26227 + continue;
26228 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26229 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26230 + else
26231 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26232 + }
26233 +
26234 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26235 + end = addr + KERNEL_IMAGE_SIZE;
26236 + for (; addr < end; addr += PMD_SIZE) {
26237 + pgd = pgd_offset_k(addr);
26238 + pud = pud_offset(pgd, addr);
26239 + pmd = pmd_offset(pud, addr);
26240 + if (!pmd_present(*pmd))
26241 + continue;
26242 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26243 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26244 + }
26245 +#endif
26246 +
26247 + flush_tlb_all();
26248 +#endif
26249 +
26250 free_init_pages("unused kernel memory",
26251 (unsigned long)(&__init_begin),
26252 (unsigned long)(&__init_end));
26253 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26254 index 11a5800..4bd9977 100644
26255 --- a/arch/x86/mm/init_32.c
26256 +++ b/arch/x86/mm/init_32.c
26257 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26258 }
26259
26260 /*
26261 - * Creates a middle page table and puts a pointer to it in the
26262 - * given global directory entry. This only returns the gd entry
26263 - * in non-PAE compilation mode, since the middle layer is folded.
26264 - */
26265 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
26266 -{
26267 - pud_t *pud;
26268 - pmd_t *pmd_table;
26269 -
26270 -#ifdef CONFIG_X86_PAE
26271 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26272 - if (after_bootmem)
26273 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26274 - else
26275 - pmd_table = (pmd_t *)alloc_low_page();
26276 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26277 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26278 - pud = pud_offset(pgd, 0);
26279 - BUG_ON(pmd_table != pmd_offset(pud, 0));
26280 -
26281 - return pmd_table;
26282 - }
26283 -#endif
26284 - pud = pud_offset(pgd, 0);
26285 - pmd_table = pmd_offset(pud, 0);
26286 -
26287 - return pmd_table;
26288 -}
26289 -
26290 -/*
26291 * Create a page table and place a pointer to it in a middle page
26292 * directory entry:
26293 */
26294 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26295 page_table = (pte_t *)alloc_low_page();
26296
26297 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26298 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26299 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26300 +#else
26301 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26302 +#endif
26303 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26304 }
26305
26306 return pte_offset_kernel(pmd, 0);
26307 }
26308
26309 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26310 +{
26311 + pud_t *pud;
26312 + pmd_t *pmd_table;
26313 +
26314 + pud = pud_offset(pgd, 0);
26315 + pmd_table = pmd_offset(pud, 0);
26316 +
26317 + return pmd_table;
26318 +}
26319 +
26320 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26321 {
26322 int pgd_idx = pgd_index(vaddr);
26323 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26324 int pgd_idx, pmd_idx;
26325 unsigned long vaddr;
26326 pgd_t *pgd;
26327 + pud_t *pud;
26328 pmd_t *pmd;
26329 pte_t *pte = NULL;
26330
26331 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26332 pgd = pgd_base + pgd_idx;
26333
26334 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26335 - pmd = one_md_table_init(pgd);
26336 - pmd = pmd + pmd_index(vaddr);
26337 + pud = pud_offset(pgd, vaddr);
26338 + pmd = pmd_offset(pud, vaddr);
26339 +
26340 +#ifdef CONFIG_X86_PAE
26341 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26342 +#endif
26343 +
26344 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26345 pmd++, pmd_idx++) {
26346 pte = page_table_kmap_check(one_page_table_init(pmd),
26347 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26348 }
26349 }
26350
26351 -static inline int is_kernel_text(unsigned long addr)
26352 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26353 {
26354 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26355 - return 1;
26356 - return 0;
26357 + if ((start > ktla_ktva((unsigned long)_etext) ||
26358 + end <= ktla_ktva((unsigned long)_stext)) &&
26359 + (start > ktla_ktva((unsigned long)_einittext) ||
26360 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26361 +
26362 +#ifdef CONFIG_ACPI_SLEEP
26363 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26364 +#endif
26365 +
26366 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26367 + return 0;
26368 + return 1;
26369 }
26370
26371 /*
26372 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26373 unsigned long last_map_addr = end;
26374 unsigned long start_pfn, end_pfn;
26375 pgd_t *pgd_base = swapper_pg_dir;
26376 - int pgd_idx, pmd_idx, pte_ofs;
26377 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26378 unsigned long pfn;
26379 pgd_t *pgd;
26380 + pud_t *pud;
26381 pmd_t *pmd;
26382 pte_t *pte;
26383 unsigned pages_2m, pages_4k;
26384 @@ -280,8 +281,13 @@ repeat:
26385 pfn = start_pfn;
26386 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26387 pgd = pgd_base + pgd_idx;
26388 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26389 - pmd = one_md_table_init(pgd);
26390 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26391 + pud = pud_offset(pgd, 0);
26392 + pmd = pmd_offset(pud, 0);
26393 +
26394 +#ifdef CONFIG_X86_PAE
26395 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26396 +#endif
26397
26398 if (pfn >= end_pfn)
26399 continue;
26400 @@ -293,14 +299,13 @@ repeat:
26401 #endif
26402 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26403 pmd++, pmd_idx++) {
26404 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26405 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26406
26407 /*
26408 * Map with big pages if possible, otherwise
26409 * create normal page tables:
26410 */
26411 if (use_pse) {
26412 - unsigned int addr2;
26413 pgprot_t prot = PAGE_KERNEL_LARGE;
26414 /*
26415 * first pass will use the same initial
26416 @@ -310,11 +315,7 @@ repeat:
26417 __pgprot(PTE_IDENT_ATTR |
26418 _PAGE_PSE);
26419
26420 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26421 - PAGE_OFFSET + PAGE_SIZE-1;
26422 -
26423 - if (is_kernel_text(addr) ||
26424 - is_kernel_text(addr2))
26425 + if (is_kernel_text(address, address + PMD_SIZE))
26426 prot = PAGE_KERNEL_LARGE_EXEC;
26427
26428 pages_2m++;
26429 @@ -331,7 +332,7 @@ repeat:
26430 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26431 pte += pte_ofs;
26432 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26433 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26434 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26435 pgprot_t prot = PAGE_KERNEL;
26436 /*
26437 * first pass will use the same initial
26438 @@ -339,7 +340,7 @@ repeat:
26439 */
26440 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26441
26442 - if (is_kernel_text(addr))
26443 + if (is_kernel_text(address, address + PAGE_SIZE))
26444 prot = PAGE_KERNEL_EXEC;
26445
26446 pages_4k++;
26447 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26448
26449 pud = pud_offset(pgd, va);
26450 pmd = pmd_offset(pud, va);
26451 - if (!pmd_present(*pmd))
26452 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26453 break;
26454
26455 pte = pte_offset_kernel(pmd, va);
26456 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26457
26458 static void __init pagetable_init(void)
26459 {
26460 - pgd_t *pgd_base = swapper_pg_dir;
26461 -
26462 - permanent_kmaps_init(pgd_base);
26463 + permanent_kmaps_init(swapper_pg_dir);
26464 }
26465
26466 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26467 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26468 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26469
26470 /* user-defined highmem size */
26471 @@ -731,6 +730,12 @@ void __init mem_init(void)
26472
26473 pci_iommu_alloc();
26474
26475 +#ifdef CONFIG_PAX_PER_CPU_PGD
26476 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26477 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26478 + KERNEL_PGD_PTRS);
26479 +#endif
26480 +
26481 #ifdef CONFIG_FLATMEM
26482 BUG_ON(!mem_map);
26483 #endif
26484 @@ -757,7 +762,7 @@ void __init mem_init(void)
26485 reservedpages++;
26486
26487 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26488 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26489 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26490 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26491
26492 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26493 @@ -798,10 +803,10 @@ void __init mem_init(void)
26494 ((unsigned long)&__init_end -
26495 (unsigned long)&__init_begin) >> 10,
26496
26497 - (unsigned long)&_etext, (unsigned long)&_edata,
26498 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26499 + (unsigned long)&_sdata, (unsigned long)&_edata,
26500 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26501
26502 - (unsigned long)&_text, (unsigned long)&_etext,
26503 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26504 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26505
26506 /*
26507 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26508 if (!kernel_set_to_readonly)
26509 return;
26510
26511 + start = ktla_ktva(start);
26512 pr_debug("Set kernel text: %lx - %lx for read write\n",
26513 start, start+size);
26514
26515 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26516 if (!kernel_set_to_readonly)
26517 return;
26518
26519 + start = ktla_ktva(start);
26520 pr_debug("Set kernel text: %lx - %lx for read only\n",
26521 start, start+size);
26522
26523 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26524 unsigned long start = PFN_ALIGN(_text);
26525 unsigned long size = PFN_ALIGN(_etext) - start;
26526
26527 + start = ktla_ktva(start);
26528 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26529 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26530 size >> 10);
26531 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26532 index ce42da7..678a54e 100644
26533 --- a/arch/x86/mm/init_64.c
26534 +++ b/arch/x86/mm/init_64.c
26535 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26536 * around without checking the pgd every time.
26537 */
26538
26539 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26540 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26541 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26542
26543 int force_personality32;
26544 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26545
26546 for (address = start; address <= end; address += PGDIR_SIZE) {
26547 const pgd_t *pgd_ref = pgd_offset_k(address);
26548 +
26549 +#ifdef CONFIG_PAX_PER_CPU_PGD
26550 + unsigned long cpu;
26551 +#else
26552 struct page *page;
26553 +#endif
26554
26555 if (pgd_none(*pgd_ref))
26556 continue;
26557
26558 spin_lock(&pgd_lock);
26559 +
26560 +#ifdef CONFIG_PAX_PER_CPU_PGD
26561 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26562 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26563 +#else
26564 list_for_each_entry(page, &pgd_list, lru) {
26565 pgd_t *pgd;
26566 spinlock_t *pgt_lock;
26567 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26568 /* the pgt_lock only for Xen */
26569 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26570 spin_lock(pgt_lock);
26571 +#endif
26572
26573 if (pgd_none(*pgd))
26574 set_pgd(pgd, *pgd_ref);
26575 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26576 BUG_ON(pgd_page_vaddr(*pgd)
26577 != pgd_page_vaddr(*pgd_ref));
26578
26579 +#ifndef CONFIG_PAX_PER_CPU_PGD
26580 spin_unlock(pgt_lock);
26581 +#endif
26582 +
26583 }
26584 spin_unlock(&pgd_lock);
26585 }
26586 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26587 {
26588 if (pgd_none(*pgd)) {
26589 pud_t *pud = (pud_t *)spp_getpage();
26590 - pgd_populate(&init_mm, pgd, pud);
26591 + pgd_populate_kernel(&init_mm, pgd, pud);
26592 if (pud != pud_offset(pgd, 0))
26593 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26594 pud, pud_offset(pgd, 0));
26595 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26596 {
26597 if (pud_none(*pud)) {
26598 pmd_t *pmd = (pmd_t *) spp_getpage();
26599 - pud_populate(&init_mm, pud, pmd);
26600 + pud_populate_kernel(&init_mm, pud, pmd);
26601 if (pmd != pmd_offset(pud, 0))
26602 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26603 pmd, pmd_offset(pud, 0));
26604 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26605 pmd = fill_pmd(pud, vaddr);
26606 pte = fill_pte(pmd, vaddr);
26607
26608 + pax_open_kernel();
26609 set_pte(pte, new_pte);
26610 + pax_close_kernel();
26611
26612 /*
26613 * It's enough to flush this one mapping.
26614 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26615 pgd = pgd_offset_k((unsigned long)__va(phys));
26616 if (pgd_none(*pgd)) {
26617 pud = (pud_t *) spp_getpage();
26618 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26619 - _PAGE_USER));
26620 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26621 }
26622 pud = pud_offset(pgd, (unsigned long)__va(phys));
26623 if (pud_none(*pud)) {
26624 pmd = (pmd_t *) spp_getpage();
26625 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26626 - _PAGE_USER));
26627 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26628 }
26629 pmd = pmd_offset(pud, phys);
26630 BUG_ON(!pmd_none(*pmd));
26631 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26632 if (pfn >= pgt_buf_top)
26633 panic("alloc_low_page: ran out of memory");
26634
26635 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26636 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26637 clear_page(adr);
26638 *phys = pfn * PAGE_SIZE;
26639 return adr;
26640 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26641
26642 phys = __pa(virt);
26643 left = phys & (PAGE_SIZE - 1);
26644 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26645 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26646 adr = (void *)(((unsigned long)adr) | left);
26647
26648 return adr;
26649 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26650 unmap_low_page(pmd);
26651
26652 spin_lock(&init_mm.page_table_lock);
26653 - pud_populate(&init_mm, pud, __va(pmd_phys));
26654 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26655 spin_unlock(&init_mm.page_table_lock);
26656 }
26657 __flush_tlb_all();
26658 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26659 unmap_low_page(pud);
26660
26661 spin_lock(&init_mm.page_table_lock);
26662 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26663 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26664 spin_unlock(&init_mm.page_table_lock);
26665 pgd_changed = true;
26666 }
26667 @@ -691,6 +705,12 @@ void __init mem_init(void)
26668
26669 pci_iommu_alloc();
26670
26671 +#ifdef CONFIG_PAX_PER_CPU_PGD
26672 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26673 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26674 + KERNEL_PGD_PTRS);
26675 +#endif
26676 +
26677 /* clear_bss() already clear the empty_zero_page */
26678
26679 reservedpages = 0;
26680 @@ -854,8 +874,8 @@ int kern_addr_valid(unsigned long addr)
26681 static struct vm_area_struct gate_vma = {
26682 .vm_start = VSYSCALL_START,
26683 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26684 - .vm_page_prot = PAGE_READONLY_EXEC,
26685 - .vm_flags = VM_READ | VM_EXEC
26686 + .vm_page_prot = PAGE_READONLY,
26687 + .vm_flags = VM_READ
26688 };
26689
26690 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26691 @@ -889,7 +909,7 @@ int in_gate_area_no_mm(unsigned long addr)
26692
26693 const char *arch_vma_name(struct vm_area_struct *vma)
26694 {
26695 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26696 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26697 return "[vdso]";
26698 if (vma == &gate_vma)
26699 return "[vsyscall]";
26700 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26701 index 7b179b4..6bd1777 100644
26702 --- a/arch/x86/mm/iomap_32.c
26703 +++ b/arch/x86/mm/iomap_32.c
26704 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26705 type = kmap_atomic_idx_push();
26706 idx = type + KM_TYPE_NR * smp_processor_id();
26707 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26708 +
26709 + pax_open_kernel();
26710 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26711 + pax_close_kernel();
26712 +
26713 arch_flush_lazy_mmu_mode();
26714
26715 return (void *)vaddr;
26716 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26717 index 78fe3f1..2f9433c 100644
26718 --- a/arch/x86/mm/ioremap.c
26719 +++ b/arch/x86/mm/ioremap.c
26720 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26721 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26722 int is_ram = page_is_ram(pfn);
26723
26724 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26725 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26726 return NULL;
26727 WARN_ON_ONCE(is_ram);
26728 }
26729 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26730 *
26731 * Caller must ensure there is only one unmapping for the same pointer.
26732 */
26733 -void iounmap(volatile void __iomem *addr)
26734 +void iounmap(const volatile void __iomem *addr)
26735 {
26736 struct vm_struct *p, *o;
26737
26738 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26739
26740 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26741 if (page_is_ram(start >> PAGE_SHIFT))
26742 +#ifdef CONFIG_HIGHMEM
26743 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26744 +#endif
26745 return __va(phys);
26746
26747 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26748 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26749 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26750
26751 static __initdata int after_paging_init;
26752 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26753 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26754
26755 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26756 {
26757 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26758 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26759
26760 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26761 - memset(bm_pte, 0, sizeof(bm_pte));
26762 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26763 + pmd_populate_user(&init_mm, pmd, bm_pte);
26764
26765 /*
26766 * The boot-ioremap range spans multiple pmds, for which
26767 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26768 index d87dd6d..bf3fa66 100644
26769 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26770 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26771 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26772 * memory (e.g. tracked pages)? For now, we need this to avoid
26773 * invoking kmemcheck for PnP BIOS calls.
26774 */
26775 - if (regs->flags & X86_VM_MASK)
26776 + if (v8086_mode(regs))
26777 return false;
26778 - if (regs->cs != __KERNEL_CS)
26779 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26780 return false;
26781
26782 pte = kmemcheck_pte_lookup(address);
26783 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26784 index 845df68..1d8d29f 100644
26785 --- a/arch/x86/mm/mmap.c
26786 +++ b/arch/x86/mm/mmap.c
26787 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26788 * Leave an at least ~128 MB hole with possible stack randomization.
26789 */
26790 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26791 -#define MAX_GAP (TASK_SIZE/6*5)
26792 +#define MAX_GAP (pax_task_size/6*5)
26793
26794 static int mmap_is_legacy(void)
26795 {
26796 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26797 return rnd << PAGE_SHIFT;
26798 }
26799
26800 -static unsigned long mmap_base(void)
26801 +static unsigned long mmap_base(struct mm_struct *mm)
26802 {
26803 unsigned long gap = rlimit(RLIMIT_STACK);
26804 + unsigned long pax_task_size = TASK_SIZE;
26805 +
26806 +#ifdef CONFIG_PAX_SEGMEXEC
26807 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26808 + pax_task_size = SEGMEXEC_TASK_SIZE;
26809 +#endif
26810
26811 if (gap < MIN_GAP)
26812 gap = MIN_GAP;
26813 else if (gap > MAX_GAP)
26814 gap = MAX_GAP;
26815
26816 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26817 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26818 }
26819
26820 /*
26821 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26822 * does, but not when emulating X86_32
26823 */
26824 -static unsigned long mmap_legacy_base(void)
26825 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26826 {
26827 - if (mmap_is_ia32())
26828 + if (mmap_is_ia32()) {
26829 +
26830 +#ifdef CONFIG_PAX_SEGMEXEC
26831 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26832 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26833 + else
26834 +#endif
26835 +
26836 return TASK_UNMAPPED_BASE;
26837 - else
26838 + } else
26839 return TASK_UNMAPPED_BASE + mmap_rnd();
26840 }
26841
26842 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26843 void arch_pick_mmap_layout(struct mm_struct *mm)
26844 {
26845 if (mmap_is_legacy()) {
26846 - mm->mmap_base = mmap_legacy_base();
26847 + mm->mmap_base = mmap_legacy_base(mm);
26848 +
26849 +#ifdef CONFIG_PAX_RANDMMAP
26850 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26851 + mm->mmap_base += mm->delta_mmap;
26852 +#endif
26853 +
26854 mm->get_unmapped_area = arch_get_unmapped_area;
26855 mm->unmap_area = arch_unmap_area;
26856 } else {
26857 - mm->mmap_base = mmap_base();
26858 + mm->mmap_base = mmap_base(mm);
26859 +
26860 +#ifdef CONFIG_PAX_RANDMMAP
26861 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26862 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26863 +#endif
26864 +
26865 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26866 mm->unmap_area = arch_unmap_area_topdown;
26867 }
26868 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26869 index dc0b727..f612039 100644
26870 --- a/arch/x86/mm/mmio-mod.c
26871 +++ b/arch/x86/mm/mmio-mod.c
26872 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26873 break;
26874 default:
26875 {
26876 - unsigned char *ip = (unsigned char *)instptr;
26877 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26878 my_trace->opcode = MMIO_UNKNOWN_OP;
26879 my_trace->width = 0;
26880 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26881 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26882 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26883 void __iomem *addr)
26884 {
26885 - static atomic_t next_id;
26886 + static atomic_unchecked_t next_id;
26887 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26888 /* These are page-unaligned. */
26889 struct mmiotrace_map map = {
26890 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26891 .private = trace
26892 },
26893 .phys = offset,
26894 - .id = atomic_inc_return(&next_id)
26895 + .id = atomic_inc_return_unchecked(&next_id)
26896 };
26897 map.map_id = trace->id;
26898
26899 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26900 ioremap_trace_core(offset, size, addr);
26901 }
26902
26903 -static void iounmap_trace_core(volatile void __iomem *addr)
26904 +static void iounmap_trace_core(const volatile void __iomem *addr)
26905 {
26906 struct mmiotrace_map map = {
26907 .phys = 0,
26908 @@ -328,7 +328,7 @@ not_enabled:
26909 }
26910 }
26911
26912 -void mmiotrace_iounmap(volatile void __iomem *addr)
26913 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26914 {
26915 might_sleep();
26916 if (is_enabled()) /* recheck and proper locking in *_core() */
26917 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26918 index b008656..773eac2 100644
26919 --- a/arch/x86/mm/pageattr-test.c
26920 +++ b/arch/x86/mm/pageattr-test.c
26921 @@ -36,7 +36,7 @@ enum {
26922
26923 static int pte_testbit(pte_t pte)
26924 {
26925 - return pte_flags(pte) & _PAGE_UNUSED1;
26926 + return pte_flags(pte) & _PAGE_CPA_TEST;
26927 }
26928
26929 struct split_state {
26930 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26931 index a718e0d..77419bc 100644
26932 --- a/arch/x86/mm/pageattr.c
26933 +++ b/arch/x86/mm/pageattr.c
26934 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26935 */
26936 #ifdef CONFIG_PCI_BIOS
26937 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26938 - pgprot_val(forbidden) |= _PAGE_NX;
26939 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26940 #endif
26941
26942 /*
26943 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26944 * Does not cover __inittext since that is gone later on. On
26945 * 64bit we do not enforce !NX on the low mapping
26946 */
26947 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
26948 - pgprot_val(forbidden) |= _PAGE_NX;
26949 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26950 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26951
26952 +#ifdef CONFIG_DEBUG_RODATA
26953 /*
26954 * The .rodata section needs to be read-only. Using the pfn
26955 * catches all aliases.
26956 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26957 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26958 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26959 pgprot_val(forbidden) |= _PAGE_RW;
26960 +#endif
26961
26962 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26963 /*
26964 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26965 }
26966 #endif
26967
26968 +#ifdef CONFIG_PAX_KERNEXEC
26969 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
26970 + pgprot_val(forbidden) |= _PAGE_RW;
26971 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26972 + }
26973 +#endif
26974 +
26975 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
26976
26977 return prot;
26978 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
26979 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
26980 {
26981 /* change init_mm */
26982 + pax_open_kernel();
26983 set_pte_atomic(kpte, pte);
26984 +
26985 #ifdef CONFIG_X86_32
26986 if (!SHARED_KERNEL_PMD) {
26987 +
26988 +#ifdef CONFIG_PAX_PER_CPU_PGD
26989 + unsigned long cpu;
26990 +#else
26991 struct page *page;
26992 +#endif
26993
26994 +#ifdef CONFIG_PAX_PER_CPU_PGD
26995 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26996 + pgd_t *pgd = get_cpu_pgd(cpu);
26997 +#else
26998 list_for_each_entry(page, &pgd_list, lru) {
26999 - pgd_t *pgd;
27000 + pgd_t *pgd = (pgd_t *)page_address(page);
27001 +#endif
27002 +
27003 pud_t *pud;
27004 pmd_t *pmd;
27005
27006 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
27007 + pgd += pgd_index(address);
27008 pud = pud_offset(pgd, address);
27009 pmd = pmd_offset(pud, address);
27010 set_pte_atomic((pte_t *)pmd, pte);
27011 }
27012 }
27013 #endif
27014 + pax_close_kernel();
27015 }
27016
27017 static int
27018 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27019 index 0eb572e..92f5c1e 100644
27020 --- a/arch/x86/mm/pat.c
27021 +++ b/arch/x86/mm/pat.c
27022 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27023
27024 if (!entry) {
27025 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27026 - current->comm, current->pid, start, end - 1);
27027 + current->comm, task_pid_nr(current), start, end - 1);
27028 return -EINVAL;
27029 }
27030
27031 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27032
27033 while (cursor < to) {
27034 if (!devmem_is_allowed(pfn)) {
27035 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27036 - current->comm, from, to - 1);
27037 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27038 + current->comm, from, to - 1, cursor);
27039 return 0;
27040 }
27041 cursor += PAGE_SIZE;
27042 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27043 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27044 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27045 "for [mem %#010Lx-%#010Lx]\n",
27046 - current->comm, current->pid,
27047 + current->comm, task_pid_nr(current),
27048 cattr_name(flags),
27049 base, (unsigned long long)(base + size-1));
27050 return -EINVAL;
27051 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27052 flags = lookup_memtype(paddr);
27053 if (want_flags != flags) {
27054 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27055 - current->comm, current->pid,
27056 + current->comm, task_pid_nr(current),
27057 cattr_name(want_flags),
27058 (unsigned long long)paddr,
27059 (unsigned long long)(paddr + size - 1),
27060 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27061 free_memtype(paddr, paddr + size);
27062 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27063 " for [mem %#010Lx-%#010Lx], got %s\n",
27064 - current->comm, current->pid,
27065 + current->comm, task_pid_nr(current),
27066 cattr_name(want_flags),
27067 (unsigned long long)paddr,
27068 (unsigned long long)(paddr + size - 1),
27069 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27070 index 9f0614d..92ae64a 100644
27071 --- a/arch/x86/mm/pf_in.c
27072 +++ b/arch/x86/mm/pf_in.c
27073 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27074 int i;
27075 enum reason_type rv = OTHERS;
27076
27077 - p = (unsigned char *)ins_addr;
27078 + p = (unsigned char *)ktla_ktva(ins_addr);
27079 p += skip_prefix(p, &prf);
27080 p += get_opcode(p, &opcode);
27081
27082 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27083 struct prefix_bits prf;
27084 int i;
27085
27086 - p = (unsigned char *)ins_addr;
27087 + p = (unsigned char *)ktla_ktva(ins_addr);
27088 p += skip_prefix(p, &prf);
27089 p += get_opcode(p, &opcode);
27090
27091 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27092 struct prefix_bits prf;
27093 int i;
27094
27095 - p = (unsigned char *)ins_addr;
27096 + p = (unsigned char *)ktla_ktva(ins_addr);
27097 p += skip_prefix(p, &prf);
27098 p += get_opcode(p, &opcode);
27099
27100 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27101 struct prefix_bits prf;
27102 int i;
27103
27104 - p = (unsigned char *)ins_addr;
27105 + p = (unsigned char *)ktla_ktva(ins_addr);
27106 p += skip_prefix(p, &prf);
27107 p += get_opcode(p, &opcode);
27108 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27109 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27110 struct prefix_bits prf;
27111 int i;
27112
27113 - p = (unsigned char *)ins_addr;
27114 + p = (unsigned char *)ktla_ktva(ins_addr);
27115 p += skip_prefix(p, &prf);
27116 p += get_opcode(p, &opcode);
27117 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27118 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27119 index 8573b83..4f3ed7e 100644
27120 --- a/arch/x86/mm/pgtable.c
27121 +++ b/arch/x86/mm/pgtable.c
27122 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27123 list_del(&page->lru);
27124 }
27125
27126 -#define UNSHARED_PTRS_PER_PGD \
27127 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27128 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27129 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27130
27131 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27132 +{
27133 + unsigned int count = USER_PGD_PTRS;
27134
27135 + while (count--)
27136 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27137 +}
27138 +#endif
27139 +
27140 +#ifdef CONFIG_PAX_PER_CPU_PGD
27141 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27142 +{
27143 + unsigned int count = USER_PGD_PTRS;
27144 +
27145 + while (count--) {
27146 + pgd_t pgd;
27147 +
27148 +#ifdef CONFIG_X86_64
27149 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27150 +#else
27151 + pgd = *src++;
27152 +#endif
27153 +
27154 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27155 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27156 +#endif
27157 +
27158 + *dst++ = pgd;
27159 + }
27160 +
27161 +}
27162 +#endif
27163 +
27164 +#ifdef CONFIG_X86_64
27165 +#define pxd_t pud_t
27166 +#define pyd_t pgd_t
27167 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27168 +#define pxd_free(mm, pud) pud_free((mm), (pud))
27169 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27170 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
27171 +#define PYD_SIZE PGDIR_SIZE
27172 +#else
27173 +#define pxd_t pmd_t
27174 +#define pyd_t pud_t
27175 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27176 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
27177 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27178 +#define pyd_offset(mm, address) pud_offset((mm), (address))
27179 +#define PYD_SIZE PUD_SIZE
27180 +#endif
27181 +
27182 +#ifdef CONFIG_PAX_PER_CPU_PGD
27183 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27184 +static inline void pgd_dtor(pgd_t *pgd) {}
27185 +#else
27186 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27187 {
27188 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27189 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27190 pgd_list_del(pgd);
27191 spin_unlock(&pgd_lock);
27192 }
27193 +#endif
27194
27195 /*
27196 * List of all pgd's needed for non-PAE so it can invalidate entries
27197 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27198 * -- wli
27199 */
27200
27201 -#ifdef CONFIG_X86_PAE
27202 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27203 /*
27204 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27205 * updating the top-level pagetable entries to guarantee the
27206 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27207 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27208 * and initialize the kernel pmds here.
27209 */
27210 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27211 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27212
27213 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27214 {
27215 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27216 */
27217 flush_tlb_mm(mm);
27218 }
27219 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27220 +#define PREALLOCATED_PXDS USER_PGD_PTRS
27221 #else /* !CONFIG_X86_PAE */
27222
27223 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27224 -#define PREALLOCATED_PMDS 0
27225 +#define PREALLOCATED_PXDS 0
27226
27227 #endif /* CONFIG_X86_PAE */
27228
27229 -static void free_pmds(pmd_t *pmds[])
27230 +static void free_pxds(pxd_t *pxds[])
27231 {
27232 int i;
27233
27234 - for(i = 0; i < PREALLOCATED_PMDS; i++)
27235 - if (pmds[i])
27236 - free_page((unsigned long)pmds[i]);
27237 + for(i = 0; i < PREALLOCATED_PXDS; i++)
27238 + if (pxds[i])
27239 + free_page((unsigned long)pxds[i]);
27240 }
27241
27242 -static int preallocate_pmds(pmd_t *pmds[])
27243 +static int preallocate_pxds(pxd_t *pxds[])
27244 {
27245 int i;
27246 bool failed = false;
27247
27248 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27249 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27250 - if (pmd == NULL)
27251 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27252 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27253 + if (pxd == NULL)
27254 failed = true;
27255 - pmds[i] = pmd;
27256 + pxds[i] = pxd;
27257 }
27258
27259 if (failed) {
27260 - free_pmds(pmds);
27261 + free_pxds(pxds);
27262 return -ENOMEM;
27263 }
27264
27265 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27266 * preallocate which never got a corresponding vma will need to be
27267 * freed manually.
27268 */
27269 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27270 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27271 {
27272 int i;
27273
27274 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27275 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27276 pgd_t pgd = pgdp[i];
27277
27278 if (pgd_val(pgd) != 0) {
27279 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27280 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27281
27282 - pgdp[i] = native_make_pgd(0);
27283 + set_pgd(pgdp + i, native_make_pgd(0));
27284
27285 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27286 - pmd_free(mm, pmd);
27287 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27288 + pxd_free(mm, pxd);
27289 }
27290 }
27291 }
27292
27293 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27294 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27295 {
27296 - pud_t *pud;
27297 + pyd_t *pyd;
27298 unsigned long addr;
27299 int i;
27300
27301 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27302 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27303 return;
27304
27305 - pud = pud_offset(pgd, 0);
27306 +#ifdef CONFIG_X86_64
27307 + pyd = pyd_offset(mm, 0L);
27308 +#else
27309 + pyd = pyd_offset(pgd, 0L);
27310 +#endif
27311
27312 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27313 - i++, pud++, addr += PUD_SIZE) {
27314 - pmd_t *pmd = pmds[i];
27315 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27316 + i++, pyd++, addr += PYD_SIZE) {
27317 + pxd_t *pxd = pxds[i];
27318
27319 if (i >= KERNEL_PGD_BOUNDARY)
27320 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27321 - sizeof(pmd_t) * PTRS_PER_PMD);
27322 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27323 + sizeof(pxd_t) * PTRS_PER_PMD);
27324
27325 - pud_populate(mm, pud, pmd);
27326 + pyd_populate(mm, pyd, pxd);
27327 }
27328 }
27329
27330 pgd_t *pgd_alloc(struct mm_struct *mm)
27331 {
27332 pgd_t *pgd;
27333 - pmd_t *pmds[PREALLOCATED_PMDS];
27334 + pxd_t *pxds[PREALLOCATED_PXDS];
27335
27336 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27337
27338 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27339
27340 mm->pgd = pgd;
27341
27342 - if (preallocate_pmds(pmds) != 0)
27343 + if (preallocate_pxds(pxds) != 0)
27344 goto out_free_pgd;
27345
27346 if (paravirt_pgd_alloc(mm) != 0)
27347 - goto out_free_pmds;
27348 + goto out_free_pxds;
27349
27350 /*
27351 * Make sure that pre-populating the pmds is atomic with
27352 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27353 spin_lock(&pgd_lock);
27354
27355 pgd_ctor(mm, pgd);
27356 - pgd_prepopulate_pmd(mm, pgd, pmds);
27357 + pgd_prepopulate_pxd(mm, pgd, pxds);
27358
27359 spin_unlock(&pgd_lock);
27360
27361 return pgd;
27362
27363 -out_free_pmds:
27364 - free_pmds(pmds);
27365 +out_free_pxds:
27366 + free_pxds(pxds);
27367 out_free_pgd:
27368 free_page((unsigned long)pgd);
27369 out:
27370 @@ -295,7 +356,7 @@ out:
27371
27372 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27373 {
27374 - pgd_mop_up_pmds(mm, pgd);
27375 + pgd_mop_up_pxds(mm, pgd);
27376 pgd_dtor(pgd);
27377 paravirt_pgd_free(mm, pgd);
27378 free_page((unsigned long)pgd);
27379 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27380 index a69bcb8..19068ab 100644
27381 --- a/arch/x86/mm/pgtable_32.c
27382 +++ b/arch/x86/mm/pgtable_32.c
27383 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27384 return;
27385 }
27386 pte = pte_offset_kernel(pmd, vaddr);
27387 +
27388 + pax_open_kernel();
27389 if (pte_val(pteval))
27390 set_pte_at(&init_mm, vaddr, pte, pteval);
27391 else
27392 pte_clear(&init_mm, vaddr, pte);
27393 + pax_close_kernel();
27394
27395 /*
27396 * It's enough to flush this one mapping.
27397 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27398 index 410531d..0f16030 100644
27399 --- a/arch/x86/mm/setup_nx.c
27400 +++ b/arch/x86/mm/setup_nx.c
27401 @@ -5,8 +5,10 @@
27402 #include <asm/pgtable.h>
27403 #include <asm/proto.h>
27404
27405 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27406 static int disable_nx __cpuinitdata;
27407
27408 +#ifndef CONFIG_PAX_PAGEEXEC
27409 /*
27410 * noexec = on|off
27411 *
27412 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27413 return 0;
27414 }
27415 early_param("noexec", noexec_setup);
27416 +#endif
27417 +
27418 +#endif
27419
27420 void __cpuinit x86_configure_nx(void)
27421 {
27422 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27423 if (cpu_has_nx && !disable_nx)
27424 __supported_pte_mask |= _PAGE_NX;
27425 else
27426 +#endif
27427 __supported_pte_mask &= ~_PAGE_NX;
27428 }
27429
27430 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27431 index 60f926c..a710970 100644
27432 --- a/arch/x86/mm/tlb.c
27433 +++ b/arch/x86/mm/tlb.c
27434 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27435 BUG();
27436 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27437 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27438 +
27439 +#ifndef CONFIG_PAX_PER_CPU_PGD
27440 load_cr3(swapper_pg_dir);
27441 +#endif
27442 +
27443 }
27444 }
27445 EXPORT_SYMBOL_GPL(leave_mm);
27446 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27447 index 877b9a1..a8ecf42 100644
27448 --- a/arch/x86/net/bpf_jit.S
27449 +++ b/arch/x86/net/bpf_jit.S
27450 @@ -9,6 +9,7 @@
27451 */
27452 #include <linux/linkage.h>
27453 #include <asm/dwarf2.h>
27454 +#include <asm/alternative-asm.h>
27455
27456 /*
27457 * Calling convention :
27458 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27459 jle bpf_slow_path_word
27460 mov (SKBDATA,%rsi),%eax
27461 bswap %eax /* ntohl() */
27462 + pax_force_retaddr
27463 ret
27464
27465 sk_load_half:
27466 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27467 jle bpf_slow_path_half
27468 movzwl (SKBDATA,%rsi),%eax
27469 rol $8,%ax # ntohs()
27470 + pax_force_retaddr
27471 ret
27472
27473 sk_load_byte:
27474 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27475 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27476 jle bpf_slow_path_byte
27477 movzbl (SKBDATA,%rsi),%eax
27478 + pax_force_retaddr
27479 ret
27480
27481 /**
27482 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27483 movzbl (SKBDATA,%rsi),%ebx
27484 and $15,%bl
27485 shl $2,%bl
27486 + pax_force_retaddr
27487 ret
27488
27489 /* rsi contains offset and can be scratched */
27490 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27491 js bpf_error
27492 mov -12(%rbp),%eax
27493 bswap %eax
27494 + pax_force_retaddr
27495 ret
27496
27497 bpf_slow_path_half:
27498 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27499 mov -12(%rbp),%ax
27500 rol $8,%ax
27501 movzwl %ax,%eax
27502 + pax_force_retaddr
27503 ret
27504
27505 bpf_slow_path_byte:
27506 bpf_slow_path_common(1)
27507 js bpf_error
27508 movzbl -12(%rbp),%eax
27509 + pax_force_retaddr
27510 ret
27511
27512 bpf_slow_path_byte_msh:
27513 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27514 and $15,%al
27515 shl $2,%al
27516 xchg %eax,%ebx
27517 + pax_force_retaddr
27518 ret
27519
27520 #define sk_negative_common(SIZE) \
27521 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27522 sk_negative_common(4)
27523 mov (%rax), %eax
27524 bswap %eax
27525 + pax_force_retaddr
27526 ret
27527
27528 bpf_slow_path_half_neg:
27529 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27530 mov (%rax),%ax
27531 rol $8,%ax
27532 movzwl %ax,%eax
27533 + pax_force_retaddr
27534 ret
27535
27536 bpf_slow_path_byte_neg:
27537 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27538 .globl sk_load_byte_negative_offset
27539 sk_negative_common(1)
27540 movzbl (%rax), %eax
27541 + pax_force_retaddr
27542 ret
27543
27544 bpf_slow_path_byte_msh_neg:
27545 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27546 and $15,%al
27547 shl $2,%al
27548 xchg %eax,%ebx
27549 + pax_force_retaddr
27550 ret
27551
27552 bpf_error:
27553 @@ -197,4 +210,5 @@ bpf_error:
27554 xor %eax,%eax
27555 mov -8(%rbp),%rbx
27556 leaveq
27557 + pax_force_retaddr
27558 ret
27559 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27560 index 520d2bd..b895ef4 100644
27561 --- a/arch/x86/net/bpf_jit_comp.c
27562 +++ b/arch/x86/net/bpf_jit_comp.c
27563 @@ -11,6 +11,7 @@
27564 #include <asm/cacheflush.h>
27565 #include <linux/netdevice.h>
27566 #include <linux/filter.h>
27567 +#include <linux/random.h>
27568
27569 /*
27570 * Conventions :
27571 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27572 return ptr + len;
27573 }
27574
27575 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27576 +#define MAX_INSTR_CODE_SIZE 96
27577 +#else
27578 +#define MAX_INSTR_CODE_SIZE 64
27579 +#endif
27580 +
27581 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27582
27583 #define EMIT1(b1) EMIT(b1, 1)
27584 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27585 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27586 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27587 +
27588 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27589 +/* original constant will appear in ecx */
27590 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27591 +do { \
27592 + /* mov ecx, randkey */ \
27593 + EMIT1(0xb9); \
27594 + EMIT(_key, 4); \
27595 + /* xor ecx, randkey ^ off */ \
27596 + EMIT2(0x81, 0xf1); \
27597 + EMIT((_key) ^ (_off), 4); \
27598 +} while (0)
27599 +
27600 +#define EMIT1_off32(b1, _off) \
27601 +do { \
27602 + switch (b1) { \
27603 + case 0x05: /* add eax, imm32 */ \
27604 + case 0x2d: /* sub eax, imm32 */ \
27605 + case 0x25: /* and eax, imm32 */ \
27606 + case 0x0d: /* or eax, imm32 */ \
27607 + case 0xb8: /* mov eax, imm32 */ \
27608 + case 0x3d: /* cmp eax, imm32 */ \
27609 + case 0xa9: /* test eax, imm32 */ \
27610 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27611 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27612 + break; \
27613 + case 0xbb: /* mov ebx, imm32 */ \
27614 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27615 + /* mov ebx, ecx */ \
27616 + EMIT2(0x89, 0xcb); \
27617 + break; \
27618 + case 0xbe: /* mov esi, imm32 */ \
27619 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27620 + /* mov esi, ecx */ \
27621 + EMIT2(0x89, 0xce); \
27622 + break; \
27623 + case 0xe9: /* jmp rel imm32 */ \
27624 + EMIT1(b1); \
27625 + EMIT(_off, 4); \
27626 + /* prevent fall-through, we're not called if off = 0 */ \
27627 + EMIT(0xcccccccc, 4); \
27628 + EMIT(0xcccccccc, 4); \
27629 + break; \
27630 + default: \
27631 + EMIT1(b1); \
27632 + EMIT(_off, 4); \
27633 + } \
27634 +} while (0)
27635 +
27636 +#define EMIT2_off32(b1, b2, _off) \
27637 +do { \
27638 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27639 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27640 + EMIT(randkey, 4); \
27641 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27642 + EMIT((_off) - randkey, 4); \
27643 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27644 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27645 + /* imul eax, ecx */ \
27646 + EMIT3(0x0f, 0xaf, 0xc1); \
27647 + } else { \
27648 + EMIT2(b1, b2); \
27649 + EMIT(_off, 4); \
27650 + } \
27651 +} while (0)
27652 +#else
27653 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27654 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27655 +#endif
27656
27657 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27658 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27659 @@ -89,6 +164,24 @@ do { \
27660 #define X86_JBE 0x76
27661 #define X86_JA 0x77
27662
27663 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27664 +#define APPEND_FLOW_VERIFY() \
27665 +do { \
27666 + /* mov ecx, randkey */ \
27667 + EMIT1(0xb9); \
27668 + EMIT(randkey, 4); \
27669 + /* cmp ecx, randkey */ \
27670 + EMIT2(0x81, 0xf9); \
27671 + EMIT(randkey, 4); \
27672 + /* jz after 8 int 3s */ \
27673 + EMIT2(0x74, 0x08); \
27674 + EMIT(0xcccccccc, 4); \
27675 + EMIT(0xcccccccc, 4); \
27676 +} while (0)
27677 +#else
27678 +#define APPEND_FLOW_VERIFY() do { } while (0)
27679 +#endif
27680 +
27681 #define EMIT_COND_JMP(op, offset) \
27682 do { \
27683 if (is_near(offset)) \
27684 @@ -96,6 +189,7 @@ do { \
27685 else { \
27686 EMIT2(0x0f, op + 0x10); \
27687 EMIT(offset, 4); /* jxx .+off32 */ \
27688 + APPEND_FLOW_VERIFY(); \
27689 } \
27690 } while (0)
27691
27692 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27693 set_fs(old_fs);
27694 }
27695
27696 +struct bpf_jit_work {
27697 + struct work_struct work;
27698 + void *image;
27699 +};
27700 +
27701 #define CHOOSE_LOAD_FUNC(K, func) \
27702 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27703
27704 void bpf_jit_compile(struct sk_filter *fp)
27705 {
27706 - u8 temp[64];
27707 + u8 temp[MAX_INSTR_CODE_SIZE];
27708 u8 *prog;
27709 unsigned int proglen, oldproglen = 0;
27710 int ilen, i;
27711 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27712 unsigned int *addrs;
27713 const struct sock_filter *filter = fp->insns;
27714 int flen = fp->len;
27715 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27716 + unsigned int randkey;
27717 +#endif
27718
27719 if (!bpf_jit_enable)
27720 return;
27721 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27722 if (addrs == NULL)
27723 return;
27724
27725 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27726 + if (!fp->work)
27727 + goto out;
27728 +
27729 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27730 + randkey = get_random_int();
27731 +#endif
27732 +
27733 /* Before first pass, make a rough estimation of addrs[]
27734 - * each bpf instruction is translated to less than 64 bytes
27735 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27736 */
27737 for (proglen = 0, i = 0; i < flen; i++) {
27738 - proglen += 64;
27739 + proglen += MAX_INSTR_CODE_SIZE;
27740 addrs[i] = proglen;
27741 }
27742 cleanup_addr = proglen; /* epilogue address */
27743 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27744 case BPF_S_ALU_MUL_K: /* A *= K */
27745 if (is_imm8(K))
27746 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27747 - else {
27748 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27749 - EMIT(K, 4);
27750 - }
27751 + else
27752 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27753 break;
27754 case BPF_S_ALU_DIV_X: /* A /= X; */
27755 seen |= SEEN_XREG;
27756 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27757 break;
27758 case BPF_S_ALU_MOD_K: /* A %= K; */
27759 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27760 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27761 + DILUTE_CONST_SEQUENCE(K, randkey);
27762 +#else
27763 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27764 +#endif
27765 EMIT2(0xf7, 0xf1); /* div %ecx */
27766 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27767 break;
27768 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27769 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27770 + DILUTE_CONST_SEQUENCE(K, randkey);
27771 + // imul rax, rcx
27772 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27773 +#else
27774 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27775 EMIT(K, 4);
27776 +#endif
27777 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27778 break;
27779 case BPF_S_ALU_AND_X:
27780 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27781 if (is_imm8(K)) {
27782 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27783 } else {
27784 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27785 - EMIT(K, 4);
27786 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27787 }
27788 } else {
27789 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27790 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27791 break;
27792 default:
27793 /* hmm, too complex filter, give up with jit compiler */
27794 - goto out;
27795 + goto error;
27796 }
27797 ilen = prog - temp;
27798 if (image) {
27799 if (unlikely(proglen + ilen > oldproglen)) {
27800 pr_err("bpb_jit_compile fatal error\n");
27801 - kfree(addrs);
27802 - module_free(NULL, image);
27803 - return;
27804 + module_free_exec(NULL, image);
27805 + goto error;
27806 }
27807 + pax_open_kernel();
27808 memcpy(image + proglen, temp, ilen);
27809 + pax_close_kernel();
27810 }
27811 proglen += ilen;
27812 addrs[i] = proglen;
27813 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27814 break;
27815 }
27816 if (proglen == oldproglen) {
27817 - image = module_alloc(max_t(unsigned int,
27818 - proglen,
27819 - sizeof(struct work_struct)));
27820 + image = module_alloc_exec(proglen);
27821 if (!image)
27822 - goto out;
27823 + goto error;
27824 }
27825 oldproglen = proglen;
27826 }
27827 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27828 bpf_flush_icache(image, image + proglen);
27829
27830 fp->bpf_func = (void *)image;
27831 - }
27832 + } else
27833 +error:
27834 + kfree(fp->work);
27835 +
27836 out:
27837 kfree(addrs);
27838 return;
27839 @@ -686,18 +805,20 @@ out:
27840
27841 static void jit_free_defer(struct work_struct *arg)
27842 {
27843 - module_free(NULL, arg);
27844 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27845 + kfree(arg);
27846 }
27847
27848 /* run from softirq, we must use a work_struct to call
27849 - * module_free() from process context
27850 + * module_free_exec() from process context
27851 */
27852 void bpf_jit_free(struct sk_filter *fp)
27853 {
27854 if (fp->bpf_func != sk_run_filter) {
27855 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27856 + struct work_struct *work = &fp->work->work;
27857
27858 INIT_WORK(work, jit_free_defer);
27859 + fp->work->image = fp->bpf_func;
27860 schedule_work(work);
27861 }
27862 }
27863 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27864 index d6aa6e8..266395a 100644
27865 --- a/arch/x86/oprofile/backtrace.c
27866 +++ b/arch/x86/oprofile/backtrace.c
27867 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27868 struct stack_frame_ia32 *fp;
27869 unsigned long bytes;
27870
27871 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27872 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27873 if (bytes != sizeof(bufhead))
27874 return NULL;
27875
27876 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27877 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27878
27879 oprofile_add_trace(bufhead[0].return_address);
27880
27881 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27882 struct stack_frame bufhead[2];
27883 unsigned long bytes;
27884
27885 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27886 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27887 if (bytes != sizeof(bufhead))
27888 return NULL;
27889
27890 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27891 {
27892 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27893
27894 - if (!user_mode_vm(regs)) {
27895 + if (!user_mode(regs)) {
27896 unsigned long stack = kernel_stack_pointer(regs);
27897 if (depth)
27898 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27899 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27900 index e14a2ff..3fd6b58 100644
27901 --- a/arch/x86/pci/mrst.c
27902 +++ b/arch/x86/pci/mrst.c
27903 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27904 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27905 pci_mmcfg_late_init();
27906 pcibios_enable_irq = mrst_pci_irq_enable;
27907 - pci_root_ops = pci_mrst_ops;
27908 + pax_open_kernel();
27909 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27910 + pax_close_kernel();
27911 pci_soc_mode = 1;
27912 /* Continue with standard init */
27913 return 1;
27914 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27915 index da8fe05..7ee6704 100644
27916 --- a/arch/x86/pci/pcbios.c
27917 +++ b/arch/x86/pci/pcbios.c
27918 @@ -79,50 +79,93 @@ union bios32 {
27919 static struct {
27920 unsigned long address;
27921 unsigned short segment;
27922 -} bios32_indirect = { 0, __KERNEL_CS };
27923 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27924
27925 /*
27926 * Returns the entry point for the given service, NULL on error
27927 */
27928
27929 -static unsigned long bios32_service(unsigned long service)
27930 +static unsigned long __devinit bios32_service(unsigned long service)
27931 {
27932 unsigned char return_code; /* %al */
27933 unsigned long address; /* %ebx */
27934 unsigned long length; /* %ecx */
27935 unsigned long entry; /* %edx */
27936 unsigned long flags;
27937 + struct desc_struct d, *gdt;
27938
27939 local_irq_save(flags);
27940 - __asm__("lcall *(%%edi); cld"
27941 +
27942 + gdt = get_cpu_gdt_table(smp_processor_id());
27943 +
27944 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27945 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27946 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27947 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27948 +
27949 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27950 : "=a" (return_code),
27951 "=b" (address),
27952 "=c" (length),
27953 "=d" (entry)
27954 : "0" (service),
27955 "1" (0),
27956 - "D" (&bios32_indirect));
27957 + "D" (&bios32_indirect),
27958 + "r"(__PCIBIOS_DS)
27959 + : "memory");
27960 +
27961 + pax_open_kernel();
27962 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
27963 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
27964 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
27965 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
27966 + pax_close_kernel();
27967 +
27968 local_irq_restore(flags);
27969
27970 switch (return_code) {
27971 - case 0:
27972 - return address + entry;
27973 - case 0x80: /* Not present */
27974 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27975 - return 0;
27976 - default: /* Shouldn't happen */
27977 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27978 - service, return_code);
27979 + case 0: {
27980 + int cpu;
27981 + unsigned char flags;
27982 +
27983 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
27984 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
27985 + printk(KERN_WARNING "bios32_service: not valid\n");
27986 return 0;
27987 + }
27988 + address = address + PAGE_OFFSET;
27989 + length += 16UL; /* some BIOSs underreport this... */
27990 + flags = 4;
27991 + if (length >= 64*1024*1024) {
27992 + length >>= PAGE_SHIFT;
27993 + flags |= 8;
27994 + }
27995 +
27996 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27997 + gdt = get_cpu_gdt_table(cpu);
27998 + pack_descriptor(&d, address, length, 0x9b, flags);
27999 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28000 + pack_descriptor(&d, address, length, 0x93, flags);
28001 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28002 + }
28003 + return entry;
28004 + }
28005 + case 0x80: /* Not present */
28006 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28007 + return 0;
28008 + default: /* Shouldn't happen */
28009 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28010 + service, return_code);
28011 + return 0;
28012 }
28013 }
28014
28015 static struct {
28016 unsigned long address;
28017 unsigned short segment;
28018 -} pci_indirect = { 0, __KERNEL_CS };
28019 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28020
28021 -static int pci_bios_present;
28022 +static int pci_bios_present __read_only;
28023
28024 static int __devinit check_pcibios(void)
28025 {
28026 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28027 unsigned long flags, pcibios_entry;
28028
28029 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28030 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28031 + pci_indirect.address = pcibios_entry;
28032
28033 local_irq_save(flags);
28034 - __asm__(
28035 - "lcall *(%%edi); cld\n\t"
28036 + __asm__("movw %w6, %%ds\n\t"
28037 + "lcall *%%ss:(%%edi); cld\n\t"
28038 + "push %%ss\n\t"
28039 + "pop %%ds\n\t"
28040 "jc 1f\n\t"
28041 "xor %%ah, %%ah\n"
28042 "1:"
28043 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28044 "=b" (ebx),
28045 "=c" (ecx)
28046 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28047 - "D" (&pci_indirect)
28048 + "D" (&pci_indirect),
28049 + "r" (__PCIBIOS_DS)
28050 : "memory");
28051 local_irq_restore(flags);
28052
28053 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28054
28055 switch (len) {
28056 case 1:
28057 - __asm__("lcall *(%%esi); cld\n\t"
28058 + __asm__("movw %w6, %%ds\n\t"
28059 + "lcall *%%ss:(%%esi); cld\n\t"
28060 + "push %%ss\n\t"
28061 + "pop %%ds\n\t"
28062 "jc 1f\n\t"
28063 "xor %%ah, %%ah\n"
28064 "1:"
28065 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28066 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28067 "b" (bx),
28068 "D" ((long)reg),
28069 - "S" (&pci_indirect));
28070 + "S" (&pci_indirect),
28071 + "r" (__PCIBIOS_DS));
28072 /*
28073 * Zero-extend the result beyond 8 bits, do not trust the
28074 * BIOS having done it:
28075 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28076 *value &= 0xff;
28077 break;
28078 case 2:
28079 - __asm__("lcall *(%%esi); cld\n\t"
28080 + __asm__("movw %w6, %%ds\n\t"
28081 + "lcall *%%ss:(%%esi); cld\n\t"
28082 + "push %%ss\n\t"
28083 + "pop %%ds\n\t"
28084 "jc 1f\n\t"
28085 "xor %%ah, %%ah\n"
28086 "1:"
28087 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28088 : "1" (PCIBIOS_READ_CONFIG_WORD),
28089 "b" (bx),
28090 "D" ((long)reg),
28091 - "S" (&pci_indirect));
28092 + "S" (&pci_indirect),
28093 + "r" (__PCIBIOS_DS));
28094 /*
28095 * Zero-extend the result beyond 16 bits, do not trust the
28096 * BIOS having done it:
28097 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28098 *value &= 0xffff;
28099 break;
28100 case 4:
28101 - __asm__("lcall *(%%esi); cld\n\t"
28102 + __asm__("movw %w6, %%ds\n\t"
28103 + "lcall *%%ss:(%%esi); cld\n\t"
28104 + "push %%ss\n\t"
28105 + "pop %%ds\n\t"
28106 "jc 1f\n\t"
28107 "xor %%ah, %%ah\n"
28108 "1:"
28109 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28110 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28111 "b" (bx),
28112 "D" ((long)reg),
28113 - "S" (&pci_indirect));
28114 + "S" (&pci_indirect),
28115 + "r" (__PCIBIOS_DS));
28116 break;
28117 }
28118
28119 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28120
28121 switch (len) {
28122 case 1:
28123 - __asm__("lcall *(%%esi); cld\n\t"
28124 + __asm__("movw %w6, %%ds\n\t"
28125 + "lcall *%%ss:(%%esi); cld\n\t"
28126 + "push %%ss\n\t"
28127 + "pop %%ds\n\t"
28128 "jc 1f\n\t"
28129 "xor %%ah, %%ah\n"
28130 "1:"
28131 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28132 "c" (value),
28133 "b" (bx),
28134 "D" ((long)reg),
28135 - "S" (&pci_indirect));
28136 + "S" (&pci_indirect),
28137 + "r" (__PCIBIOS_DS));
28138 break;
28139 case 2:
28140 - __asm__("lcall *(%%esi); cld\n\t"
28141 + __asm__("movw %w6, %%ds\n\t"
28142 + "lcall *%%ss:(%%esi); cld\n\t"
28143 + "push %%ss\n\t"
28144 + "pop %%ds\n\t"
28145 "jc 1f\n\t"
28146 "xor %%ah, %%ah\n"
28147 "1:"
28148 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28149 "c" (value),
28150 "b" (bx),
28151 "D" ((long)reg),
28152 - "S" (&pci_indirect));
28153 + "S" (&pci_indirect),
28154 + "r" (__PCIBIOS_DS));
28155 break;
28156 case 4:
28157 - __asm__("lcall *(%%esi); cld\n\t"
28158 + __asm__("movw %w6, %%ds\n\t"
28159 + "lcall *%%ss:(%%esi); cld\n\t"
28160 + "push %%ss\n\t"
28161 + "pop %%ds\n\t"
28162 "jc 1f\n\t"
28163 "xor %%ah, %%ah\n"
28164 "1:"
28165 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28166 "c" (value),
28167 "b" (bx),
28168 "D" ((long)reg),
28169 - "S" (&pci_indirect));
28170 + "S" (&pci_indirect),
28171 + "r" (__PCIBIOS_DS));
28172 break;
28173 }
28174
28175 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28176
28177 DBG("PCI: Fetching IRQ routing table... ");
28178 __asm__("push %%es\n\t"
28179 + "movw %w8, %%ds\n\t"
28180 "push %%ds\n\t"
28181 "pop %%es\n\t"
28182 - "lcall *(%%esi); cld\n\t"
28183 + "lcall *%%ss:(%%esi); cld\n\t"
28184 "pop %%es\n\t"
28185 + "push %%ss\n\t"
28186 + "pop %%ds\n"
28187 "jc 1f\n\t"
28188 "xor %%ah, %%ah\n"
28189 "1:"
28190 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28191 "1" (0),
28192 "D" ((long) &opt),
28193 "S" (&pci_indirect),
28194 - "m" (opt)
28195 + "m" (opt),
28196 + "r" (__PCIBIOS_DS)
28197 : "memory");
28198 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28199 if (ret & 0xff00)
28200 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28201 {
28202 int ret;
28203
28204 - __asm__("lcall *(%%esi); cld\n\t"
28205 + __asm__("movw %w5, %%ds\n\t"
28206 + "lcall *%%ss:(%%esi); cld\n\t"
28207 + "push %%ss\n\t"
28208 + "pop %%ds\n"
28209 "jc 1f\n\t"
28210 "xor %%ah, %%ah\n"
28211 "1:"
28212 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28213 : "0" (PCIBIOS_SET_PCI_HW_INT),
28214 "b" ((dev->bus->number << 8) | dev->devfn),
28215 "c" ((irq << 8) | (pin + 10)),
28216 - "S" (&pci_indirect));
28217 + "S" (&pci_indirect),
28218 + "r" (__PCIBIOS_DS));
28219 return !(ret & 0xff00);
28220 }
28221 EXPORT_SYMBOL(pcibios_set_irq_routing);
28222 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28223 index 40e4469..1ab536e 100644
28224 --- a/arch/x86/platform/efi/efi_32.c
28225 +++ b/arch/x86/platform/efi/efi_32.c
28226 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28227 {
28228 struct desc_ptr gdt_descr;
28229
28230 +#ifdef CONFIG_PAX_KERNEXEC
28231 + struct desc_struct d;
28232 +#endif
28233 +
28234 local_irq_save(efi_rt_eflags);
28235
28236 load_cr3(initial_page_table);
28237 __flush_tlb_all();
28238
28239 +#ifdef CONFIG_PAX_KERNEXEC
28240 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28241 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28242 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28243 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28244 +#endif
28245 +
28246 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28247 gdt_descr.size = GDT_SIZE - 1;
28248 load_gdt(&gdt_descr);
28249 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28250 {
28251 struct desc_ptr gdt_descr;
28252
28253 +#ifdef CONFIG_PAX_KERNEXEC
28254 + struct desc_struct d;
28255 +
28256 + memset(&d, 0, sizeof d);
28257 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28258 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28259 +#endif
28260 +
28261 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28262 gdt_descr.size = GDT_SIZE - 1;
28263 load_gdt(&gdt_descr);
28264 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28265 index fbe66e6..eae5e38 100644
28266 --- a/arch/x86/platform/efi/efi_stub_32.S
28267 +++ b/arch/x86/platform/efi/efi_stub_32.S
28268 @@ -6,7 +6,9 @@
28269 */
28270
28271 #include <linux/linkage.h>
28272 +#include <linux/init.h>
28273 #include <asm/page_types.h>
28274 +#include <asm/segment.h>
28275
28276 /*
28277 * efi_call_phys(void *, ...) is a function with variable parameters.
28278 @@ -20,7 +22,7 @@
28279 * service functions will comply with gcc calling convention, too.
28280 */
28281
28282 -.text
28283 +__INIT
28284 ENTRY(efi_call_phys)
28285 /*
28286 * 0. The function can only be called in Linux kernel. So CS has been
28287 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28288 * The mapping of lower virtual memory has been created in prelog and
28289 * epilog.
28290 */
28291 - movl $1f, %edx
28292 - subl $__PAGE_OFFSET, %edx
28293 - jmp *%edx
28294 +#ifdef CONFIG_PAX_KERNEXEC
28295 + movl $(__KERNEXEC_EFI_DS), %edx
28296 + mov %edx, %ds
28297 + mov %edx, %es
28298 + mov %edx, %ss
28299 + addl $2f,(1f)
28300 + ljmp *(1f)
28301 +
28302 +__INITDATA
28303 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28304 +.previous
28305 +
28306 +2:
28307 + subl $2b,(1b)
28308 +#else
28309 + jmp 1f-__PAGE_OFFSET
28310 1:
28311 +#endif
28312
28313 /*
28314 * 2. Now on the top of stack is the return
28315 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28316 * parameter 2, ..., param n. To make things easy, we save the return
28317 * address of efi_call_phys in a global variable.
28318 */
28319 - popl %edx
28320 - movl %edx, saved_return_addr
28321 - /* get the function pointer into ECX*/
28322 - popl %ecx
28323 - movl %ecx, efi_rt_function_ptr
28324 - movl $2f, %edx
28325 - subl $__PAGE_OFFSET, %edx
28326 - pushl %edx
28327 + popl (saved_return_addr)
28328 + popl (efi_rt_function_ptr)
28329
28330 /*
28331 * 3. Clear PG bit in %CR0.
28332 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28333 /*
28334 * 5. Call the physical function.
28335 */
28336 - jmp *%ecx
28337 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28338
28339 -2:
28340 /*
28341 * 6. After EFI runtime service returns, control will return to
28342 * following instruction. We'd better readjust stack pointer first.
28343 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28344 movl %cr0, %edx
28345 orl $0x80000000, %edx
28346 movl %edx, %cr0
28347 - jmp 1f
28348 -1:
28349 +
28350 /*
28351 * 8. Now restore the virtual mode from flat mode by
28352 * adding EIP with PAGE_OFFSET.
28353 */
28354 - movl $1f, %edx
28355 - jmp *%edx
28356 +#ifdef CONFIG_PAX_KERNEXEC
28357 + movl $(__KERNEL_DS), %edx
28358 + mov %edx, %ds
28359 + mov %edx, %es
28360 + mov %edx, %ss
28361 + ljmp $(__KERNEL_CS),$1f
28362 +#else
28363 + jmp 1f+__PAGE_OFFSET
28364 +#endif
28365 1:
28366
28367 /*
28368 * 9. Balance the stack. And because EAX contain the return value,
28369 * we'd better not clobber it.
28370 */
28371 - leal efi_rt_function_ptr, %edx
28372 - movl (%edx), %ecx
28373 - pushl %ecx
28374 + pushl (efi_rt_function_ptr)
28375
28376 /*
28377 - * 10. Push the saved return address onto the stack and return.
28378 + * 10. Return to the saved return address.
28379 */
28380 - leal saved_return_addr, %edx
28381 - movl (%edx), %ecx
28382 - pushl %ecx
28383 - ret
28384 + jmpl *(saved_return_addr)
28385 ENDPROC(efi_call_phys)
28386 .previous
28387
28388 -.data
28389 +__INITDATA
28390 saved_return_addr:
28391 .long 0
28392 efi_rt_function_ptr:
28393 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28394 index 4c07cca..2c8427d 100644
28395 --- a/arch/x86/platform/efi/efi_stub_64.S
28396 +++ b/arch/x86/platform/efi/efi_stub_64.S
28397 @@ -7,6 +7,7 @@
28398 */
28399
28400 #include <linux/linkage.h>
28401 +#include <asm/alternative-asm.h>
28402
28403 #define SAVE_XMM \
28404 mov %rsp, %rax; \
28405 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28406 call *%rdi
28407 addq $32, %rsp
28408 RESTORE_XMM
28409 + pax_force_retaddr 0, 1
28410 ret
28411 ENDPROC(efi_call0)
28412
28413 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28414 call *%rdi
28415 addq $32, %rsp
28416 RESTORE_XMM
28417 + pax_force_retaddr 0, 1
28418 ret
28419 ENDPROC(efi_call1)
28420
28421 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28422 call *%rdi
28423 addq $32, %rsp
28424 RESTORE_XMM
28425 + pax_force_retaddr 0, 1
28426 ret
28427 ENDPROC(efi_call2)
28428
28429 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28430 call *%rdi
28431 addq $32, %rsp
28432 RESTORE_XMM
28433 + pax_force_retaddr 0, 1
28434 ret
28435 ENDPROC(efi_call3)
28436
28437 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28438 call *%rdi
28439 addq $32, %rsp
28440 RESTORE_XMM
28441 + pax_force_retaddr 0, 1
28442 ret
28443 ENDPROC(efi_call4)
28444
28445 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28446 call *%rdi
28447 addq $48, %rsp
28448 RESTORE_XMM
28449 + pax_force_retaddr 0, 1
28450 ret
28451 ENDPROC(efi_call5)
28452
28453 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28454 call *%rdi
28455 addq $48, %rsp
28456 RESTORE_XMM
28457 + pax_force_retaddr 0, 1
28458 ret
28459 ENDPROC(efi_call6)
28460 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28461 index fd41a92..9c33628 100644
28462 --- a/arch/x86/platform/mrst/mrst.c
28463 +++ b/arch/x86/platform/mrst/mrst.c
28464 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28465 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28466 int sfi_mrtc_num;
28467
28468 -static void mrst_power_off(void)
28469 +static __noreturn void mrst_power_off(void)
28470 {
28471 + BUG();
28472 }
28473
28474 -static void mrst_reboot(void)
28475 +static __noreturn void mrst_reboot(void)
28476 {
28477 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28478 + BUG();
28479 }
28480
28481 /* parse all the mtimer info to a static mtimer array */
28482 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28483 index d6ee929..3637cb5 100644
28484 --- a/arch/x86/platform/olpc/olpc_dt.c
28485 +++ b/arch/x86/platform/olpc/olpc_dt.c
28486 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28487 return res;
28488 }
28489
28490 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28491 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28492 .nextprop = olpc_dt_nextprop,
28493 .getproplen = olpc_dt_getproplen,
28494 .getproperty = olpc_dt_getproperty,
28495 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28496 index 218cdb1..c1178eb 100644
28497 --- a/arch/x86/power/cpu.c
28498 +++ b/arch/x86/power/cpu.c
28499 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28500 static void fix_processor_context(void)
28501 {
28502 int cpu = smp_processor_id();
28503 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28504 + struct tss_struct *t = init_tss + cpu;
28505
28506 set_tss_desc(cpu, t); /*
28507 * This just modifies memory; should not be
28508 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28509 */
28510
28511 #ifdef CONFIG_X86_64
28512 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28513 -
28514 syscall_init(); /* This sets MSR_*STAR and related */
28515 #endif
28516 load_TR_desc(); /* This does ltr */
28517 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28518 index cbca565..bae7133 100644
28519 --- a/arch/x86/realmode/init.c
28520 +++ b/arch/x86/realmode/init.c
28521 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28522 __va(real_mode_header->trampoline_header);
28523
28524 #ifdef CONFIG_X86_32
28525 - trampoline_header->start = __pa(startup_32_smp);
28526 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28527 +
28528 +#ifdef CONFIG_PAX_KERNEXEC
28529 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28530 +#endif
28531 +
28532 + trampoline_header->boot_cs = __BOOT_CS;
28533 trampoline_header->gdt_limit = __BOOT_DS + 7;
28534 trampoline_header->gdt_base = __pa(boot_gdt);
28535 #else
28536 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28537 index 8869287..d577672 100644
28538 --- a/arch/x86/realmode/rm/Makefile
28539 +++ b/arch/x86/realmode/rm/Makefile
28540 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28541 $(call cc-option, -fno-unit-at-a-time)) \
28542 $(call cc-option, -fno-stack-protector) \
28543 $(call cc-option, -mpreferred-stack-boundary=2)
28544 +ifdef CONSTIFY_PLUGIN
28545 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28546 +endif
28547 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28548 GCOV_PROFILE := n
28549 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28550 index a28221d..93c40f1 100644
28551 --- a/arch/x86/realmode/rm/header.S
28552 +++ b/arch/x86/realmode/rm/header.S
28553 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28554 #endif
28555 /* APM/BIOS reboot */
28556 .long pa_machine_real_restart_asm
28557 -#ifdef CONFIG_X86_64
28558 +#ifdef CONFIG_X86_32
28559 + .long __KERNEL_CS
28560 +#else
28561 .long __KERNEL32_CS
28562 #endif
28563 END(real_mode_header)
28564 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28565 index c1b2791..f9e31c7 100644
28566 --- a/arch/x86/realmode/rm/trampoline_32.S
28567 +++ b/arch/x86/realmode/rm/trampoline_32.S
28568 @@ -25,6 +25,12 @@
28569 #include <asm/page_types.h>
28570 #include "realmode.h"
28571
28572 +#ifdef CONFIG_PAX_KERNEXEC
28573 +#define ta(X) (X)
28574 +#else
28575 +#define ta(X) (pa_ ## X)
28576 +#endif
28577 +
28578 .text
28579 .code16
28580
28581 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28582
28583 cli # We should be safe anyway
28584
28585 - movl tr_start, %eax # where we need to go
28586 -
28587 movl $0xA5A5A5A5, trampoline_status
28588 # write marker for master knows we're running
28589
28590 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28591 movw $1, %dx # protected mode (PE) bit
28592 lmsw %dx # into protected mode
28593
28594 - ljmpl $__BOOT_CS, $pa_startup_32
28595 + ljmpl *(trampoline_header)
28596
28597 .section ".text32","ax"
28598 .code32
28599 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28600 .balign 8
28601 GLOBAL(trampoline_header)
28602 tr_start: .space 4
28603 - tr_gdt_pad: .space 2
28604 + tr_boot_cs: .space 2
28605 tr_gdt: .space 6
28606 END(trampoline_header)
28607
28608 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28609 index bb360dc..3e5945f 100644
28610 --- a/arch/x86/realmode/rm/trampoline_64.S
28611 +++ b/arch/x86/realmode/rm/trampoline_64.S
28612 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28613 wrmsr
28614
28615 # Enable paging and in turn activate Long Mode
28616 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28617 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28618 movl %eax, %cr0
28619
28620 /*
28621 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28622 index 5a1847d..deccb30 100644
28623 --- a/arch/x86/tools/relocs.c
28624 +++ b/arch/x86/tools/relocs.c
28625 @@ -12,10 +12,13 @@
28626 #include <regex.h>
28627 #include <tools/le_byteshift.h>
28628
28629 +#include "../../../include/generated/autoconf.h"
28630 +
28631 static void die(char *fmt, ...);
28632
28633 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28634 static Elf32_Ehdr ehdr;
28635 +static Elf32_Phdr *phdr;
28636 static unsigned long reloc_count, reloc_idx;
28637 static unsigned long *relocs;
28638 static unsigned long reloc16_count, reloc16_idx;
28639 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28640 }
28641 }
28642
28643 +static void read_phdrs(FILE *fp)
28644 +{
28645 + unsigned int i;
28646 +
28647 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28648 + if (!phdr) {
28649 + die("Unable to allocate %d program headers\n",
28650 + ehdr.e_phnum);
28651 + }
28652 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28653 + die("Seek to %d failed: %s\n",
28654 + ehdr.e_phoff, strerror(errno));
28655 + }
28656 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28657 + die("Cannot read ELF program headers: %s\n",
28658 + strerror(errno));
28659 + }
28660 + for(i = 0; i < ehdr.e_phnum; i++) {
28661 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28662 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28663 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28664 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28665 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28666 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28667 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28668 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28669 + }
28670 +
28671 +}
28672 +
28673 static void read_shdrs(FILE *fp)
28674 {
28675 - int i;
28676 + unsigned int i;
28677 Elf32_Shdr shdr;
28678
28679 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28680 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28681
28682 static void read_strtabs(FILE *fp)
28683 {
28684 - int i;
28685 + unsigned int i;
28686 for (i = 0; i < ehdr.e_shnum; i++) {
28687 struct section *sec = &secs[i];
28688 if (sec->shdr.sh_type != SHT_STRTAB) {
28689 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28690
28691 static void read_symtabs(FILE *fp)
28692 {
28693 - int i,j;
28694 + unsigned int i,j;
28695 for (i = 0; i < ehdr.e_shnum; i++) {
28696 struct section *sec = &secs[i];
28697 if (sec->shdr.sh_type != SHT_SYMTAB) {
28698 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28699 }
28700
28701
28702 -static void read_relocs(FILE *fp)
28703 +static void read_relocs(FILE *fp, int use_real_mode)
28704 {
28705 - int i,j;
28706 + unsigned int i,j;
28707 + uint32_t base;
28708 +
28709 for (i = 0; i < ehdr.e_shnum; i++) {
28710 struct section *sec = &secs[i];
28711 if (sec->shdr.sh_type != SHT_REL) {
28712 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28713 die("Cannot read symbol table: %s\n",
28714 strerror(errno));
28715 }
28716 + base = 0;
28717 +
28718 +#ifdef CONFIG_X86_32
28719 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28720 + if (phdr[j].p_type != PT_LOAD )
28721 + continue;
28722 + 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)
28723 + continue;
28724 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28725 + break;
28726 + }
28727 +#endif
28728 +
28729 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28730 Elf32_Rel *rel = &sec->reltab[j];
28731 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28732 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28733 rel->r_info = elf32_to_cpu(rel->r_info);
28734 }
28735 }
28736 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28737
28738 static void print_absolute_symbols(void)
28739 {
28740 - int i;
28741 + unsigned int i;
28742 printf("Absolute symbols\n");
28743 printf(" Num: Value Size Type Bind Visibility Name\n");
28744 for (i = 0; i < ehdr.e_shnum; i++) {
28745 struct section *sec = &secs[i];
28746 char *sym_strtab;
28747 - int j;
28748 + unsigned int j;
28749
28750 if (sec->shdr.sh_type != SHT_SYMTAB) {
28751 continue;
28752 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28753
28754 static void print_absolute_relocs(void)
28755 {
28756 - int i, printed = 0;
28757 + unsigned int i, printed = 0;
28758
28759 for (i = 0; i < ehdr.e_shnum; i++) {
28760 struct section *sec = &secs[i];
28761 struct section *sec_applies, *sec_symtab;
28762 char *sym_strtab;
28763 Elf32_Sym *sh_symtab;
28764 - int j;
28765 + unsigned int j;
28766 if (sec->shdr.sh_type != SHT_REL) {
28767 continue;
28768 }
28769 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28770 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28771 int use_real_mode)
28772 {
28773 - int i;
28774 + unsigned int i;
28775 /* Walk through the relocations */
28776 for (i = 0; i < ehdr.e_shnum; i++) {
28777 char *sym_strtab;
28778 Elf32_Sym *sh_symtab;
28779 struct section *sec_applies, *sec_symtab;
28780 - int j;
28781 + unsigned int j;
28782 struct section *sec = &secs[i];
28783
28784 if (sec->shdr.sh_type != SHT_REL) {
28785 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28786 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28787 r_type = ELF32_R_TYPE(rel->r_info);
28788
28789 + if (!use_real_mode) {
28790 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28791 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28792 + continue;
28793 +
28794 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28795 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28796 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28797 + continue;
28798 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28799 + continue;
28800 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28801 + continue;
28802 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28803 + continue;
28804 +#endif
28805 + }
28806 +
28807 shn_abs = sym->st_shndx == SHN_ABS;
28808
28809 switch (r_type) {
28810 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
28811
28812 static void emit_relocs(int as_text, int use_real_mode)
28813 {
28814 - int i;
28815 + unsigned int i;
28816 /* Count how many relocations I have and allocate space for them. */
28817 reloc_count = 0;
28818 walk_relocs(count_reloc, use_real_mode);
28819 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
28820 fname, strerror(errno));
28821 }
28822 read_ehdr(fp);
28823 + read_phdrs(fp);
28824 read_shdrs(fp);
28825 read_strtabs(fp);
28826 read_symtabs(fp);
28827 - read_relocs(fp);
28828 + read_relocs(fp, use_real_mode);
28829 if (show_absolute_syms) {
28830 print_absolute_symbols();
28831 return 0;
28832 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
28833 index fd14be1..e3c79c0 100644
28834 --- a/arch/x86/vdso/Makefile
28835 +++ b/arch/x86/vdso/Makefile
28836 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
28837 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
28838 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
28839
28840 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28841 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28842 GCOV_PROFILE := n
28843
28844 #
28845 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
28846 index 0faad64..39ef157 100644
28847 --- a/arch/x86/vdso/vdso32-setup.c
28848 +++ b/arch/x86/vdso/vdso32-setup.c
28849 @@ -25,6 +25,7 @@
28850 #include <asm/tlbflush.h>
28851 #include <asm/vdso.h>
28852 #include <asm/proto.h>
28853 +#include <asm/mman.h>
28854
28855 enum {
28856 VDSO_DISABLED = 0,
28857 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
28858 void enable_sep_cpu(void)
28859 {
28860 int cpu = get_cpu();
28861 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
28862 + struct tss_struct *tss = init_tss + cpu;
28863
28864 if (!boot_cpu_has(X86_FEATURE_SEP)) {
28865 put_cpu();
28866 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
28867 gate_vma.vm_start = FIXADDR_USER_START;
28868 gate_vma.vm_end = FIXADDR_USER_END;
28869 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
28870 - gate_vma.vm_page_prot = __P101;
28871 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
28872
28873 return 0;
28874 }
28875 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28876 if (compat)
28877 addr = VDSO_HIGH_BASE;
28878 else {
28879 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
28880 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
28881 if (IS_ERR_VALUE(addr)) {
28882 ret = addr;
28883 goto up_fail;
28884 }
28885 }
28886
28887 - current->mm->context.vdso = (void *)addr;
28888 + current->mm->context.vdso = addr;
28889
28890 if (compat_uses_vma || !compat) {
28891 /*
28892 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28893 }
28894
28895 current_thread_info()->sysenter_return =
28896 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28897 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28898
28899 up_fail:
28900 if (ret)
28901 - current->mm->context.vdso = NULL;
28902 + current->mm->context.vdso = 0;
28903
28904 up_write(&mm->mmap_sem);
28905
28906 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
28907
28908 const char *arch_vma_name(struct vm_area_struct *vma)
28909 {
28910 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28911 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28912 return "[vdso]";
28913 +
28914 +#ifdef CONFIG_PAX_SEGMEXEC
28915 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
28916 + return "[vdso]";
28917 +#endif
28918 +
28919 return NULL;
28920 }
28921
28922 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28923 * Check to see if the corresponding task was created in compat vdso
28924 * mode.
28925 */
28926 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
28927 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
28928 return &gate_vma;
28929 return NULL;
28930 }
28931 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
28932 index 00aaf04..4a26505 100644
28933 --- a/arch/x86/vdso/vma.c
28934 +++ b/arch/x86/vdso/vma.c
28935 @@ -16,8 +16,6 @@
28936 #include <asm/vdso.h>
28937 #include <asm/page.h>
28938
28939 -unsigned int __read_mostly vdso_enabled = 1;
28940 -
28941 extern char vdso_start[], vdso_end[];
28942 extern unsigned short vdso_sync_cpuid;
28943
28944 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
28945 * unaligned here as a result of stack start randomization.
28946 */
28947 addr = PAGE_ALIGN(addr);
28948 - addr = align_addr(addr, NULL, ALIGN_VDSO);
28949
28950 return addr;
28951 }
28952 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
28953 unsigned size)
28954 {
28955 struct mm_struct *mm = current->mm;
28956 - unsigned long addr;
28957 + unsigned long addr = 0;
28958 int ret;
28959
28960 - if (!vdso_enabled)
28961 - return 0;
28962 -
28963 down_write(&mm->mmap_sem);
28964 +
28965 +#ifdef CONFIG_PAX_RANDMMAP
28966 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28967 +#endif
28968 +
28969 addr = vdso_addr(mm->start_stack, size);
28970 + addr = align_addr(addr, NULL, ALIGN_VDSO);
28971 addr = get_unmapped_area(NULL, addr, size, 0, 0);
28972 if (IS_ERR_VALUE(addr)) {
28973 ret = addr;
28974 goto up_fail;
28975 }
28976
28977 - current->mm->context.vdso = (void *)addr;
28978 + mm->context.vdso = addr;
28979
28980 ret = install_special_mapping(mm, addr, size,
28981 VM_READ|VM_EXEC|
28982 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
28983 pages);
28984 - if (ret) {
28985 - current->mm->context.vdso = NULL;
28986 - goto up_fail;
28987 - }
28988 + if (ret)
28989 + mm->context.vdso = 0;
28990
28991 up_fail:
28992 up_write(&mm->mmap_sem);
28993 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28994 vdsox32_size);
28995 }
28996 #endif
28997 -
28998 -static __init int vdso_setup(char *s)
28999 -{
29000 - vdso_enabled = simple_strtoul(s, NULL, 0);
29001 - return 0;
29002 -}
29003 -__setup("vdso=", vdso_setup);
29004 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29005 index 586d838..e883209 100644
29006 --- a/arch/x86/xen/enlighten.c
29007 +++ b/arch/x86/xen/enlighten.c
29008 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29009
29010 struct shared_info xen_dummy_shared_info;
29011
29012 -void *xen_initial_gdt;
29013 -
29014 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29015 __read_mostly int xen_have_vector_callback;
29016 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29017 @@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29018 {
29019 unsigned long va = dtr->address;
29020 unsigned int size = dtr->size + 1;
29021 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29022 - unsigned long frames[pages];
29023 + unsigned long frames[65536 / PAGE_SIZE];
29024 int f;
29025
29026 /*
29027 @@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29028 {
29029 unsigned long va = dtr->address;
29030 unsigned int size = dtr->size + 1;
29031 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29032 - unsigned long frames[pages];
29033 + unsigned long frames[65536 / PAGE_SIZE];
29034 int f;
29035
29036 /*
29037 @@ -916,7 +912,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29038 return 0;
29039 }
29040
29041 -static void set_xen_basic_apic_ops(void)
29042 +static void __init set_xen_basic_apic_ops(void)
29043 {
29044 apic->read = xen_apic_read;
29045 apic->write = xen_apic_write;
29046 @@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29047 #endif
29048 };
29049
29050 -static void xen_reboot(int reason)
29051 +static __noreturn void xen_reboot(int reason)
29052 {
29053 struct sched_shutdown r = { .reason = reason };
29054
29055 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29056 - BUG();
29057 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29058 + BUG();
29059 }
29060
29061 -static void xen_restart(char *msg)
29062 +static __noreturn void xen_restart(char *msg)
29063 {
29064 xen_reboot(SHUTDOWN_reboot);
29065 }
29066
29067 -static void xen_emergency_restart(void)
29068 +static __noreturn void xen_emergency_restart(void)
29069 {
29070 xen_reboot(SHUTDOWN_reboot);
29071 }
29072
29073 -static void xen_machine_halt(void)
29074 +static __noreturn void xen_machine_halt(void)
29075 {
29076 xen_reboot(SHUTDOWN_poweroff);
29077 }
29078
29079 -static void xen_machine_power_off(void)
29080 +static __noreturn void xen_machine_power_off(void)
29081 {
29082 if (pm_power_off)
29083 pm_power_off();
29084 @@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29085 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29086
29087 /* Work out if we support NX */
29088 - x86_configure_nx();
29089 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29090 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29091 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29092 + unsigned l, h;
29093 +
29094 + __supported_pte_mask |= _PAGE_NX;
29095 + rdmsr(MSR_EFER, l, h);
29096 + l |= EFER_NX;
29097 + wrmsr(MSR_EFER, l, h);
29098 + }
29099 +#endif
29100
29101 xen_setup_features();
29102
29103 @@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29104 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29105 }
29106
29107 - machine_ops = xen_machine_ops;
29108 -
29109 - /*
29110 - * The only reliable way to retain the initial address of the
29111 - * percpu gdt_page is to remember it here, so we can go and
29112 - * mark it RW later, when the initial percpu area is freed.
29113 - */
29114 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29115 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29116
29117 xen_smp_init();
29118
29119 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29120 index dcf5f2d..d804c25 100644
29121 --- a/arch/x86/xen/mmu.c
29122 +++ b/arch/x86/xen/mmu.c
29123 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29124 /* L3_k[510] -> level2_kernel_pgt
29125 * L3_i[511] -> level2_fixmap_pgt */
29126 convert_pfn_mfn(level3_kernel_pgt);
29127 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29128 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29129 + convert_pfn_mfn(level3_vmemmap_pgt);
29130
29131 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29132 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29133 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29134 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29135 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29136 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29137 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29138 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29139 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29140 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29141 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29142 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29143 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29144 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29145
29146 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29147 pv_mmu_ops.set_pud = xen_set_pud;
29148 #if PAGETABLE_LEVELS == 4
29149 pv_mmu_ops.set_pgd = xen_set_pgd;
29150 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29151 #endif
29152
29153 /* This will work as long as patching hasn't happened yet
29154 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29155 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29156 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29157 .set_pgd = xen_set_pgd_hyper,
29158 + .set_pgd_batched = xen_set_pgd_hyper,
29159
29160 .alloc_pud = xen_alloc_pmd_init,
29161 .release_pud = xen_release_pmd_init,
29162 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29163 index 353c50f..8f3c179 100644
29164 --- a/arch/x86/xen/smp.c
29165 +++ b/arch/x86/xen/smp.c
29166 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29167 {
29168 BUG_ON(smp_processor_id() != 0);
29169 native_smp_prepare_boot_cpu();
29170 -
29171 - /* We've switched to the "real" per-cpu gdt, so make sure the
29172 - old memory can be recycled */
29173 - make_lowmem_page_readwrite(xen_initial_gdt);
29174 -
29175 xen_filter_cpu_maps();
29176 xen_setup_vcpu_info_placement();
29177 }
29178 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29179 gdt = get_cpu_gdt_table(cpu);
29180
29181 ctxt->flags = VGCF_IN_KERNEL;
29182 - ctxt->user_regs.ds = __USER_DS;
29183 - ctxt->user_regs.es = __USER_DS;
29184 + ctxt->user_regs.ds = __KERNEL_DS;
29185 + ctxt->user_regs.es = __KERNEL_DS;
29186 ctxt->user_regs.ss = __KERNEL_DS;
29187 #ifdef CONFIG_X86_32
29188 ctxt->user_regs.fs = __KERNEL_PERCPU;
29189 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29190 + savesegment(gs, ctxt->user_regs.gs);
29191 #else
29192 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29193 #endif
29194 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29195 int rc;
29196
29197 per_cpu(current_task, cpu) = idle;
29198 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29199 #ifdef CONFIG_X86_32
29200 irq_ctx_init(cpu);
29201 #else
29202 clear_tsk_thread_flag(idle, TIF_FORK);
29203 - per_cpu(kernel_stack, cpu) =
29204 - (unsigned long)task_stack_page(idle) -
29205 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29206 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29207 #endif
29208 xen_setup_runstate_info(cpu);
29209 xen_setup_timer(cpu);
29210 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29211
29212 void __init xen_smp_init(void)
29213 {
29214 - smp_ops = xen_smp_ops;
29215 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29216 xen_fill_possible_map();
29217 xen_init_spinlocks();
29218 }
29219 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29220 index 33ca6e4..0ded929 100644
29221 --- a/arch/x86/xen/xen-asm_32.S
29222 +++ b/arch/x86/xen/xen-asm_32.S
29223 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29224 ESP_OFFSET=4 # bytes pushed onto stack
29225
29226 /*
29227 - * Store vcpu_info pointer for easy access. Do it this way to
29228 - * avoid having to reload %fs
29229 + * Store vcpu_info pointer for easy access.
29230 */
29231 #ifdef CONFIG_SMP
29232 - GET_THREAD_INFO(%eax)
29233 - movl %ss:TI_cpu(%eax), %eax
29234 - movl %ss:__per_cpu_offset(,%eax,4), %eax
29235 - mov %ss:xen_vcpu(%eax), %eax
29236 + push %fs
29237 + mov $(__KERNEL_PERCPU), %eax
29238 + mov %eax, %fs
29239 + mov PER_CPU_VAR(xen_vcpu), %eax
29240 + pop %fs
29241 #else
29242 movl %ss:xen_vcpu, %eax
29243 #endif
29244 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29245 index 7faed58..ba4427c 100644
29246 --- a/arch/x86/xen/xen-head.S
29247 +++ b/arch/x86/xen/xen-head.S
29248 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29249 #ifdef CONFIG_X86_32
29250 mov %esi,xen_start_info
29251 mov $init_thread_union+THREAD_SIZE,%esp
29252 +#ifdef CONFIG_SMP
29253 + movl $cpu_gdt_table,%edi
29254 + movl $__per_cpu_load,%eax
29255 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29256 + rorl $16,%eax
29257 + movb %al,__KERNEL_PERCPU + 4(%edi)
29258 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29259 + movl $__per_cpu_end - 1,%eax
29260 + subl $__per_cpu_start,%eax
29261 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29262 +#endif
29263 #else
29264 mov %rsi,xen_start_info
29265 mov $init_thread_union+THREAD_SIZE,%rsp
29266 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29267 index a95b417..b6dbd0b 100644
29268 --- a/arch/x86/xen/xen-ops.h
29269 +++ b/arch/x86/xen/xen-ops.h
29270 @@ -10,8 +10,6 @@
29271 extern const char xen_hypervisor_callback[];
29272 extern const char xen_failsafe_callback[];
29273
29274 -extern void *xen_initial_gdt;
29275 -
29276 struct trap_info;
29277 void xen_copy_trap_info(struct trap_info *traps);
29278
29279 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29280 index 525bd3d..ef888b1 100644
29281 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29282 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29283 @@ -119,9 +119,9 @@
29284 ----------------------------------------------------------------------*/
29285
29286 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29287 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29288 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29289 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29290 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29291
29292 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29293 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29294 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29295 index 2f33760..835e50a 100644
29296 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29297 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29298 @@ -11,6 +11,7 @@
29299 #ifndef _XTENSA_CORE_H
29300 #define _XTENSA_CORE_H
29301
29302 +#include <linux/const.h>
29303
29304 /****************************************************************************
29305 Parameters Useful for Any Code, USER or PRIVILEGED
29306 @@ -112,9 +113,9 @@
29307 ----------------------------------------------------------------------*/
29308
29309 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29310 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29311 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29312 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29313 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29314
29315 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29316 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29317 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29318 index af00795..2bb8105 100644
29319 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29320 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29321 @@ -11,6 +11,7 @@
29322 #ifndef _XTENSA_CORE_CONFIGURATION_H
29323 #define _XTENSA_CORE_CONFIGURATION_H
29324
29325 +#include <linux/const.h>
29326
29327 /****************************************************************************
29328 Parameters Useful for Any Code, USER or PRIVILEGED
29329 @@ -118,9 +119,9 @@
29330 ----------------------------------------------------------------------*/
29331
29332 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29333 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29334 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29335 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29336 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29337
29338 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29339 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29340 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29341 index 58916af..9cb880b 100644
29342 --- a/block/blk-iopoll.c
29343 +++ b/block/blk-iopoll.c
29344 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29345 }
29346 EXPORT_SYMBOL(blk_iopoll_complete);
29347
29348 -static void blk_iopoll_softirq(struct softirq_action *h)
29349 +static void blk_iopoll_softirq(void)
29350 {
29351 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29352 int rearm = 0, budget = blk_iopoll_budget;
29353 diff --git a/block/blk-map.c b/block/blk-map.c
29354 index 623e1cd..ca1e109 100644
29355 --- a/block/blk-map.c
29356 +++ b/block/blk-map.c
29357 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29358 if (!len || !kbuf)
29359 return -EINVAL;
29360
29361 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29362 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29363 if (do_copy)
29364 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29365 else
29366 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29367 index 467c8de..4bddc6d 100644
29368 --- a/block/blk-softirq.c
29369 +++ b/block/blk-softirq.c
29370 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29371 * Softirq action handler - move entries to local list and loop over them
29372 * while passing them to the queue registered handler.
29373 */
29374 -static void blk_done_softirq(struct softirq_action *h)
29375 +static void blk_done_softirq(void)
29376 {
29377 struct list_head *cpu_list, local_list;
29378
29379 diff --git a/block/bsg.c b/block/bsg.c
29380 index ff64ae3..593560c 100644
29381 --- a/block/bsg.c
29382 +++ b/block/bsg.c
29383 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29384 struct sg_io_v4 *hdr, struct bsg_device *bd,
29385 fmode_t has_write_perm)
29386 {
29387 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29388 + unsigned char *cmdptr;
29389 +
29390 if (hdr->request_len > BLK_MAX_CDB) {
29391 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29392 if (!rq->cmd)
29393 return -ENOMEM;
29394 - }
29395 + cmdptr = rq->cmd;
29396 + } else
29397 + cmdptr = tmpcmd;
29398
29399 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29400 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29401 hdr->request_len))
29402 return -EFAULT;
29403
29404 + if (cmdptr != rq->cmd)
29405 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29406 +
29407 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29408 if (blk_verify_command(rq->cmd, has_write_perm))
29409 return -EPERM;
29410 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29411 index 7c668c8..db3521c 100644
29412 --- a/block/compat_ioctl.c
29413 +++ b/block/compat_ioctl.c
29414 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29415 err |= __get_user(f->spec1, &uf->spec1);
29416 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29417 err |= __get_user(name, &uf->name);
29418 - f->name = compat_ptr(name);
29419 + f->name = (void __force_kernel *)compat_ptr(name);
29420 if (err) {
29421 err = -EFAULT;
29422 goto out;
29423 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29424 index 6296b40..417c00f 100644
29425 --- a/block/partitions/efi.c
29426 +++ b/block/partitions/efi.c
29427 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29428 if (!gpt)
29429 return NULL;
29430
29431 + if (!le32_to_cpu(gpt->num_partition_entries))
29432 + return NULL;
29433 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29434 + if (!pte)
29435 + return NULL;
29436 +
29437 count = le32_to_cpu(gpt->num_partition_entries) *
29438 le32_to_cpu(gpt->sizeof_partition_entry);
29439 - if (!count)
29440 - return NULL;
29441 - pte = kzalloc(count, GFP_KERNEL);
29442 - if (!pte)
29443 - return NULL;
29444 -
29445 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29446 (u8 *) pte,
29447 count) < count) {
29448 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29449 index 9a87daa..fb17486 100644
29450 --- a/block/scsi_ioctl.c
29451 +++ b/block/scsi_ioctl.c
29452 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29453 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29454 struct sg_io_hdr *hdr, fmode_t mode)
29455 {
29456 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29457 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29458 + unsigned char *cmdptr;
29459 +
29460 + if (rq->cmd != rq->__cmd)
29461 + cmdptr = rq->cmd;
29462 + else
29463 + cmdptr = tmpcmd;
29464 +
29465 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29466 return -EFAULT;
29467 +
29468 + if (cmdptr != rq->cmd)
29469 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29470 +
29471 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29472 return -EPERM;
29473
29474 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29475 int err;
29476 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29477 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29478 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29479 + unsigned char *cmdptr;
29480
29481 if (!sic)
29482 return -EINVAL;
29483 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29484 */
29485 err = -EFAULT;
29486 rq->cmd_len = cmdlen;
29487 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29488 +
29489 + if (rq->cmd != rq->__cmd)
29490 + cmdptr = rq->cmd;
29491 + else
29492 + cmdptr = tmpcmd;
29493 +
29494 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29495 goto error;
29496
29497 + if (rq->cmd != cmdptr)
29498 + memcpy(rq->cmd, cmdptr, cmdlen);
29499 +
29500 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29501 goto error;
29502
29503 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
29504 index 533de95..7d4a8d2 100644
29505 --- a/crypto/ablkcipher.c
29506 +++ b/crypto/ablkcipher.c
29507 @@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
29508 {
29509 struct crypto_report_blkcipher rblkcipher;
29510
29511 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
29512 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
29513 - alg->cra_ablkcipher.geniv ?: "<default>");
29514 + strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
29515 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
29516 + sizeof(rblkcipher.geniv));
29517
29518 rblkcipher.blocksize = alg->cra_blocksize;
29519 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
29520 @@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
29521 {
29522 struct crypto_report_blkcipher rblkcipher;
29523
29524 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
29525 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
29526 - alg->cra_ablkcipher.geniv ?: "<built-in>");
29527 + strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
29528 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
29529 + sizeof(rblkcipher.geniv));
29530
29531 rblkcipher.blocksize = alg->cra_blocksize;
29532 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
29533 diff --git a/crypto/aead.c b/crypto/aead.c
29534 index 0b8121e..27bc487 100644
29535 --- a/crypto/aead.c
29536 +++ b/crypto/aead.c
29537 @@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
29538 struct crypto_report_aead raead;
29539 struct aead_alg *aead = &alg->cra_aead;
29540
29541 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
29542 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
29543 - aead->geniv ?: "<built-in>");
29544 + strncpy(raead.type, "aead", sizeof(raead.type));
29545 + strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
29546
29547 raead.blocksize = alg->cra_blocksize;
29548 raead.maxauthsize = aead->maxauthsize;
29549 @@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
29550 struct crypto_report_aead raead;
29551 struct aead_alg *aead = &alg->cra_aead;
29552
29553 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
29554 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
29555 + strncpy(raead.type, "nivaead", sizeof(raead.type));
29556 + strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
29557
29558 raead.blocksize = alg->cra_blocksize;
29559 raead.maxauthsize = aead->maxauthsize;
29560 diff --git a/crypto/ahash.c b/crypto/ahash.c
29561 index 3887856..793a27f 100644
29562 --- a/crypto/ahash.c
29563 +++ b/crypto/ahash.c
29564 @@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
29565 {
29566 struct crypto_report_hash rhash;
29567
29568 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
29569 + strncpy(rhash.type, "ahash", sizeof(rhash.type));
29570
29571 rhash.blocksize = alg->cra_blocksize;
29572 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
29573 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
29574 index a8d85a1..c44e014 100644
29575 --- a/crypto/blkcipher.c
29576 +++ b/crypto/blkcipher.c
29577 @@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
29578 {
29579 struct crypto_report_blkcipher rblkcipher;
29580
29581 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
29582 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
29583 - alg->cra_blkcipher.geniv ?: "<default>");
29584 + strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
29585 + strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
29586 + sizeof(rblkcipher.geniv));
29587
29588 rblkcipher.blocksize = alg->cra_blocksize;
29589 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
29590 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29591 index 7bdd61b..afec999 100644
29592 --- a/crypto/cryptd.c
29593 +++ b/crypto/cryptd.c
29594 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29595
29596 struct cryptd_blkcipher_request_ctx {
29597 crypto_completion_t complete;
29598 -};
29599 +} __no_const;
29600
29601 struct cryptd_hash_ctx {
29602 struct crypto_shash *child;
29603 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29604
29605 struct cryptd_aead_request_ctx {
29606 crypto_completion_t complete;
29607 -};
29608 +} __no_const;
29609
29610 static void cryptd_queue_worker(struct work_struct *work);
29611
29612 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
29613 index 35d700a..dfd511f 100644
29614 --- a/crypto/crypto_user.c
29615 +++ b/crypto/crypto_user.c
29616 @@ -30,6 +30,8 @@
29617
29618 #include "internal.h"
29619
29620 +#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
29621 +
29622 static DEFINE_MUTEX(crypto_cfg_mutex);
29623
29624 /* The crypto netlink socket */
29625 @@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
29626 {
29627 struct crypto_report_cipher rcipher;
29628
29629 - snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
29630 + strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
29631
29632 rcipher.blocksize = alg->cra_blocksize;
29633 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
29634 @@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
29635 {
29636 struct crypto_report_comp rcomp;
29637
29638 - snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
29639 -
29640 + strncpy(rcomp.type, "compression", sizeof(rcomp.type));
29641 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
29642 sizeof(struct crypto_report_comp), &rcomp))
29643 goto nla_put_failure;
29644 @@ -108,12 +109,14 @@ nla_put_failure:
29645 static int crypto_report_one(struct crypto_alg *alg,
29646 struct crypto_user_alg *ualg, struct sk_buff *skb)
29647 {
29648 - memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
29649 - memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
29650 - sizeof(ualg->cru_driver_name));
29651 - memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
29652 - CRYPTO_MAX_ALG_NAME);
29653 + strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
29654 + strncpy(ualg->cru_driver_name, alg->cra_driver_name,
29655 + sizeof(ualg->cru_driver_name));
29656 + strncpy(ualg->cru_module_name, module_name(alg->cra_module),
29657 + sizeof(ualg->cru_module_name));
29658
29659 + ualg->cru_type = 0;
29660 + ualg->cru_mask = 0;
29661 ualg->cru_flags = alg->cra_flags;
29662 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
29663
29664 @@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
29665 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
29666 struct crypto_report_larval rl;
29667
29668 - snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
29669 -
29670 + strncpy(rl.type, "larval", sizeof(rl.type));
29671 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
29672 sizeof(struct crypto_report_larval), &rl))
29673 goto nla_put_failure;
29674 @@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
29675 struct crypto_dump_info info;
29676 int err;
29677
29678 - if (!p->cru_driver_name)
29679 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
29680 + return -EINVAL;
29681 +
29682 + if (!p->cru_driver_name[0])
29683 return -EINVAL;
29684
29685 alg = crypto_alg_match(p, 1);
29686 @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
29687 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
29688 LIST_HEAD(list);
29689
29690 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
29691 + return -EINVAL;
29692 +
29693 if (priority && !strlen(p->cru_driver_name))
29694 return -EINVAL;
29695
29696 @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
29697 struct crypto_alg *alg;
29698 struct crypto_user_alg *p = nlmsg_data(nlh);
29699
29700 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
29701 + return -EINVAL;
29702 +
29703 alg = crypto_alg_match(p, 1);
29704 if (!alg)
29705 return -ENOENT;
29706 @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
29707 struct crypto_user_alg *p = nlmsg_data(nlh);
29708 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
29709
29710 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
29711 + return -EINVAL;
29712 +
29713 if (strlen(p->cru_driver_name))
29714 exact = 1;
29715
29716 diff --git a/crypto/pcompress.c b/crypto/pcompress.c
29717 index 04e083f..7140fe7 100644
29718 --- a/crypto/pcompress.c
29719 +++ b/crypto/pcompress.c
29720 @@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
29721 {
29722 struct crypto_report_comp rpcomp;
29723
29724 - snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
29725 -
29726 + strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
29727 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
29728 sizeof(struct crypto_report_comp), &rpcomp))
29729 goto nla_put_failure;
29730 diff --git a/crypto/rng.c b/crypto/rng.c
29731 index f3b7894..e0a25c2 100644
29732 --- a/crypto/rng.c
29733 +++ b/crypto/rng.c
29734 @@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
29735 {
29736 struct crypto_report_rng rrng;
29737
29738 - snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
29739 + strncpy(rrng.type, "rng", sizeof(rrng.type));
29740
29741 rrng.seedsize = alg->cra_rng.seedsize;
29742
29743 diff --git a/crypto/shash.c b/crypto/shash.c
29744 index f426330f..929058a 100644
29745 --- a/crypto/shash.c
29746 +++ b/crypto/shash.c
29747 @@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
29748 struct crypto_report_hash rhash;
29749 struct shash_alg *salg = __crypto_shash_alg(alg);
29750
29751 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
29752 + strncpy(rhash.type, "shash", sizeof(rhash.type));
29753 +
29754 rhash.blocksize = alg->cra_blocksize;
29755 rhash.digestsize = salg->digestsize;
29756
29757 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29758 index e6defd8..c26a225 100644
29759 --- a/drivers/acpi/apei/cper.c
29760 +++ b/drivers/acpi/apei/cper.c
29761 @@ -38,12 +38,12 @@
29762 */
29763 u64 cper_next_record_id(void)
29764 {
29765 - static atomic64_t seq;
29766 + static atomic64_unchecked_t seq;
29767
29768 - if (!atomic64_read(&seq))
29769 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29770 + if (!atomic64_read_unchecked(&seq))
29771 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29772
29773 - return atomic64_inc_return(&seq);
29774 + return atomic64_inc_return_unchecked(&seq);
29775 }
29776 EXPORT_SYMBOL_GPL(cper_next_record_id);
29777
29778 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29779 index 7586544..636a2f0 100644
29780 --- a/drivers/acpi/ec_sys.c
29781 +++ b/drivers/acpi/ec_sys.c
29782 @@ -12,6 +12,7 @@
29783 #include <linux/acpi.h>
29784 #include <linux/debugfs.h>
29785 #include <linux/module.h>
29786 +#include <linux/uaccess.h>
29787 #include "internal.h"
29788
29789 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29790 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29791 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29792 */
29793 unsigned int size = EC_SPACE_SIZE;
29794 - u8 *data = (u8 *) buf;
29795 + u8 data;
29796 loff_t init_off = *off;
29797 int err = 0;
29798
29799 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29800 size = count;
29801
29802 while (size) {
29803 - err = ec_read(*off, &data[*off - init_off]);
29804 + err = ec_read(*off, &data);
29805 if (err)
29806 return err;
29807 + if (put_user(data, &buf[*off - init_off]))
29808 + return -EFAULT;
29809 *off += 1;
29810 size--;
29811 }
29812 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29813
29814 unsigned int size = count;
29815 loff_t init_off = *off;
29816 - u8 *data = (u8 *) buf;
29817 int err = 0;
29818
29819 if (*off >= EC_SPACE_SIZE)
29820 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29821 }
29822
29823 while (size) {
29824 - u8 byte_write = data[*off - init_off];
29825 + u8 byte_write;
29826 + if (get_user(byte_write, &buf[*off - init_off]))
29827 + return -EFAULT;
29828 err = ec_write(*off, byte_write);
29829 if (err)
29830 return err;
29831 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
29832 index 27adb09..ef98796b 100644
29833 --- a/drivers/acpi/proc.c
29834 +++ b/drivers/acpi/proc.c
29835 @@ -362,16 +362,13 @@ acpi_system_write_wakeup_device(struct file *file,
29836 struct list_head *node, *next;
29837 char strbuf[5];
29838 char str[5] = "";
29839 - unsigned int len = count;
29840
29841 - if (len > 4)
29842 - len = 4;
29843 - if (len < 0)
29844 - return -EFAULT;
29845 + if (count > 4)
29846 + count = 4;
29847
29848 - if (copy_from_user(strbuf, buffer, len))
29849 + if (copy_from_user(strbuf, buffer, count))
29850 return -EFAULT;
29851 - strbuf[len] = '\0';
29852 + strbuf[count] = '\0';
29853 sscanf(strbuf, "%s", str);
29854
29855 mutex_lock(&acpi_device_lock);
29856 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
29857 index bd4e5dc..0497b66 100644
29858 --- a/drivers/acpi/processor_driver.c
29859 +++ b/drivers/acpi/processor_driver.c
29860 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
29861 return 0;
29862 #endif
29863
29864 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
29865 + BUG_ON(pr->id >= nr_cpu_ids);
29866
29867 /*
29868 * Buggy BIOS check
29869 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
29870 index c8ac4fe..631818e 100644
29871 --- a/drivers/ata/libata-core.c
29872 +++ b/drivers/ata/libata-core.c
29873 @@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
29874 struct ata_port *ap;
29875 unsigned int tag;
29876
29877 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29878 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29879 ap = qc->ap;
29880
29881 qc->flags = 0;
29882 @@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
29883 struct ata_port *ap;
29884 struct ata_link *link;
29885
29886 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29887 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29888 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
29889 ap = qc->ap;
29890 link = qc->dev->link;
29891 @@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29892 return;
29893
29894 spin_lock(&lock);
29895 + pax_open_kernel();
29896
29897 for (cur = ops->inherits; cur; cur = cur->inherits) {
29898 void **inherit = (void **)cur;
29899 @@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29900 if (IS_ERR(*pp))
29901 *pp = NULL;
29902
29903 - ops->inherits = NULL;
29904 + *(struct ata_port_operations **)&ops->inherits = NULL;
29905
29906 + pax_close_kernel();
29907 spin_unlock(&lock);
29908 }
29909
29910 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
29911 index 371fd2c..0836c78 100644
29912 --- a/drivers/ata/pata_arasan_cf.c
29913 +++ b/drivers/ata/pata_arasan_cf.c
29914 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
29915 /* Handle platform specific quirks */
29916 if (pdata->quirk) {
29917 if (pdata->quirk & CF_BROKEN_PIO) {
29918 - ap->ops->set_piomode = NULL;
29919 + pax_open_kernel();
29920 + *(void **)&ap->ops->set_piomode = NULL;
29921 + pax_close_kernel();
29922 ap->pio_mask = 0;
29923 }
29924 if (pdata->quirk & CF_BROKEN_MWDMA)
29925 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29926 index f9b983a..887b9d8 100644
29927 --- a/drivers/atm/adummy.c
29928 +++ b/drivers/atm/adummy.c
29929 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29930 vcc->pop(vcc, skb);
29931 else
29932 dev_kfree_skb_any(skb);
29933 - atomic_inc(&vcc->stats->tx);
29934 + atomic_inc_unchecked(&vcc->stats->tx);
29935
29936 return 0;
29937 }
29938 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29939 index ff7bb8a..568fc0b 100644
29940 --- a/drivers/atm/ambassador.c
29941 +++ b/drivers/atm/ambassador.c
29942 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29943 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29944
29945 // VC layer stats
29946 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29947 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29948
29949 // free the descriptor
29950 kfree (tx_descr);
29951 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29952 dump_skb ("<<<", vc, skb);
29953
29954 // VC layer stats
29955 - atomic_inc(&atm_vcc->stats->rx);
29956 + atomic_inc_unchecked(&atm_vcc->stats->rx);
29957 __net_timestamp(skb);
29958 // end of our responsibility
29959 atm_vcc->push (atm_vcc, skb);
29960 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29961 } else {
29962 PRINTK (KERN_INFO, "dropped over-size frame");
29963 // should we count this?
29964 - atomic_inc(&atm_vcc->stats->rx_drop);
29965 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29966 }
29967
29968 } else {
29969 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29970 }
29971
29972 if (check_area (skb->data, skb->len)) {
29973 - atomic_inc(&atm_vcc->stats->tx_err);
29974 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29975 return -ENOMEM; // ?
29976 }
29977
29978 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29979 index b22d71c..d6e1049 100644
29980 --- a/drivers/atm/atmtcp.c
29981 +++ b/drivers/atm/atmtcp.c
29982 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29983 if (vcc->pop) vcc->pop(vcc,skb);
29984 else dev_kfree_skb(skb);
29985 if (dev_data) return 0;
29986 - atomic_inc(&vcc->stats->tx_err);
29987 + atomic_inc_unchecked(&vcc->stats->tx_err);
29988 return -ENOLINK;
29989 }
29990 size = skb->len+sizeof(struct atmtcp_hdr);
29991 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29992 if (!new_skb) {
29993 if (vcc->pop) vcc->pop(vcc,skb);
29994 else dev_kfree_skb(skb);
29995 - atomic_inc(&vcc->stats->tx_err);
29996 + atomic_inc_unchecked(&vcc->stats->tx_err);
29997 return -ENOBUFS;
29998 }
29999 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30000 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30001 if (vcc->pop) vcc->pop(vcc,skb);
30002 else dev_kfree_skb(skb);
30003 out_vcc->push(out_vcc,new_skb);
30004 - atomic_inc(&vcc->stats->tx);
30005 - atomic_inc(&out_vcc->stats->rx);
30006 + atomic_inc_unchecked(&vcc->stats->tx);
30007 + atomic_inc_unchecked(&out_vcc->stats->rx);
30008 return 0;
30009 }
30010
30011 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30012 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30013 read_unlock(&vcc_sklist_lock);
30014 if (!out_vcc) {
30015 - atomic_inc(&vcc->stats->tx_err);
30016 + atomic_inc_unchecked(&vcc->stats->tx_err);
30017 goto done;
30018 }
30019 skb_pull(skb,sizeof(struct atmtcp_hdr));
30020 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30021 __net_timestamp(new_skb);
30022 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30023 out_vcc->push(out_vcc,new_skb);
30024 - atomic_inc(&vcc->stats->tx);
30025 - atomic_inc(&out_vcc->stats->rx);
30026 + atomic_inc_unchecked(&vcc->stats->tx);
30027 + atomic_inc_unchecked(&out_vcc->stats->rx);
30028 done:
30029 if (vcc->pop) vcc->pop(vcc,skb);
30030 else dev_kfree_skb(skb);
30031 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30032 index 81e44f7..498ea36 100644
30033 --- a/drivers/atm/eni.c
30034 +++ b/drivers/atm/eni.c
30035 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30036 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30037 vcc->dev->number);
30038 length = 0;
30039 - atomic_inc(&vcc->stats->rx_err);
30040 + atomic_inc_unchecked(&vcc->stats->rx_err);
30041 }
30042 else {
30043 length = ATM_CELL_SIZE-1; /* no HEC */
30044 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30045 size);
30046 }
30047 eff = length = 0;
30048 - atomic_inc(&vcc->stats->rx_err);
30049 + atomic_inc_unchecked(&vcc->stats->rx_err);
30050 }
30051 else {
30052 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30053 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30054 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30055 vcc->dev->number,vcc->vci,length,size << 2,descr);
30056 length = eff = 0;
30057 - atomic_inc(&vcc->stats->rx_err);
30058 + atomic_inc_unchecked(&vcc->stats->rx_err);
30059 }
30060 }
30061 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30062 @@ -767,7 +767,7 @@ rx_dequeued++;
30063 vcc->push(vcc,skb);
30064 pushed++;
30065 }
30066 - atomic_inc(&vcc->stats->rx);
30067 + atomic_inc_unchecked(&vcc->stats->rx);
30068 }
30069 wake_up(&eni_dev->rx_wait);
30070 }
30071 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30072 PCI_DMA_TODEVICE);
30073 if (vcc->pop) vcc->pop(vcc,skb);
30074 else dev_kfree_skb_irq(skb);
30075 - atomic_inc(&vcc->stats->tx);
30076 + atomic_inc_unchecked(&vcc->stats->tx);
30077 wake_up(&eni_dev->tx_wait);
30078 dma_complete++;
30079 }
30080 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30081 index 86fed1b..6dc4721 100644
30082 --- a/drivers/atm/firestream.c
30083 +++ b/drivers/atm/firestream.c
30084 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30085 }
30086 }
30087
30088 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30089 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30090
30091 fs_dprintk (FS_DEBUG_TXMEM, "i");
30092 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30093 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30094 #endif
30095 skb_put (skb, qe->p1 & 0xffff);
30096 ATM_SKB(skb)->vcc = atm_vcc;
30097 - atomic_inc(&atm_vcc->stats->rx);
30098 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30099 __net_timestamp(skb);
30100 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30101 atm_vcc->push (atm_vcc, skb);
30102 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30103 kfree (pe);
30104 }
30105 if (atm_vcc)
30106 - atomic_inc(&atm_vcc->stats->rx_drop);
30107 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30108 break;
30109 case 0x1f: /* Reassembly abort: no buffers. */
30110 /* Silently increment error counter. */
30111 if (atm_vcc)
30112 - atomic_inc(&atm_vcc->stats->rx_drop);
30113 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30114 break;
30115 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30116 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30117 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30118 index 361f5ae..7fc552d 100644
30119 --- a/drivers/atm/fore200e.c
30120 +++ b/drivers/atm/fore200e.c
30121 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30122 #endif
30123 /* check error condition */
30124 if (*entry->status & STATUS_ERROR)
30125 - atomic_inc(&vcc->stats->tx_err);
30126 + atomic_inc_unchecked(&vcc->stats->tx_err);
30127 else
30128 - atomic_inc(&vcc->stats->tx);
30129 + atomic_inc_unchecked(&vcc->stats->tx);
30130 }
30131 }
30132
30133 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30134 if (skb == NULL) {
30135 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30136
30137 - atomic_inc(&vcc->stats->rx_drop);
30138 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30139 return -ENOMEM;
30140 }
30141
30142 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30143
30144 dev_kfree_skb_any(skb);
30145
30146 - atomic_inc(&vcc->stats->rx_drop);
30147 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30148 return -ENOMEM;
30149 }
30150
30151 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30152
30153 vcc->push(vcc, skb);
30154 - atomic_inc(&vcc->stats->rx);
30155 + atomic_inc_unchecked(&vcc->stats->rx);
30156
30157 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30158
30159 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30160 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30161 fore200e->atm_dev->number,
30162 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30163 - atomic_inc(&vcc->stats->rx_err);
30164 + atomic_inc_unchecked(&vcc->stats->rx_err);
30165 }
30166 }
30167
30168 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30169 goto retry_here;
30170 }
30171
30172 - atomic_inc(&vcc->stats->tx_err);
30173 + atomic_inc_unchecked(&vcc->stats->tx_err);
30174
30175 fore200e->tx_sat++;
30176 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30177 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30178 index b182c2f..1c6fa8a 100644
30179 --- a/drivers/atm/he.c
30180 +++ b/drivers/atm/he.c
30181 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30182
30183 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30184 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30185 - atomic_inc(&vcc->stats->rx_drop);
30186 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30187 goto return_host_buffers;
30188 }
30189
30190 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30191 RBRQ_LEN_ERR(he_dev->rbrq_head)
30192 ? "LEN_ERR" : "",
30193 vcc->vpi, vcc->vci);
30194 - atomic_inc(&vcc->stats->rx_err);
30195 + atomic_inc_unchecked(&vcc->stats->rx_err);
30196 goto return_host_buffers;
30197 }
30198
30199 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30200 vcc->push(vcc, skb);
30201 spin_lock(&he_dev->global_lock);
30202
30203 - atomic_inc(&vcc->stats->rx);
30204 + atomic_inc_unchecked(&vcc->stats->rx);
30205
30206 return_host_buffers:
30207 ++pdus_assembled;
30208 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30209 tpd->vcc->pop(tpd->vcc, tpd->skb);
30210 else
30211 dev_kfree_skb_any(tpd->skb);
30212 - atomic_inc(&tpd->vcc->stats->tx_err);
30213 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30214 }
30215 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30216 return;
30217 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30218 vcc->pop(vcc, skb);
30219 else
30220 dev_kfree_skb_any(skb);
30221 - atomic_inc(&vcc->stats->tx_err);
30222 + atomic_inc_unchecked(&vcc->stats->tx_err);
30223 return -EINVAL;
30224 }
30225
30226 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30227 vcc->pop(vcc, skb);
30228 else
30229 dev_kfree_skb_any(skb);
30230 - atomic_inc(&vcc->stats->tx_err);
30231 + atomic_inc_unchecked(&vcc->stats->tx_err);
30232 return -EINVAL;
30233 }
30234 #endif
30235 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30236 vcc->pop(vcc, skb);
30237 else
30238 dev_kfree_skb_any(skb);
30239 - atomic_inc(&vcc->stats->tx_err);
30240 + atomic_inc_unchecked(&vcc->stats->tx_err);
30241 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30242 return -ENOMEM;
30243 }
30244 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30245 vcc->pop(vcc, skb);
30246 else
30247 dev_kfree_skb_any(skb);
30248 - atomic_inc(&vcc->stats->tx_err);
30249 + atomic_inc_unchecked(&vcc->stats->tx_err);
30250 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30251 return -ENOMEM;
30252 }
30253 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30254 __enqueue_tpd(he_dev, tpd, cid);
30255 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30256
30257 - atomic_inc(&vcc->stats->tx);
30258 + atomic_inc_unchecked(&vcc->stats->tx);
30259
30260 return 0;
30261 }
30262 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30263 index 7d01c2a..4e3ac01 100644
30264 --- a/drivers/atm/horizon.c
30265 +++ b/drivers/atm/horizon.c
30266 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30267 {
30268 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30269 // VC layer stats
30270 - atomic_inc(&vcc->stats->rx);
30271 + atomic_inc_unchecked(&vcc->stats->rx);
30272 __net_timestamp(skb);
30273 // end of our responsibility
30274 vcc->push (vcc, skb);
30275 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30276 dev->tx_iovec = NULL;
30277
30278 // VC layer stats
30279 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30280 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30281
30282 // free the skb
30283 hrz_kfree_skb (skb);
30284 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30285 index 8974bd2..b856f85 100644
30286 --- a/drivers/atm/idt77252.c
30287 +++ b/drivers/atm/idt77252.c
30288 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30289 else
30290 dev_kfree_skb(skb);
30291
30292 - atomic_inc(&vcc->stats->tx);
30293 + atomic_inc_unchecked(&vcc->stats->tx);
30294 }
30295
30296 atomic_dec(&scq->used);
30297 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30298 if ((sb = dev_alloc_skb(64)) == NULL) {
30299 printk("%s: Can't allocate buffers for aal0.\n",
30300 card->name);
30301 - atomic_add(i, &vcc->stats->rx_drop);
30302 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30303 break;
30304 }
30305 if (!atm_charge(vcc, sb->truesize)) {
30306 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30307 card->name);
30308 - atomic_add(i - 1, &vcc->stats->rx_drop);
30309 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30310 dev_kfree_skb(sb);
30311 break;
30312 }
30313 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30314 ATM_SKB(sb)->vcc = vcc;
30315 __net_timestamp(sb);
30316 vcc->push(vcc, sb);
30317 - atomic_inc(&vcc->stats->rx);
30318 + atomic_inc_unchecked(&vcc->stats->rx);
30319
30320 cell += ATM_CELL_PAYLOAD;
30321 }
30322 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30323 "(CDC: %08x)\n",
30324 card->name, len, rpp->len, readl(SAR_REG_CDC));
30325 recycle_rx_pool_skb(card, rpp);
30326 - atomic_inc(&vcc->stats->rx_err);
30327 + atomic_inc_unchecked(&vcc->stats->rx_err);
30328 return;
30329 }
30330 if (stat & SAR_RSQE_CRC) {
30331 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30332 recycle_rx_pool_skb(card, rpp);
30333 - atomic_inc(&vcc->stats->rx_err);
30334 + atomic_inc_unchecked(&vcc->stats->rx_err);
30335 return;
30336 }
30337 if (skb_queue_len(&rpp->queue) > 1) {
30338 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30339 RXPRINTK("%s: Can't alloc RX skb.\n",
30340 card->name);
30341 recycle_rx_pool_skb(card, rpp);
30342 - atomic_inc(&vcc->stats->rx_err);
30343 + atomic_inc_unchecked(&vcc->stats->rx_err);
30344 return;
30345 }
30346 if (!atm_charge(vcc, skb->truesize)) {
30347 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30348 __net_timestamp(skb);
30349
30350 vcc->push(vcc, skb);
30351 - atomic_inc(&vcc->stats->rx);
30352 + atomic_inc_unchecked(&vcc->stats->rx);
30353
30354 return;
30355 }
30356 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30357 __net_timestamp(skb);
30358
30359 vcc->push(vcc, skb);
30360 - atomic_inc(&vcc->stats->rx);
30361 + atomic_inc_unchecked(&vcc->stats->rx);
30362
30363 if (skb->truesize > SAR_FB_SIZE_3)
30364 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30365 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30366 if (vcc->qos.aal != ATM_AAL0) {
30367 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30368 card->name, vpi, vci);
30369 - atomic_inc(&vcc->stats->rx_drop);
30370 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30371 goto drop;
30372 }
30373
30374 if ((sb = dev_alloc_skb(64)) == NULL) {
30375 printk("%s: Can't allocate buffers for AAL0.\n",
30376 card->name);
30377 - atomic_inc(&vcc->stats->rx_err);
30378 + atomic_inc_unchecked(&vcc->stats->rx_err);
30379 goto drop;
30380 }
30381
30382 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30383 ATM_SKB(sb)->vcc = vcc;
30384 __net_timestamp(sb);
30385 vcc->push(vcc, sb);
30386 - atomic_inc(&vcc->stats->rx);
30387 + atomic_inc_unchecked(&vcc->stats->rx);
30388
30389 drop:
30390 skb_pull(queue, 64);
30391 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30392
30393 if (vc == NULL) {
30394 printk("%s: NULL connection in send().\n", card->name);
30395 - atomic_inc(&vcc->stats->tx_err);
30396 + atomic_inc_unchecked(&vcc->stats->tx_err);
30397 dev_kfree_skb(skb);
30398 return -EINVAL;
30399 }
30400 if (!test_bit(VCF_TX, &vc->flags)) {
30401 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30402 - atomic_inc(&vcc->stats->tx_err);
30403 + atomic_inc_unchecked(&vcc->stats->tx_err);
30404 dev_kfree_skb(skb);
30405 return -EINVAL;
30406 }
30407 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30408 break;
30409 default:
30410 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30411 - atomic_inc(&vcc->stats->tx_err);
30412 + atomic_inc_unchecked(&vcc->stats->tx_err);
30413 dev_kfree_skb(skb);
30414 return -EINVAL;
30415 }
30416
30417 if (skb_shinfo(skb)->nr_frags != 0) {
30418 printk("%s: No scatter-gather yet.\n", card->name);
30419 - atomic_inc(&vcc->stats->tx_err);
30420 + atomic_inc_unchecked(&vcc->stats->tx_err);
30421 dev_kfree_skb(skb);
30422 return -EINVAL;
30423 }
30424 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30425
30426 err = queue_skb(card, vc, skb, oam);
30427 if (err) {
30428 - atomic_inc(&vcc->stats->tx_err);
30429 + atomic_inc_unchecked(&vcc->stats->tx_err);
30430 dev_kfree_skb(skb);
30431 return err;
30432 }
30433 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30434 skb = dev_alloc_skb(64);
30435 if (!skb) {
30436 printk("%s: Out of memory in send_oam().\n", card->name);
30437 - atomic_inc(&vcc->stats->tx_err);
30438 + atomic_inc_unchecked(&vcc->stats->tx_err);
30439 return -ENOMEM;
30440 }
30441 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30442 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30443 index 96cce6d..62c3ec5 100644
30444 --- a/drivers/atm/iphase.c
30445 +++ b/drivers/atm/iphase.c
30446 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30447 status = (u_short) (buf_desc_ptr->desc_mode);
30448 if (status & (RX_CER | RX_PTE | RX_OFL))
30449 {
30450 - atomic_inc(&vcc->stats->rx_err);
30451 + atomic_inc_unchecked(&vcc->stats->rx_err);
30452 IF_ERR(printk("IA: bad packet, dropping it");)
30453 if (status & RX_CER) {
30454 IF_ERR(printk(" cause: packet CRC error\n");)
30455 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30456 len = dma_addr - buf_addr;
30457 if (len > iadev->rx_buf_sz) {
30458 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30459 - atomic_inc(&vcc->stats->rx_err);
30460 + atomic_inc_unchecked(&vcc->stats->rx_err);
30461 goto out_free_desc;
30462 }
30463
30464 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30465 ia_vcc = INPH_IA_VCC(vcc);
30466 if (ia_vcc == NULL)
30467 {
30468 - atomic_inc(&vcc->stats->rx_err);
30469 + atomic_inc_unchecked(&vcc->stats->rx_err);
30470 atm_return(vcc, skb->truesize);
30471 dev_kfree_skb_any(skb);
30472 goto INCR_DLE;
30473 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30474 if ((length > iadev->rx_buf_sz) || (length >
30475 (skb->len - sizeof(struct cpcs_trailer))))
30476 {
30477 - atomic_inc(&vcc->stats->rx_err);
30478 + atomic_inc_unchecked(&vcc->stats->rx_err);
30479 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30480 length, skb->len);)
30481 atm_return(vcc, skb->truesize);
30482 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30483
30484 IF_RX(printk("rx_dle_intr: skb push");)
30485 vcc->push(vcc,skb);
30486 - atomic_inc(&vcc->stats->rx);
30487 + atomic_inc_unchecked(&vcc->stats->rx);
30488 iadev->rx_pkt_cnt++;
30489 }
30490 INCR_DLE:
30491 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30492 {
30493 struct k_sonet_stats *stats;
30494 stats = &PRIV(_ia_dev[board])->sonet_stats;
30495 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30496 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30497 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30498 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30499 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30500 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30501 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30502 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30503 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30504 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30505 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30506 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30507 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30508 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30509 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30510 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30511 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30512 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30513 }
30514 ia_cmds.status = 0;
30515 break;
30516 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30517 if ((desc == 0) || (desc > iadev->num_tx_desc))
30518 {
30519 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30520 - atomic_inc(&vcc->stats->tx);
30521 + atomic_inc_unchecked(&vcc->stats->tx);
30522 if (vcc->pop)
30523 vcc->pop(vcc, skb);
30524 else
30525 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30526 ATM_DESC(skb) = vcc->vci;
30527 skb_queue_tail(&iadev->tx_dma_q, skb);
30528
30529 - atomic_inc(&vcc->stats->tx);
30530 + atomic_inc_unchecked(&vcc->stats->tx);
30531 iadev->tx_pkt_cnt++;
30532 /* Increment transaction counter */
30533 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30534
30535 #if 0
30536 /* add flow control logic */
30537 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30538 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30539 if (iavcc->vc_desc_cnt > 10) {
30540 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30541 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30542 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30543 index 68c7588..7036683 100644
30544 --- a/drivers/atm/lanai.c
30545 +++ b/drivers/atm/lanai.c
30546 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30547 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30548 lanai_endtx(lanai, lvcc);
30549 lanai_free_skb(lvcc->tx.atmvcc, skb);
30550 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30551 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30552 }
30553
30554 /* Try to fill the buffer - don't call unless there is backlog */
30555 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30556 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30557 __net_timestamp(skb);
30558 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30559 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30560 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30561 out:
30562 lvcc->rx.buf.ptr = end;
30563 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30564 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30565 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30566 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30567 lanai->stats.service_rxnotaal5++;
30568 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30569 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30570 return 0;
30571 }
30572 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30573 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30574 int bytes;
30575 read_unlock(&vcc_sklist_lock);
30576 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30577 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30578 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30579 lvcc->stats.x.aal5.service_trash++;
30580 bytes = (SERVICE_GET_END(s) * 16) -
30581 (((unsigned long) lvcc->rx.buf.ptr) -
30582 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30583 }
30584 if (s & SERVICE_STREAM) {
30585 read_unlock(&vcc_sklist_lock);
30586 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30587 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30588 lvcc->stats.x.aal5.service_stream++;
30589 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30590 "PDU on VCI %d!\n", lanai->number, vci);
30591 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30592 return 0;
30593 }
30594 DPRINTK("got rx crc error on vci %d\n", vci);
30595 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30596 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30597 lvcc->stats.x.aal5.service_rxcrc++;
30598 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30599 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30600 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30601 index 1c70c45..300718d 100644
30602 --- a/drivers/atm/nicstar.c
30603 +++ b/drivers/atm/nicstar.c
30604 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30605 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30606 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30607 card->index);
30608 - atomic_inc(&vcc->stats->tx_err);
30609 + atomic_inc_unchecked(&vcc->stats->tx_err);
30610 dev_kfree_skb_any(skb);
30611 return -EINVAL;
30612 }
30613 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30614 if (!vc->tx) {
30615 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30616 card->index);
30617 - atomic_inc(&vcc->stats->tx_err);
30618 + atomic_inc_unchecked(&vcc->stats->tx_err);
30619 dev_kfree_skb_any(skb);
30620 return -EINVAL;
30621 }
30622 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30623 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30624 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30625 card->index);
30626 - atomic_inc(&vcc->stats->tx_err);
30627 + atomic_inc_unchecked(&vcc->stats->tx_err);
30628 dev_kfree_skb_any(skb);
30629 return -EINVAL;
30630 }
30631
30632 if (skb_shinfo(skb)->nr_frags != 0) {
30633 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30634 - atomic_inc(&vcc->stats->tx_err);
30635 + atomic_inc_unchecked(&vcc->stats->tx_err);
30636 dev_kfree_skb_any(skb);
30637 return -EINVAL;
30638 }
30639 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30640 }
30641
30642 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30643 - atomic_inc(&vcc->stats->tx_err);
30644 + atomic_inc_unchecked(&vcc->stats->tx_err);
30645 dev_kfree_skb_any(skb);
30646 return -EIO;
30647 }
30648 - atomic_inc(&vcc->stats->tx);
30649 + atomic_inc_unchecked(&vcc->stats->tx);
30650
30651 return 0;
30652 }
30653 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30654 printk
30655 ("nicstar%d: Can't allocate buffers for aal0.\n",
30656 card->index);
30657 - atomic_add(i, &vcc->stats->rx_drop);
30658 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30659 break;
30660 }
30661 if (!atm_charge(vcc, sb->truesize)) {
30662 RXPRINTK
30663 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30664 card->index);
30665 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30666 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30667 dev_kfree_skb_any(sb);
30668 break;
30669 }
30670 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30671 ATM_SKB(sb)->vcc = vcc;
30672 __net_timestamp(sb);
30673 vcc->push(vcc, sb);
30674 - atomic_inc(&vcc->stats->rx);
30675 + atomic_inc_unchecked(&vcc->stats->rx);
30676 cell += ATM_CELL_PAYLOAD;
30677 }
30678
30679 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30680 if (iovb == NULL) {
30681 printk("nicstar%d: Out of iovec buffers.\n",
30682 card->index);
30683 - atomic_inc(&vcc->stats->rx_drop);
30684 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30685 recycle_rx_buf(card, skb);
30686 return;
30687 }
30688 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30689 small or large buffer itself. */
30690 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30691 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30692 - atomic_inc(&vcc->stats->rx_err);
30693 + atomic_inc_unchecked(&vcc->stats->rx_err);
30694 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30695 NS_MAX_IOVECS);
30696 NS_PRV_IOVCNT(iovb) = 0;
30697 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30698 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30699 card->index);
30700 which_list(card, skb);
30701 - atomic_inc(&vcc->stats->rx_err);
30702 + atomic_inc_unchecked(&vcc->stats->rx_err);
30703 recycle_rx_buf(card, skb);
30704 vc->rx_iov = NULL;
30705 recycle_iov_buf(card, iovb);
30706 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30707 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30708 card->index);
30709 which_list(card, skb);
30710 - atomic_inc(&vcc->stats->rx_err);
30711 + atomic_inc_unchecked(&vcc->stats->rx_err);
30712 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30713 NS_PRV_IOVCNT(iovb));
30714 vc->rx_iov = NULL;
30715 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30716 printk(" - PDU size mismatch.\n");
30717 else
30718 printk(".\n");
30719 - atomic_inc(&vcc->stats->rx_err);
30720 + atomic_inc_unchecked(&vcc->stats->rx_err);
30721 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30722 NS_PRV_IOVCNT(iovb));
30723 vc->rx_iov = NULL;
30724 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30725 /* skb points to a small buffer */
30726 if (!atm_charge(vcc, skb->truesize)) {
30727 push_rxbufs(card, skb);
30728 - atomic_inc(&vcc->stats->rx_drop);
30729 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30730 } else {
30731 skb_put(skb, len);
30732 dequeue_sm_buf(card, skb);
30733 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30734 ATM_SKB(skb)->vcc = vcc;
30735 __net_timestamp(skb);
30736 vcc->push(vcc, skb);
30737 - atomic_inc(&vcc->stats->rx);
30738 + atomic_inc_unchecked(&vcc->stats->rx);
30739 }
30740 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30741 struct sk_buff *sb;
30742 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30743 if (len <= NS_SMBUFSIZE) {
30744 if (!atm_charge(vcc, sb->truesize)) {
30745 push_rxbufs(card, sb);
30746 - atomic_inc(&vcc->stats->rx_drop);
30747 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30748 } else {
30749 skb_put(sb, len);
30750 dequeue_sm_buf(card, sb);
30751 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30752 ATM_SKB(sb)->vcc = vcc;
30753 __net_timestamp(sb);
30754 vcc->push(vcc, sb);
30755 - atomic_inc(&vcc->stats->rx);
30756 + atomic_inc_unchecked(&vcc->stats->rx);
30757 }
30758
30759 push_rxbufs(card, skb);
30760 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30761
30762 if (!atm_charge(vcc, skb->truesize)) {
30763 push_rxbufs(card, skb);
30764 - atomic_inc(&vcc->stats->rx_drop);
30765 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30766 } else {
30767 dequeue_lg_buf(card, skb);
30768 #ifdef NS_USE_DESTRUCTORS
30769 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30770 ATM_SKB(skb)->vcc = vcc;
30771 __net_timestamp(skb);
30772 vcc->push(vcc, skb);
30773 - atomic_inc(&vcc->stats->rx);
30774 + atomic_inc_unchecked(&vcc->stats->rx);
30775 }
30776
30777 push_rxbufs(card, sb);
30778 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30779 printk
30780 ("nicstar%d: Out of huge buffers.\n",
30781 card->index);
30782 - atomic_inc(&vcc->stats->rx_drop);
30783 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30784 recycle_iovec_rx_bufs(card,
30785 (struct iovec *)
30786 iovb->data,
30787 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30788 card->hbpool.count++;
30789 } else
30790 dev_kfree_skb_any(hb);
30791 - atomic_inc(&vcc->stats->rx_drop);
30792 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30793 } else {
30794 /* Copy the small buffer to the huge buffer */
30795 sb = (struct sk_buff *)iov->iov_base;
30796 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30797 #endif /* NS_USE_DESTRUCTORS */
30798 __net_timestamp(hb);
30799 vcc->push(vcc, hb);
30800 - atomic_inc(&vcc->stats->rx);
30801 + atomic_inc_unchecked(&vcc->stats->rx);
30802 }
30803 }
30804
30805 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30806 index 1853a45..cf2426d 100644
30807 --- a/drivers/atm/solos-pci.c
30808 +++ b/drivers/atm/solos-pci.c
30809 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30810 }
30811 atm_charge(vcc, skb->truesize);
30812 vcc->push(vcc, skb);
30813 - atomic_inc(&vcc->stats->rx);
30814 + atomic_inc_unchecked(&vcc->stats->rx);
30815 break;
30816
30817 case PKT_STATUS:
30818 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30819 vcc = SKB_CB(oldskb)->vcc;
30820
30821 if (vcc) {
30822 - atomic_inc(&vcc->stats->tx);
30823 + atomic_inc_unchecked(&vcc->stats->tx);
30824 solos_pop(vcc, oldskb);
30825 } else
30826 dev_kfree_skb_irq(oldskb);
30827 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30828 index 0215934..ce9f5b1 100644
30829 --- a/drivers/atm/suni.c
30830 +++ b/drivers/atm/suni.c
30831 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30832
30833
30834 #define ADD_LIMITED(s,v) \
30835 - atomic_add((v),&stats->s); \
30836 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30837 + atomic_add_unchecked((v),&stats->s); \
30838 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30839
30840
30841 static void suni_hz(unsigned long from_timer)
30842 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30843 index 5120a96..e2572bd 100644
30844 --- a/drivers/atm/uPD98402.c
30845 +++ b/drivers/atm/uPD98402.c
30846 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30847 struct sonet_stats tmp;
30848 int error = 0;
30849
30850 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30851 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30852 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30853 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30854 if (zero && !error) {
30855 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30856
30857
30858 #define ADD_LIMITED(s,v) \
30859 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30860 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30861 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30862 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30863 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30864 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30865
30866
30867 static void stat_event(struct atm_dev *dev)
30868 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
30869 if (reason & uPD98402_INT_PFM) stat_event(dev);
30870 if (reason & uPD98402_INT_PCO) {
30871 (void) GET(PCOCR); /* clear interrupt cause */
30872 - atomic_add(GET(HECCT),
30873 + atomic_add_unchecked(GET(HECCT),
30874 &PRIV(dev)->sonet_stats.uncorr_hcs);
30875 }
30876 if ((reason & uPD98402_INT_RFO) &&
30877 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
30878 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30879 uPD98402_INT_LOS),PIMR); /* enable them */
30880 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30881 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30882 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30883 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30884 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30885 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30886 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30887 return 0;
30888 }
30889
30890 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30891 index abe4e20..83c4727 100644
30892 --- a/drivers/atm/zatm.c
30893 +++ b/drivers/atm/zatm.c
30894 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30895 }
30896 if (!size) {
30897 dev_kfree_skb_irq(skb);
30898 - if (vcc) atomic_inc(&vcc->stats->rx_err);
30899 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30900 continue;
30901 }
30902 if (!atm_charge(vcc,skb->truesize)) {
30903 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30904 skb->len = size;
30905 ATM_SKB(skb)->vcc = vcc;
30906 vcc->push(vcc,skb);
30907 - atomic_inc(&vcc->stats->rx);
30908 + atomic_inc_unchecked(&vcc->stats->rx);
30909 }
30910 zout(pos & 0xffff,MTA(mbx));
30911 #if 0 /* probably a stupid idea */
30912 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30913 skb_queue_head(&zatm_vcc->backlog,skb);
30914 break;
30915 }
30916 - atomic_inc(&vcc->stats->tx);
30917 + atomic_inc_unchecked(&vcc->stats->tx);
30918 wake_up(&zatm_vcc->tx_wait);
30919 }
30920
30921 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
30922 index 147d1a4..d0fd4b0 100644
30923 --- a/drivers/base/devtmpfs.c
30924 +++ b/drivers/base/devtmpfs.c
30925 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
30926 if (!thread)
30927 return 0;
30928
30929 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
30930 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
30931 if (err)
30932 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
30933 else
30934 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
30935 index e6ee5e8..98ad7fc 100644
30936 --- a/drivers/base/power/wakeup.c
30937 +++ b/drivers/base/power/wakeup.c
30938 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
30939 * They need to be modified together atomically, so it's better to use one
30940 * atomic variable to hold them both.
30941 */
30942 -static atomic_t combined_event_count = ATOMIC_INIT(0);
30943 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
30944
30945 #define IN_PROGRESS_BITS (sizeof(int) * 4)
30946 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
30947
30948 static void split_counters(unsigned int *cnt, unsigned int *inpr)
30949 {
30950 - unsigned int comb = atomic_read(&combined_event_count);
30951 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
30952
30953 *cnt = (comb >> IN_PROGRESS_BITS);
30954 *inpr = comb & MAX_IN_PROGRESS;
30955 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
30956 ws->start_prevent_time = ws->last_time;
30957
30958 /* Increment the counter of events in progress. */
30959 - cec = atomic_inc_return(&combined_event_count);
30960 + cec = atomic_inc_return_unchecked(&combined_event_count);
30961
30962 trace_wakeup_source_activate(ws->name, cec);
30963 }
30964 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
30965 * Increment the counter of registered wakeup events and decrement the
30966 * couter of wakeup events in progress simultaneously.
30967 */
30968 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
30969 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
30970 trace_wakeup_source_deactivate(ws->name, cec);
30971
30972 split_counters(&cnt, &inpr);
30973 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30974 index ca83f96..69d4ea9 100644
30975 --- a/drivers/block/cciss.c
30976 +++ b/drivers/block/cciss.c
30977 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30978 int err;
30979 u32 cp;
30980
30981 + memset(&arg64, 0, sizeof(arg64));
30982 +
30983 err = 0;
30984 err |=
30985 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30986 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
30987 while (!list_empty(&h->reqQ)) {
30988 c = list_entry(h->reqQ.next, CommandList_struct, list);
30989 /* can't do anything if fifo is full */
30990 - if ((h->access.fifo_full(h))) {
30991 + if ((h->access->fifo_full(h))) {
30992 dev_warn(&h->pdev->dev, "fifo full\n");
30993 break;
30994 }
30995 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
30996 h->Qdepth--;
30997
30998 /* Tell the controller execute command */
30999 - h->access.submit_command(h, c);
31000 + h->access->submit_command(h, c);
31001
31002 /* Put job onto the completed Q */
31003 addQ(&h->cmpQ, c);
31004 @@ -3443,17 +3445,17 @@ startio:
31005
31006 static inline unsigned long get_next_completion(ctlr_info_t *h)
31007 {
31008 - return h->access.command_completed(h);
31009 + return h->access->command_completed(h);
31010 }
31011
31012 static inline int interrupt_pending(ctlr_info_t *h)
31013 {
31014 - return h->access.intr_pending(h);
31015 + return h->access->intr_pending(h);
31016 }
31017
31018 static inline long interrupt_not_for_us(ctlr_info_t *h)
31019 {
31020 - return ((h->access.intr_pending(h) == 0) ||
31021 + return ((h->access->intr_pending(h) == 0) ||
31022 (h->interrupts_enabled == 0));
31023 }
31024
31025 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31026 u32 a;
31027
31028 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31029 - return h->access.command_completed(h);
31030 + return h->access->command_completed(h);
31031
31032 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31033 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31034 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31035 trans_support & CFGTBL_Trans_use_short_tags);
31036
31037 /* Change the access methods to the performant access methods */
31038 - h->access = SA5_performant_access;
31039 + h->access = &SA5_performant_access;
31040 h->transMethod = CFGTBL_Trans_Performant;
31041
31042 return;
31043 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31044 if (prod_index < 0)
31045 return -ENODEV;
31046 h->product_name = products[prod_index].product_name;
31047 - h->access = *(products[prod_index].access);
31048 + h->access = products[prod_index].access;
31049
31050 if (cciss_board_disabled(h)) {
31051 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31052 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31053 }
31054
31055 /* make sure the board interrupts are off */
31056 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31057 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31058 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31059 if (rc)
31060 goto clean2;
31061 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31062 * fake ones to scoop up any residual completions.
31063 */
31064 spin_lock_irqsave(&h->lock, flags);
31065 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31066 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31067 spin_unlock_irqrestore(&h->lock, flags);
31068 free_irq(h->intr[h->intr_mode], h);
31069 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31070 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31071 dev_info(&h->pdev->dev, "Board READY.\n");
31072 dev_info(&h->pdev->dev,
31073 "Waiting for stale completions to drain.\n");
31074 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31075 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31076 msleep(10000);
31077 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31078 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31079
31080 rc = controller_reset_failed(h->cfgtable);
31081 if (rc)
31082 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31083 cciss_scsi_setup(h);
31084
31085 /* Turn the interrupts on so we can service requests */
31086 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31087 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31088
31089 /* Get the firmware version */
31090 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31091 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31092 kfree(flush_buf);
31093 if (return_code != IO_OK)
31094 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31095 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31096 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31097 free_irq(h->intr[h->intr_mode], h);
31098 }
31099
31100 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31101 index 7fda30e..eb5dfe0 100644
31102 --- a/drivers/block/cciss.h
31103 +++ b/drivers/block/cciss.h
31104 @@ -101,7 +101,7 @@ struct ctlr_info
31105 /* information about each logical volume */
31106 drive_info_struct *drv[CISS_MAX_LUN];
31107
31108 - struct access_method access;
31109 + struct access_method *access;
31110
31111 /* queue and queue Info */
31112 struct list_head reqQ;
31113 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31114 index 9125bbe..eede5c8 100644
31115 --- a/drivers/block/cpqarray.c
31116 +++ b/drivers/block/cpqarray.c
31117 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31118 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31119 goto Enomem4;
31120 }
31121 - hba[i]->access.set_intr_mask(hba[i], 0);
31122 + hba[i]->access->set_intr_mask(hba[i], 0);
31123 if (request_irq(hba[i]->intr, do_ida_intr,
31124 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31125 {
31126 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31127 add_timer(&hba[i]->timer);
31128
31129 /* Enable IRQ now that spinlock and rate limit timer are set up */
31130 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31131 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31132
31133 for(j=0; j<NWD; j++) {
31134 struct gendisk *disk = ida_gendisk[i][j];
31135 @@ -694,7 +694,7 @@ DBGINFO(
31136 for(i=0; i<NR_PRODUCTS; i++) {
31137 if (board_id == products[i].board_id) {
31138 c->product_name = products[i].product_name;
31139 - c->access = *(products[i].access);
31140 + c->access = products[i].access;
31141 break;
31142 }
31143 }
31144 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31145 hba[ctlr]->intr = intr;
31146 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31147 hba[ctlr]->product_name = products[j].product_name;
31148 - hba[ctlr]->access = *(products[j].access);
31149 + hba[ctlr]->access = products[j].access;
31150 hba[ctlr]->ctlr = ctlr;
31151 hba[ctlr]->board_id = board_id;
31152 hba[ctlr]->pci_dev = NULL; /* not PCI */
31153 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31154
31155 while((c = h->reqQ) != NULL) {
31156 /* Can't do anything if we're busy */
31157 - if (h->access.fifo_full(h) == 0)
31158 + if (h->access->fifo_full(h) == 0)
31159 return;
31160
31161 /* Get the first entry from the request Q */
31162 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31163 h->Qdepth--;
31164
31165 /* Tell the controller to do our bidding */
31166 - h->access.submit_command(h, c);
31167 + h->access->submit_command(h, c);
31168
31169 /* Get onto the completion Q */
31170 addQ(&h->cmpQ, c);
31171 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31172 unsigned long flags;
31173 __u32 a,a1;
31174
31175 - istat = h->access.intr_pending(h);
31176 + istat = h->access->intr_pending(h);
31177 /* Is this interrupt for us? */
31178 if (istat == 0)
31179 return IRQ_NONE;
31180 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31181 */
31182 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31183 if (istat & FIFO_NOT_EMPTY) {
31184 - while((a = h->access.command_completed(h))) {
31185 + while((a = h->access->command_completed(h))) {
31186 a1 = a; a &= ~3;
31187 if ((c = h->cmpQ) == NULL)
31188 {
31189 @@ -1449,11 +1449,11 @@ static int sendcmd(
31190 /*
31191 * Disable interrupt
31192 */
31193 - info_p->access.set_intr_mask(info_p, 0);
31194 + info_p->access->set_intr_mask(info_p, 0);
31195 /* Make sure there is room in the command FIFO */
31196 /* Actually it should be completely empty at this time. */
31197 for (i = 200000; i > 0; i--) {
31198 - temp = info_p->access.fifo_full(info_p);
31199 + temp = info_p->access->fifo_full(info_p);
31200 if (temp != 0) {
31201 break;
31202 }
31203 @@ -1466,7 +1466,7 @@ DBG(
31204 /*
31205 * Send the cmd
31206 */
31207 - info_p->access.submit_command(info_p, c);
31208 + info_p->access->submit_command(info_p, c);
31209 complete = pollcomplete(ctlr);
31210
31211 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31212 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31213 * we check the new geometry. Then turn interrupts back on when
31214 * we're done.
31215 */
31216 - host->access.set_intr_mask(host, 0);
31217 + host->access->set_intr_mask(host, 0);
31218 getgeometry(ctlr);
31219 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31220 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31221
31222 for(i=0; i<NWD; i++) {
31223 struct gendisk *disk = ida_gendisk[ctlr][i];
31224 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31225 /* Wait (up to 2 seconds) for a command to complete */
31226
31227 for (i = 200000; i > 0; i--) {
31228 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31229 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31230 if (done == 0) {
31231 udelay(10); /* a short fixed delay */
31232 } else
31233 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31234 index be73e9d..7fbf140 100644
31235 --- a/drivers/block/cpqarray.h
31236 +++ b/drivers/block/cpqarray.h
31237 @@ -99,7 +99,7 @@ struct ctlr_info {
31238 drv_info_t drv[NWD];
31239 struct proc_dir_entry *proc;
31240
31241 - struct access_method access;
31242 + struct access_method *access;
31243
31244 cmdlist_t *reqQ;
31245 cmdlist_t *cmpQ;
31246 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31247 index b953cc7..e3dc580 100644
31248 --- a/drivers/block/drbd/drbd_int.h
31249 +++ b/drivers/block/drbd/drbd_int.h
31250 @@ -735,7 +735,7 @@ struct drbd_request;
31251 struct drbd_epoch {
31252 struct list_head list;
31253 unsigned int barrier_nr;
31254 - atomic_t epoch_size; /* increased on every request added. */
31255 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31256 atomic_t active; /* increased on every req. added, and dec on every finished. */
31257 unsigned long flags;
31258 };
31259 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31260 void *int_dig_in;
31261 void *int_dig_vv;
31262 wait_queue_head_t seq_wait;
31263 - atomic_t packet_seq;
31264 + atomic_unchecked_t packet_seq;
31265 unsigned int peer_seq;
31266 spinlock_t peer_seq_lock;
31267 unsigned int minor;
31268 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31269
31270 static inline void drbd_tcp_cork(struct socket *sock)
31271 {
31272 - int __user val = 1;
31273 + int val = 1;
31274 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31275 - (char __user *)&val, sizeof(val));
31276 + (char __force_user *)&val, sizeof(val));
31277 }
31278
31279 static inline void drbd_tcp_uncork(struct socket *sock)
31280 {
31281 - int __user val = 0;
31282 + int val = 0;
31283 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31284 - (char __user *)&val, sizeof(val));
31285 + (char __force_user *)&val, sizeof(val));
31286 }
31287
31288 static inline void drbd_tcp_nodelay(struct socket *sock)
31289 {
31290 - int __user val = 1;
31291 + int val = 1;
31292 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31293 - (char __user *)&val, sizeof(val));
31294 + (char __force_user *)&val, sizeof(val));
31295 }
31296
31297 static inline void drbd_tcp_quickack(struct socket *sock)
31298 {
31299 - int __user val = 2;
31300 + int val = 2;
31301 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31302 - (char __user *)&val, sizeof(val));
31303 + (char __force_user *)&val, sizeof(val));
31304 }
31305
31306 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31307 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31308 index f55683a..2101b96 100644
31309 --- a/drivers/block/drbd/drbd_main.c
31310 +++ b/drivers/block/drbd/drbd_main.c
31311 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31312 p.sector = sector;
31313 p.block_id = block_id;
31314 p.blksize = blksize;
31315 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31316 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31317
31318 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31319 return false;
31320 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31321
31322 p.sector = cpu_to_be64(req->sector);
31323 p.block_id = (unsigned long)req;
31324 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31325 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31326
31327 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31328
31329 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31330 atomic_set(&mdev->unacked_cnt, 0);
31331 atomic_set(&mdev->local_cnt, 0);
31332 atomic_set(&mdev->net_cnt, 0);
31333 - atomic_set(&mdev->packet_seq, 0);
31334 + atomic_set_unchecked(&mdev->packet_seq, 0);
31335 atomic_set(&mdev->pp_in_use, 0);
31336 atomic_set(&mdev->pp_in_use_by_net, 0);
31337 atomic_set(&mdev->rs_sect_in, 0);
31338 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31339 mdev->receiver.t_state);
31340
31341 /* no need to lock it, I'm the only thread alive */
31342 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31343 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31344 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31345 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31346 mdev->al_writ_cnt =
31347 mdev->bm_writ_cnt =
31348 mdev->read_cnt =
31349 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31350 index edb490a..ecd69da 100644
31351 --- a/drivers/block/drbd/drbd_nl.c
31352 +++ b/drivers/block/drbd/drbd_nl.c
31353 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31354 module_put(THIS_MODULE);
31355 }
31356
31357 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31358 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31359
31360 static unsigned short *
31361 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31362 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31363 cn_reply->id.idx = CN_IDX_DRBD;
31364 cn_reply->id.val = CN_VAL_DRBD;
31365
31366 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31367 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31368 cn_reply->ack = 0; /* not used here. */
31369 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31370 (int)((char *)tl - (char *)reply->tag_list);
31371 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31372 cn_reply->id.idx = CN_IDX_DRBD;
31373 cn_reply->id.val = CN_VAL_DRBD;
31374
31375 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31376 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31377 cn_reply->ack = 0; /* not used here. */
31378 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31379 (int)((char *)tl - (char *)reply->tag_list);
31380 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31381 cn_reply->id.idx = CN_IDX_DRBD;
31382 cn_reply->id.val = CN_VAL_DRBD;
31383
31384 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31385 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31386 cn_reply->ack = 0; // not used here.
31387 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31388 (int)((char*)tl - (char*)reply->tag_list);
31389 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31390 cn_reply->id.idx = CN_IDX_DRBD;
31391 cn_reply->id.val = CN_VAL_DRBD;
31392
31393 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31394 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31395 cn_reply->ack = 0; /* not used here. */
31396 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31397 (int)((char *)tl - (char *)reply->tag_list);
31398 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31399 index c74ca2d..860c819 100644
31400 --- a/drivers/block/drbd/drbd_receiver.c
31401 +++ b/drivers/block/drbd/drbd_receiver.c
31402 @@ -898,7 +898,7 @@ retry:
31403 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31404 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31405
31406 - atomic_set(&mdev->packet_seq, 0);
31407 + atomic_set_unchecked(&mdev->packet_seq, 0);
31408 mdev->peer_seq = 0;
31409
31410 if (drbd_send_protocol(mdev) == -1)
31411 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31412 do {
31413 next_epoch = NULL;
31414
31415 - epoch_size = atomic_read(&epoch->epoch_size);
31416 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31417
31418 switch (ev & ~EV_CLEANUP) {
31419 case EV_PUT:
31420 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31421 rv = FE_DESTROYED;
31422 } else {
31423 epoch->flags = 0;
31424 - atomic_set(&epoch->epoch_size, 0);
31425 + atomic_set_unchecked(&epoch->epoch_size, 0);
31426 /* atomic_set(&epoch->active, 0); is already zero */
31427 if (rv == FE_STILL_LIVE)
31428 rv = FE_RECYCLED;
31429 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31430 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31431 drbd_flush(mdev);
31432
31433 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31434 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31435 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31436 if (epoch)
31437 break;
31438 }
31439
31440 epoch = mdev->current_epoch;
31441 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31442 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31443
31444 D_ASSERT(atomic_read(&epoch->active) == 0);
31445 D_ASSERT(epoch->flags == 0);
31446 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31447 }
31448
31449 epoch->flags = 0;
31450 - atomic_set(&epoch->epoch_size, 0);
31451 + atomic_set_unchecked(&epoch->epoch_size, 0);
31452 atomic_set(&epoch->active, 0);
31453
31454 spin_lock(&mdev->epoch_lock);
31455 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31456 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31457 list_add(&epoch->list, &mdev->current_epoch->list);
31458 mdev->current_epoch = epoch;
31459 mdev->epochs++;
31460 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31461 spin_unlock(&mdev->peer_seq_lock);
31462
31463 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31464 - atomic_inc(&mdev->current_epoch->epoch_size);
31465 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31466 return drbd_drain_block(mdev, data_size);
31467 }
31468
31469 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31470
31471 spin_lock(&mdev->epoch_lock);
31472 e->epoch = mdev->current_epoch;
31473 - atomic_inc(&e->epoch->epoch_size);
31474 + atomic_inc_unchecked(&e->epoch->epoch_size);
31475 atomic_inc(&e->epoch->active);
31476 spin_unlock(&mdev->epoch_lock);
31477
31478 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31479 D_ASSERT(list_empty(&mdev->done_ee));
31480
31481 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31482 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31483 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31484 D_ASSERT(list_empty(&mdev->current_epoch->list));
31485 }
31486
31487 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31488 index 54046e5..7759c55 100644
31489 --- a/drivers/block/loop.c
31490 +++ b/drivers/block/loop.c
31491 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31492 mm_segment_t old_fs = get_fs();
31493
31494 set_fs(get_ds());
31495 - bw = file->f_op->write(file, buf, len, &pos);
31496 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31497 set_fs(old_fs);
31498 if (likely(bw == len))
31499 return 0;
31500 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31501 index d620b44..587561e 100644
31502 --- a/drivers/cdrom/cdrom.c
31503 +++ b/drivers/cdrom/cdrom.c
31504 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31505 ENSURE(reset, CDC_RESET);
31506 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31507 cdi->mc_flags = 0;
31508 - cdo->n_minors = 0;
31509 cdi->options = CDO_USE_FFLAGS;
31510
31511 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31512 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31513 else
31514 cdi->cdda_method = CDDA_OLD;
31515
31516 - if (!cdo->generic_packet)
31517 - cdo->generic_packet = cdrom_dummy_generic_packet;
31518 + if (!cdo->generic_packet) {
31519 + pax_open_kernel();
31520 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31521 + pax_close_kernel();
31522 + }
31523
31524 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31525 mutex_lock(&cdrom_mutex);
31526 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31527 if (cdi->exit)
31528 cdi->exit(cdi);
31529
31530 - cdi->ops->n_minors--;
31531 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31532 }
31533
31534 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31535 index 75d485a..2809958 100644
31536 --- a/drivers/cdrom/gdrom.c
31537 +++ b/drivers/cdrom/gdrom.c
31538 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31539 .audio_ioctl = gdrom_audio_ioctl,
31540 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31541 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31542 - .n_minors = 1,
31543 };
31544
31545 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31546 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31547 index 72bedad..8181ce1 100644
31548 --- a/drivers/char/Kconfig
31549 +++ b/drivers/char/Kconfig
31550 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31551
31552 config DEVKMEM
31553 bool "/dev/kmem virtual device support"
31554 - default y
31555 + default n
31556 + depends on !GRKERNSEC_KMEM
31557 help
31558 Say Y here if you want to support the /dev/kmem device. The
31559 /dev/kmem device is rarely used, but can be used for certain
31560 @@ -581,6 +582,7 @@ config DEVPORT
31561 bool
31562 depends on !M68K
31563 depends on ISA || PCI
31564 + depends on !GRKERNSEC_KMEM
31565 default y
31566
31567 source "drivers/s390/char/Kconfig"
31568 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31569 index 2e04433..22afc64 100644
31570 --- a/drivers/char/agp/frontend.c
31571 +++ b/drivers/char/agp/frontend.c
31572 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31573 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31574 return -EFAULT;
31575
31576 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31577 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31578 return -EFAULT;
31579
31580 client = agp_find_client_by_pid(reserve.pid);
31581 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31582 index 21cb980..f15107c 100644
31583 --- a/drivers/char/genrtc.c
31584 +++ b/drivers/char/genrtc.c
31585 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31586 switch (cmd) {
31587
31588 case RTC_PLL_GET:
31589 + memset(&pll, 0, sizeof(pll));
31590 if (get_rtc_pll(&pll))
31591 return -EINVAL;
31592 else
31593 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31594 index dfd7876..c0b0885 100644
31595 --- a/drivers/char/hpet.c
31596 +++ b/drivers/char/hpet.c
31597 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31598 }
31599
31600 static int
31601 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31602 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31603 struct hpet_info *info)
31604 {
31605 struct hpet_timer __iomem *timer;
31606 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31607 index a0c84bb..9edcf60 100644
31608 --- a/drivers/char/ipmi/ipmi_msghandler.c
31609 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31610 @@ -420,7 +420,7 @@ struct ipmi_smi {
31611 struct proc_dir_entry *proc_dir;
31612 char proc_dir_name[10];
31613
31614 - atomic_t stats[IPMI_NUM_STATS];
31615 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31616
31617 /*
31618 * run_to_completion duplicate of smb_info, smi_info
31619 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31620
31621
31622 #define ipmi_inc_stat(intf, stat) \
31623 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31624 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31625 #define ipmi_get_stat(intf, stat) \
31626 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31627 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31628
31629 static int is_lan_addr(struct ipmi_addr *addr)
31630 {
31631 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31632 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31633 init_waitqueue_head(&intf->waitq);
31634 for (i = 0; i < IPMI_NUM_STATS; i++)
31635 - atomic_set(&intf->stats[i], 0);
31636 + atomic_set_unchecked(&intf->stats[i], 0);
31637
31638 intf->proc_dir = NULL;
31639
31640 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31641 index 32a6c7e..f6966a9 100644
31642 --- a/drivers/char/ipmi/ipmi_si_intf.c
31643 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31644 @@ -275,7 +275,7 @@ struct smi_info {
31645 unsigned char slave_addr;
31646
31647 /* Counters and things for the proc filesystem. */
31648 - atomic_t stats[SI_NUM_STATS];
31649 + atomic_unchecked_t stats[SI_NUM_STATS];
31650
31651 struct task_struct *thread;
31652
31653 @@ -284,9 +284,9 @@ struct smi_info {
31654 };
31655
31656 #define smi_inc_stat(smi, stat) \
31657 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31658 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31659 #define smi_get_stat(smi, stat) \
31660 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31661 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31662
31663 #define SI_MAX_PARMS 4
31664
31665 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31666 atomic_set(&new_smi->req_events, 0);
31667 new_smi->run_to_completion = 0;
31668 for (i = 0; i < SI_NUM_STATS; i++)
31669 - atomic_set(&new_smi->stats[i], 0);
31670 + atomic_set_unchecked(&new_smi->stats[i], 0);
31671
31672 new_smi->interrupt_disabled = 1;
31673 atomic_set(&new_smi->stop_operation, 0);
31674 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31675 index 0537903..121c699 100644
31676 --- a/drivers/char/mem.c
31677 +++ b/drivers/char/mem.c
31678 @@ -18,6 +18,7 @@
31679 #include <linux/raw.h>
31680 #include <linux/tty.h>
31681 #include <linux/capability.h>
31682 +#include <linux/security.h>
31683 #include <linux/ptrace.h>
31684 #include <linux/device.h>
31685 #include <linux/highmem.h>
31686 @@ -37,6 +38,10 @@
31687
31688 #define DEVPORT_MINOR 4
31689
31690 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31691 +extern const struct file_operations grsec_fops;
31692 +#endif
31693 +
31694 static inline unsigned long size_inside_page(unsigned long start,
31695 unsigned long size)
31696 {
31697 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31698
31699 while (cursor < to) {
31700 if (!devmem_is_allowed(pfn)) {
31701 +#ifdef CONFIG_GRKERNSEC_KMEM
31702 + gr_handle_mem_readwrite(from, to);
31703 +#else
31704 printk(KERN_INFO
31705 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31706 current->comm, from, to);
31707 +#endif
31708 return 0;
31709 }
31710 cursor += PAGE_SIZE;
31711 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31712 }
31713 return 1;
31714 }
31715 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31716 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31717 +{
31718 + return 0;
31719 +}
31720 #else
31721 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31722 {
31723 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31724
31725 while (count > 0) {
31726 unsigned long remaining;
31727 + char *temp;
31728
31729 sz = size_inside_page(p, count);
31730
31731 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31732 if (!ptr)
31733 return -EFAULT;
31734
31735 - remaining = copy_to_user(buf, ptr, sz);
31736 +#ifdef CONFIG_PAX_USERCOPY
31737 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31738 + if (!temp) {
31739 + unxlate_dev_mem_ptr(p, ptr);
31740 + return -ENOMEM;
31741 + }
31742 + memcpy(temp, ptr, sz);
31743 +#else
31744 + temp = ptr;
31745 +#endif
31746 +
31747 + remaining = copy_to_user(buf, temp, sz);
31748 +
31749 +#ifdef CONFIG_PAX_USERCOPY
31750 + kfree(temp);
31751 +#endif
31752 +
31753 unxlate_dev_mem_ptr(p, ptr);
31754 if (remaining)
31755 return -EFAULT;
31756 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31757 size_t count, loff_t *ppos)
31758 {
31759 unsigned long p = *ppos;
31760 - ssize_t low_count, read, sz;
31761 + ssize_t low_count, read, sz, err = 0;
31762 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31763 - int err = 0;
31764
31765 read = 0;
31766 if (p < (unsigned long) high_memory) {
31767 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31768 }
31769 #endif
31770 while (low_count > 0) {
31771 + char *temp;
31772 +
31773 sz = size_inside_page(p, low_count);
31774
31775 /*
31776 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31777 */
31778 kbuf = xlate_dev_kmem_ptr((char *)p);
31779
31780 - if (copy_to_user(buf, kbuf, sz))
31781 +#ifdef CONFIG_PAX_USERCOPY
31782 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31783 + if (!temp)
31784 + return -ENOMEM;
31785 + memcpy(temp, kbuf, sz);
31786 +#else
31787 + temp = kbuf;
31788 +#endif
31789 +
31790 + err = copy_to_user(buf, temp, sz);
31791 +
31792 +#ifdef CONFIG_PAX_USERCOPY
31793 + kfree(temp);
31794 +#endif
31795 +
31796 + if (err)
31797 return -EFAULT;
31798 buf += sz;
31799 p += sz;
31800 @@ -833,6 +880,9 @@ static const struct memdev {
31801 #ifdef CONFIG_CRASH_DUMP
31802 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31803 #endif
31804 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31805 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31806 +#endif
31807 };
31808
31809 static int memory_open(struct inode *inode, struct file *filp)
31810 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31811 index 9df78e2..01ba9ae 100644
31812 --- a/drivers/char/nvram.c
31813 +++ b/drivers/char/nvram.c
31814 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
31815
31816 spin_unlock_irq(&rtc_lock);
31817
31818 - if (copy_to_user(buf, contents, tmp - contents))
31819 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
31820 return -EFAULT;
31821
31822 *ppos = i;
31823 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
31824 index 21721d2..4e98777 100644
31825 --- a/drivers/char/pcmcia/synclink_cs.c
31826 +++ b/drivers/char/pcmcia/synclink_cs.c
31827 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31828
31829 if (debug_level >= DEBUG_LEVEL_INFO)
31830 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
31831 - __FILE__,__LINE__, info->device_name, port->count);
31832 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
31833
31834 - WARN_ON(!port->count);
31835 + WARN_ON(!atomic_read(&port->count));
31836
31837 if (tty_port_close_start(port, tty, filp) == 0)
31838 goto cleanup;
31839 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31840 cleanup:
31841 if (debug_level >= DEBUG_LEVEL_INFO)
31842 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
31843 - tty->driver->name, port->count);
31844 + tty->driver->name, atomic_read(&port->count));
31845 }
31846
31847 /* Wait until the transmitter is empty.
31848 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31849
31850 if (debug_level >= DEBUG_LEVEL_INFO)
31851 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
31852 - __FILE__,__LINE__,tty->driver->name, port->count);
31853 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
31854
31855 /* If port is closing, signal caller to try again */
31856 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
31857 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31858 goto cleanup;
31859 }
31860 spin_lock(&port->lock);
31861 - port->count++;
31862 + atomic_inc(&port->count);
31863 spin_unlock(&port->lock);
31864 spin_unlock_irqrestore(&info->netlock, flags);
31865
31866 - if (port->count == 1) {
31867 + if (atomic_read(&port->count) == 1) {
31868 /* 1st open on this device, init hardware */
31869 retval = startup(info, tty);
31870 if (retval < 0)
31871 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
31872 unsigned short new_crctype;
31873
31874 /* return error if TTY interface open */
31875 - if (info->port.count)
31876 + if (atomic_read(&info->port.count))
31877 return -EBUSY;
31878
31879 switch (encoding)
31880 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
31881
31882 /* arbitrate between network and tty opens */
31883 spin_lock_irqsave(&info->netlock, flags);
31884 - if (info->port.count != 0 || info->netcount != 0) {
31885 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
31886 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
31887 spin_unlock_irqrestore(&info->netlock, flags);
31888 return -EBUSY;
31889 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
31890 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
31891
31892 /* return error if TTY interface open */
31893 - if (info->port.count)
31894 + if (atomic_read(&info->port.count))
31895 return -EBUSY;
31896
31897 if (cmd != SIOCWANDEV)
31898 diff --git a/drivers/char/random.c b/drivers/char/random.c
31899 index b86eae9..b9c2ed7 100644
31900 --- a/drivers/char/random.c
31901 +++ b/drivers/char/random.c
31902 @@ -272,8 +272,13 @@
31903 /*
31904 * Configuration information
31905 */
31906 +#ifdef CONFIG_GRKERNSEC_RANDNET
31907 +#define INPUT_POOL_WORDS 512
31908 +#define OUTPUT_POOL_WORDS 128
31909 +#else
31910 #define INPUT_POOL_WORDS 128
31911 #define OUTPUT_POOL_WORDS 32
31912 +#endif
31913 #define SEC_XFER_SIZE 512
31914 #define EXTRACT_SIZE 10
31915
31916 @@ -313,10 +318,17 @@ static struct poolinfo {
31917 int poolwords;
31918 int tap1, tap2, tap3, tap4, tap5;
31919 } poolinfo_table[] = {
31920 +#ifdef CONFIG_GRKERNSEC_RANDNET
31921 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31922 + { 512, 411, 308, 208, 104, 1 },
31923 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31924 + { 128, 103, 76, 51, 25, 1 },
31925 +#else
31926 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31927 { 128, 103, 76, 51, 25, 1 },
31928 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31929 { 32, 26, 20, 14, 7, 1 },
31930 +#endif
31931 #if 0
31932 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31933 { 2048, 1638, 1231, 819, 411, 1 },
31934 @@ -437,6 +449,7 @@ struct entropy_store {
31935 int entropy_count;
31936 int entropy_total;
31937 unsigned int initialized:1;
31938 + bool last_data_init;
31939 __u8 last_data[EXTRACT_SIZE];
31940 };
31941
31942 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
31943 input_rotate += i ? 7 : 14;
31944 }
31945
31946 - ACCESS_ONCE(r->input_rotate) = input_rotate;
31947 - ACCESS_ONCE(r->add_ptr) = i;
31948 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
31949 + ACCESS_ONCE_RW(r->add_ptr) = i;
31950 smp_wmb();
31951
31952 if (out)
31953 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31954 ssize_t ret = 0, i;
31955 __u8 tmp[EXTRACT_SIZE];
31956
31957 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
31958 + if (fips_enabled && !r->last_data_init)
31959 + nbytes += EXTRACT_SIZE;
31960 +
31961 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
31962 xfer_secondary_pool(r, nbytes);
31963 nbytes = account(r, nbytes, min, reserved);
31964 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31965 if (fips_enabled) {
31966 unsigned long flags;
31967
31968 +
31969 + /* prime last_data value if need be, per fips 140-2 */
31970 + if (!r->last_data_init) {
31971 + spin_lock_irqsave(&r->lock, flags);
31972 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
31973 + r->last_data_init = true;
31974 + nbytes -= EXTRACT_SIZE;
31975 + spin_unlock_irqrestore(&r->lock, flags);
31976 + extract_buf(r, tmp);
31977 + }
31978 +
31979 spin_lock_irqsave(&r->lock, flags);
31980 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
31981 panic("Hardware RNG duplicated output!\n");
31982 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
31983
31984 extract_buf(r, tmp);
31985 i = min_t(int, nbytes, EXTRACT_SIZE);
31986 - if (copy_to_user(buf, tmp, i)) {
31987 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
31988 ret = -EFAULT;
31989 break;
31990 }
31991 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
31992
31993 r->entropy_count = 0;
31994 r->entropy_total = 0;
31995 + r->last_data_init = false;
31996 mix_pool_bytes(r, &now, sizeof(now), NULL);
31997 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
31998 if (!arch_get_random_long(&rv))
31999 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32000 #include <linux/sysctl.h>
32001
32002 static int min_read_thresh = 8, min_write_thresh;
32003 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32004 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32005 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32006 static char sysctl_bootid[16];
32007
32008 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32009 index 9b4f011..b7e0a1a 100644
32010 --- a/drivers/char/sonypi.c
32011 +++ b/drivers/char/sonypi.c
32012 @@ -54,6 +54,7 @@
32013
32014 #include <asm/uaccess.h>
32015 #include <asm/io.h>
32016 +#include <asm/local.h>
32017
32018 #include <linux/sonypi.h>
32019
32020 @@ -490,7 +491,7 @@ static struct sonypi_device {
32021 spinlock_t fifo_lock;
32022 wait_queue_head_t fifo_proc_list;
32023 struct fasync_struct *fifo_async;
32024 - int open_count;
32025 + local_t open_count;
32026 int model;
32027 struct input_dev *input_jog_dev;
32028 struct input_dev *input_key_dev;
32029 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32030 static int sonypi_misc_release(struct inode *inode, struct file *file)
32031 {
32032 mutex_lock(&sonypi_device.lock);
32033 - sonypi_device.open_count--;
32034 + local_dec(&sonypi_device.open_count);
32035 mutex_unlock(&sonypi_device.lock);
32036 return 0;
32037 }
32038 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32039 {
32040 mutex_lock(&sonypi_device.lock);
32041 /* Flush input queue on first open */
32042 - if (!sonypi_device.open_count)
32043 + if (!local_read(&sonypi_device.open_count))
32044 kfifo_reset(&sonypi_device.fifo);
32045 - sonypi_device.open_count++;
32046 + local_inc(&sonypi_device.open_count);
32047 mutex_unlock(&sonypi_device.lock);
32048
32049 return 0;
32050 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32051 index 93211df..c7805f7 100644
32052 --- a/drivers/char/tpm/tpm.c
32053 +++ b/drivers/char/tpm/tpm.c
32054 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32055 chip->vendor.req_complete_val)
32056 goto out_recv;
32057
32058 - if ((status == chip->vendor.req_canceled)) {
32059 + if (status == chip->vendor.req_canceled) {
32060 dev_err(chip->dev, "Operation Canceled\n");
32061 rc = -ECANCELED;
32062 goto out;
32063 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32064 index 56051d0..11cf3b7 100644
32065 --- a/drivers/char/tpm/tpm_acpi.c
32066 +++ b/drivers/char/tpm/tpm_acpi.c
32067 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32068 virt = acpi_os_map_memory(start, len);
32069 if (!virt) {
32070 kfree(log->bios_event_log);
32071 + log->bios_event_log = NULL;
32072 printk("%s: ERROR - Unable to map memory\n", __func__);
32073 return -EIO;
32074 }
32075
32076 - memcpy_fromio(log->bios_event_log, virt, len);
32077 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32078
32079 acpi_os_unmap_memory(virt, len);
32080 return 0;
32081 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32082 index 84ddc55..1d32f1e 100644
32083 --- a/drivers/char/tpm/tpm_eventlog.c
32084 +++ b/drivers/char/tpm/tpm_eventlog.c
32085 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32086 event = addr;
32087
32088 if ((event->event_type == 0 && event->event_size == 0) ||
32089 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32090 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32091 return NULL;
32092
32093 return addr;
32094 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32095 return NULL;
32096
32097 if ((event->event_type == 0 && event->event_size == 0) ||
32098 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32099 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32100 return NULL;
32101
32102 (*pos)++;
32103 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32104 int i;
32105
32106 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32107 - seq_putc(m, data[i]);
32108 + if (!seq_putc(m, data[i]))
32109 + return -EFAULT;
32110
32111 return 0;
32112 }
32113 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32114 index 088c8fd..774c5a5 100644
32115 --- a/drivers/char/virtio_console.c
32116 +++ b/drivers/char/virtio_console.c
32117 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32118 if (to_user) {
32119 ssize_t ret;
32120
32121 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32122 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32123 if (ret)
32124 return -EFAULT;
32125 } else {
32126 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32127 if (!port_has_data(port) && !port->host_connected)
32128 return 0;
32129
32130 - return fill_readbuf(port, ubuf, count, true);
32131 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32132 }
32133
32134 static int wait_port_writable(struct port *port, bool nonblock)
32135 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
32136 index 75c0a1a..96ba8f6 100644
32137 --- a/drivers/edac/edac_mc.c
32138 +++ b/drivers/edac/edac_mc.c
32139 @@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32140 /*
32141 * Alocate and fill the csrow/channels structs
32142 */
32143 - mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
32144 + mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
32145 if (!mci->csrows)
32146 goto error;
32147 for (row = 0; row < tot_csrows; row++) {
32148 @@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32149 csr->csrow_idx = row;
32150 csr->mci = mci;
32151 csr->nr_channels = tot_channels;
32152 - csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
32153 + csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
32154 GFP_KERNEL);
32155 if (!csr->channels)
32156 goto error;
32157 @@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32158 /*
32159 * Allocate and fill the dimm structs
32160 */
32161 - mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
32162 + mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
32163 if (!mci->dimms)
32164 goto error;
32165
32166 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32167 index 1bfb207..0d059c2 100644
32168 --- a/drivers/edac/edac_pci_sysfs.c
32169 +++ b/drivers/edac/edac_pci_sysfs.c
32170 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32171 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32172 static int edac_pci_poll_msec = 1000; /* one second workq period */
32173
32174 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32175 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32176 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32177 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32178
32179 static struct kobject *edac_pci_top_main_kobj;
32180 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32181 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32182 edac_printk(KERN_CRIT, EDAC_PCI,
32183 "Signaled System Error on %s\n",
32184 pci_name(dev));
32185 - atomic_inc(&pci_nonparity_count);
32186 + atomic_inc_unchecked(&pci_nonparity_count);
32187 }
32188
32189 if (status & (PCI_STATUS_PARITY)) {
32190 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32191 "Master Data Parity Error on %s\n",
32192 pci_name(dev));
32193
32194 - atomic_inc(&pci_parity_count);
32195 + atomic_inc_unchecked(&pci_parity_count);
32196 }
32197
32198 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32199 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32200 "Detected Parity Error on %s\n",
32201 pci_name(dev));
32202
32203 - atomic_inc(&pci_parity_count);
32204 + atomic_inc_unchecked(&pci_parity_count);
32205 }
32206 }
32207
32208 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32209 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32210 "Signaled System Error on %s\n",
32211 pci_name(dev));
32212 - atomic_inc(&pci_nonparity_count);
32213 + atomic_inc_unchecked(&pci_nonparity_count);
32214 }
32215
32216 if (status & (PCI_STATUS_PARITY)) {
32217 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32218 "Master Data Parity Error on "
32219 "%s\n", pci_name(dev));
32220
32221 - atomic_inc(&pci_parity_count);
32222 + atomic_inc_unchecked(&pci_parity_count);
32223 }
32224
32225 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32226 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32227 "Detected Parity Error on %s\n",
32228 pci_name(dev));
32229
32230 - atomic_inc(&pci_parity_count);
32231 + atomic_inc_unchecked(&pci_parity_count);
32232 }
32233 }
32234 }
32235 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32236 if (!check_pci_errors)
32237 return;
32238
32239 - before_count = atomic_read(&pci_parity_count);
32240 + before_count = atomic_read_unchecked(&pci_parity_count);
32241
32242 /* scan all PCI devices looking for a Parity Error on devices and
32243 * bridges.
32244 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32245 /* Only if operator has selected panic on PCI Error */
32246 if (edac_pci_get_panic_on_pe()) {
32247 /* If the count is different 'after' from 'before' */
32248 - if (before_count != atomic_read(&pci_parity_count))
32249 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32250 panic("EDAC: PCI Parity Error");
32251 }
32252 }
32253 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32254 index 8c87a5e..a19cbd7 100644
32255 --- a/drivers/edac/mce_amd.h
32256 +++ b/drivers/edac/mce_amd.h
32257 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32258 struct amd_decoder_ops {
32259 bool (*dc_mce)(u16, u8);
32260 bool (*ic_mce)(u16, u8);
32261 -};
32262 +} __no_const;
32263
32264 void amd_report_gart_errors(bool);
32265 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32266 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32267 index 57ea7f4..789e3c3 100644
32268 --- a/drivers/firewire/core-card.c
32269 +++ b/drivers/firewire/core-card.c
32270 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32271
32272 void fw_core_remove_card(struct fw_card *card)
32273 {
32274 - struct fw_card_driver dummy_driver = dummy_driver_template;
32275 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32276
32277 card->driver->update_phy_reg(card, 4,
32278 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32279 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32280 index f8d2287..5aaf4db 100644
32281 --- a/drivers/firewire/core-cdev.c
32282 +++ b/drivers/firewire/core-cdev.c
32283 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32284 int ret;
32285
32286 if ((request->channels == 0 && request->bandwidth == 0) ||
32287 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32288 - request->bandwidth < 0)
32289 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32290 return -EINVAL;
32291
32292 r = kmalloc(sizeof(*r), GFP_KERNEL);
32293 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32294 index 28a94c7..58da63a 100644
32295 --- a/drivers/firewire/core-transaction.c
32296 +++ b/drivers/firewire/core-transaction.c
32297 @@ -38,6 +38,7 @@
32298 #include <linux/timer.h>
32299 #include <linux/types.h>
32300 #include <linux/workqueue.h>
32301 +#include <linux/sched.h>
32302
32303 #include <asm/byteorder.h>
32304
32305 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32306 index 515a42c..5ecf3ba 100644
32307 --- a/drivers/firewire/core.h
32308 +++ b/drivers/firewire/core.h
32309 @@ -111,6 +111,7 @@ struct fw_card_driver {
32310
32311 int (*stop_iso)(struct fw_iso_context *ctx);
32312 };
32313 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32314
32315 void fw_card_initialize(struct fw_card *card,
32316 const struct fw_card_driver *driver, struct device *device);
32317 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32318 index 982f1f5..d21e5da 100644
32319 --- a/drivers/firmware/dmi_scan.c
32320 +++ b/drivers/firmware/dmi_scan.c
32321 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32322 }
32323 }
32324 else {
32325 - /*
32326 - * no iounmap() for that ioremap(); it would be a no-op, but
32327 - * it's so early in setup that sucker gets confused into doing
32328 - * what it shouldn't if we actually call it.
32329 - */
32330 p = dmi_ioremap(0xF0000, 0x10000);
32331 if (p == NULL)
32332 goto error;
32333 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32334 if (buf == NULL)
32335 return -1;
32336
32337 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32338 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32339
32340 iounmap(buf);
32341 return 0;
32342 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32343 index bfd8f43..b1fe1f8 100644
32344 --- a/drivers/firmware/efivars.c
32345 +++ b/drivers/firmware/efivars.c
32346 @@ -1206,7 +1206,7 @@ out:
32347 EXPORT_SYMBOL_GPL(register_efivars);
32348
32349 static struct efivars __efivars;
32350 -static struct efivar_operations ops;
32351 +static efivar_operations_no_const ops __read_only;
32352
32353 /*
32354 * For now we register the efi subsystem with the firmware subsystem
32355 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32356 index 82d5c20..44a7177 100644
32357 --- a/drivers/gpio/gpio-vr41xx.c
32358 +++ b/drivers/gpio/gpio-vr41xx.c
32359 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32360 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32361 maskl, pendl, maskh, pendh);
32362
32363 - atomic_inc(&irq_err_count);
32364 + atomic_inc_unchecked(&irq_err_count);
32365
32366 return -EINVAL;
32367 }
32368 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32369 index 1227adf..f2301c2 100644
32370 --- a/drivers/gpu/drm/drm_crtc_helper.c
32371 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32372 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32373 struct drm_crtc *tmp;
32374 int crtc_mask = 1;
32375
32376 - WARN(!crtc, "checking null crtc?\n");
32377 + BUG_ON(!crtc);
32378
32379 dev = crtc->dev;
32380
32381 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32382 index be174ca..0bcbb71 100644
32383 --- a/drivers/gpu/drm/drm_drv.c
32384 +++ b/drivers/gpu/drm/drm_drv.c
32385 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32386 /**
32387 * Copy and IOCTL return string to user space
32388 */
32389 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32390 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32391 {
32392 int len;
32393
32394 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32395 return -ENODEV;
32396
32397 atomic_inc(&dev->ioctl_count);
32398 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32399 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32400 ++file_priv->ioctl_count;
32401
32402 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32403 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32404 index 133b413..fd68225 100644
32405 --- a/drivers/gpu/drm/drm_fops.c
32406 +++ b/drivers/gpu/drm/drm_fops.c
32407 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32408 }
32409
32410 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32411 - atomic_set(&dev->counts[i], 0);
32412 + atomic_set_unchecked(&dev->counts[i], 0);
32413
32414 dev->sigdata.lock = NULL;
32415
32416 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32417 if (drm_device_is_unplugged(dev))
32418 return -ENODEV;
32419
32420 - if (!dev->open_count++)
32421 + if (local_inc_return(&dev->open_count) == 1)
32422 need_setup = 1;
32423 mutex_lock(&dev->struct_mutex);
32424 old_mapping = dev->dev_mapping;
32425 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32426 retcode = drm_open_helper(inode, filp, dev);
32427 if (retcode)
32428 goto err_undo;
32429 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32430 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32431 if (need_setup) {
32432 retcode = drm_setup(dev);
32433 if (retcode)
32434 @@ -164,7 +164,7 @@ err_undo:
32435 iput(container_of(dev->dev_mapping, struct inode, i_data));
32436 dev->dev_mapping = old_mapping;
32437 mutex_unlock(&dev->struct_mutex);
32438 - dev->open_count--;
32439 + local_dec(&dev->open_count);
32440 return retcode;
32441 }
32442 EXPORT_SYMBOL(drm_open);
32443 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32444
32445 mutex_lock(&drm_global_mutex);
32446
32447 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32448 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32449
32450 if (dev->driver->preclose)
32451 dev->driver->preclose(dev, file_priv);
32452 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32453 * Begin inline drm_release
32454 */
32455
32456 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32457 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32458 task_pid_nr(current),
32459 (long)old_encode_dev(file_priv->minor->device),
32460 - dev->open_count);
32461 + local_read(&dev->open_count));
32462
32463 /* Release any auth tokens that might point to this file_priv,
32464 (do that under the drm_global_mutex) */
32465 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32466 * End inline drm_release
32467 */
32468
32469 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32470 - if (!--dev->open_count) {
32471 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32472 + if (local_dec_and_test(&dev->open_count)) {
32473 if (atomic_read(&dev->ioctl_count)) {
32474 DRM_ERROR("Device busy: %d\n",
32475 atomic_read(&dev->ioctl_count));
32476 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32477 index f731116..629842c 100644
32478 --- a/drivers/gpu/drm/drm_global.c
32479 +++ b/drivers/gpu/drm/drm_global.c
32480 @@ -36,7 +36,7 @@
32481 struct drm_global_item {
32482 struct mutex mutex;
32483 void *object;
32484 - int refcount;
32485 + atomic_t refcount;
32486 };
32487
32488 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32489 @@ -49,7 +49,7 @@ void drm_global_init(void)
32490 struct drm_global_item *item = &glob[i];
32491 mutex_init(&item->mutex);
32492 item->object = NULL;
32493 - item->refcount = 0;
32494 + atomic_set(&item->refcount, 0);
32495 }
32496 }
32497
32498 @@ -59,7 +59,7 @@ void drm_global_release(void)
32499 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32500 struct drm_global_item *item = &glob[i];
32501 BUG_ON(item->object != NULL);
32502 - BUG_ON(item->refcount != 0);
32503 + BUG_ON(atomic_read(&item->refcount) != 0);
32504 }
32505 }
32506
32507 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32508 void *object;
32509
32510 mutex_lock(&item->mutex);
32511 - if (item->refcount == 0) {
32512 + if (atomic_read(&item->refcount) == 0) {
32513 item->object = kzalloc(ref->size, GFP_KERNEL);
32514 if (unlikely(item->object == NULL)) {
32515 ret = -ENOMEM;
32516 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32517 goto out_err;
32518
32519 }
32520 - ++item->refcount;
32521 + atomic_inc(&item->refcount);
32522 ref->object = item->object;
32523 object = item->object;
32524 mutex_unlock(&item->mutex);
32525 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32526 struct drm_global_item *item = &glob[ref->global_type];
32527
32528 mutex_lock(&item->mutex);
32529 - BUG_ON(item->refcount == 0);
32530 + BUG_ON(atomic_read(&item->refcount) == 0);
32531 BUG_ON(ref->object != item->object);
32532 - if (--item->refcount == 0) {
32533 + if (atomic_dec_and_test(&item->refcount)) {
32534 ref->release(ref);
32535 item->object = NULL;
32536 }
32537 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32538 index d4b20ce..77a8d41 100644
32539 --- a/drivers/gpu/drm/drm_info.c
32540 +++ b/drivers/gpu/drm/drm_info.c
32541 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32542 struct drm_local_map *map;
32543 struct drm_map_list *r_list;
32544
32545 - /* Hardcoded from _DRM_FRAME_BUFFER,
32546 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32547 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32548 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32549 + static const char * const types[] = {
32550 + [_DRM_FRAME_BUFFER] = "FB",
32551 + [_DRM_REGISTERS] = "REG",
32552 + [_DRM_SHM] = "SHM",
32553 + [_DRM_AGP] = "AGP",
32554 + [_DRM_SCATTER_GATHER] = "SG",
32555 + [_DRM_CONSISTENT] = "PCI",
32556 + [_DRM_GEM] = "GEM" };
32557 const char *type;
32558 int i;
32559
32560 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32561 map = r_list->map;
32562 if (!map)
32563 continue;
32564 - if (map->type < 0 || map->type > 5)
32565 + if (map->type >= ARRAY_SIZE(types))
32566 type = "??";
32567 else
32568 type = types[map->type];
32569 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32570 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32571 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32572 vma->vm_flags & VM_IO ? 'i' : '-',
32573 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32574 + 0);
32575 +#else
32576 vma->vm_pgoff);
32577 +#endif
32578
32579 #if defined(__i386__)
32580 pgprot = pgprot_val(vma->vm_page_prot);
32581 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32582 index 2f4c434..764794b 100644
32583 --- a/drivers/gpu/drm/drm_ioc32.c
32584 +++ b/drivers/gpu/drm/drm_ioc32.c
32585 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32586 request = compat_alloc_user_space(nbytes);
32587 if (!access_ok(VERIFY_WRITE, request, nbytes))
32588 return -EFAULT;
32589 - list = (struct drm_buf_desc *) (request + 1);
32590 + list = (struct drm_buf_desc __user *) (request + 1);
32591
32592 if (__put_user(count, &request->count)
32593 || __put_user(list, &request->list))
32594 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32595 request = compat_alloc_user_space(nbytes);
32596 if (!access_ok(VERIFY_WRITE, request, nbytes))
32597 return -EFAULT;
32598 - list = (struct drm_buf_pub *) (request + 1);
32599 + list = (struct drm_buf_pub __user *) (request + 1);
32600
32601 if (__put_user(count, &request->count)
32602 || __put_user(list, &request->list))
32603 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32604 index 23dd975..63e9801 100644
32605 --- a/drivers/gpu/drm/drm_ioctl.c
32606 +++ b/drivers/gpu/drm/drm_ioctl.c
32607 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32608 stats->data[i].value =
32609 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32610 else
32611 - stats->data[i].value = atomic_read(&dev->counts[i]);
32612 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32613 stats->data[i].type = dev->types[i];
32614 }
32615
32616 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32617 index d752c96..fe08455 100644
32618 --- a/drivers/gpu/drm/drm_lock.c
32619 +++ b/drivers/gpu/drm/drm_lock.c
32620 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32621 if (drm_lock_take(&master->lock, lock->context)) {
32622 master->lock.file_priv = file_priv;
32623 master->lock.lock_time = jiffies;
32624 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32625 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32626 break; /* Got lock */
32627 }
32628
32629 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32630 return -EINVAL;
32631 }
32632
32633 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32634 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32635
32636 if (drm_lock_free(&master->lock, lock->context)) {
32637 /* FIXME: Should really bail out here. */
32638 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32639 index c236fd2..6b5f2e7 100644
32640 --- a/drivers/gpu/drm/drm_stub.c
32641 +++ b/drivers/gpu/drm/drm_stub.c
32642 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32643
32644 drm_device_set_unplugged(dev);
32645
32646 - if (dev->open_count == 0) {
32647 + if (local_read(&dev->open_count) == 0) {
32648 drm_put_dev(dev);
32649 }
32650 mutex_unlock(&drm_global_mutex);
32651 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32652 index 004ecdf..db1f6e0 100644
32653 --- a/drivers/gpu/drm/i810/i810_dma.c
32654 +++ b/drivers/gpu/drm/i810/i810_dma.c
32655 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32656 dma->buflist[vertex->idx],
32657 vertex->discard, vertex->used);
32658
32659 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32660 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32661 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32662 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32663 sarea_priv->last_enqueue = dev_priv->counter - 1;
32664 sarea_priv->last_dispatch = (int)hw_status[5];
32665
32666 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32667 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32668 mc->last_render);
32669
32670 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32671 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32672 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32673 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32674 sarea_priv->last_enqueue = dev_priv->counter - 1;
32675 sarea_priv->last_dispatch = (int)hw_status[5];
32676
32677 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32678 index 6e0acad..93c8289 100644
32679 --- a/drivers/gpu/drm/i810/i810_drv.h
32680 +++ b/drivers/gpu/drm/i810/i810_drv.h
32681 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32682 int page_flipping;
32683
32684 wait_queue_head_t irq_queue;
32685 - atomic_t irq_received;
32686 - atomic_t irq_emitted;
32687 + atomic_unchecked_t irq_received;
32688 + atomic_unchecked_t irq_emitted;
32689
32690 int front_offset;
32691 } drm_i810_private_t;
32692 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32693 index 3a1a495..995c093 100644
32694 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32695 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32696 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32697 I915_READ(GTIMR));
32698 }
32699 seq_printf(m, "Interrupts received: %d\n",
32700 - atomic_read(&dev_priv->irq_received));
32701 + atomic_read_unchecked(&dev_priv->irq_received));
32702 for_each_ring(ring, dev_priv, i) {
32703 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32704 seq_printf(m,
32705 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32706 index 61ae104..f8a4bc1 100644
32707 --- a/drivers/gpu/drm/i915/i915_dma.c
32708 +++ b/drivers/gpu/drm/i915/i915_dma.c
32709 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32710 bool can_switch;
32711
32712 spin_lock(&dev->count_lock);
32713 - can_switch = (dev->open_count == 0);
32714 + can_switch = (local_read(&dev->open_count) == 0);
32715 spin_unlock(&dev->count_lock);
32716 return can_switch;
32717 }
32718 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32719 index 92f1750..3beba74 100644
32720 --- a/drivers/gpu/drm/i915/i915_drv.h
32721 +++ b/drivers/gpu/drm/i915/i915_drv.h
32722 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32723
32724 struct resource mch_res;
32725
32726 - atomic_t irq_received;
32727 + atomic_unchecked_t irq_received;
32728
32729 /* protects the irq masks */
32730 spinlock_t irq_lock;
32731 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32732 * will be page flipped away on the next vblank. When it
32733 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32734 */
32735 - atomic_t pending_flip;
32736 + atomic_unchecked_t pending_flip;
32737 };
32738
32739 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32740 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32741 struct drm_i915_private *dev_priv, unsigned port);
32742 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32743 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32744 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32745 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32746 {
32747 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32748 }
32749 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32750 index 67036e9..b9f1357 100644
32751 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32752 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32753 @@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32754 i915_gem_clflush_object(obj);
32755
32756 if (obj->base.pending_write_domain)
32757 - flips |= atomic_read(&obj->pending_flip);
32758 + flips |= atomic_read_unchecked(&obj->pending_flip);
32759
32760 flush_domains |= obj->base.write_domain;
32761 }
32762 @@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32763
32764 static int
32765 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32766 - int count)
32767 + unsigned int count)
32768 {
32769 - int i;
32770 + unsigned int i;
32771
32772 for (i = 0; i < count; i++) {
32773 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32774 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32775 index dc29ace..137d83a 100644
32776 --- a/drivers/gpu/drm/i915/i915_irq.c
32777 +++ b/drivers/gpu/drm/i915/i915_irq.c
32778 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32779 u32 pipe_stats[I915_MAX_PIPES];
32780 bool blc_event;
32781
32782 - atomic_inc(&dev_priv->irq_received);
32783 + atomic_inc_unchecked(&dev_priv->irq_received);
32784
32785 while (true) {
32786 iir = I915_READ(VLV_IIR);
32787 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32788 irqreturn_t ret = IRQ_NONE;
32789 int i;
32790
32791 - atomic_inc(&dev_priv->irq_received);
32792 + atomic_inc_unchecked(&dev_priv->irq_received);
32793
32794 /* disable master interrupt before clearing iir */
32795 de_ier = I915_READ(DEIER);
32796 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32797 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32798 u32 hotplug_mask;
32799
32800 - atomic_inc(&dev_priv->irq_received);
32801 + atomic_inc_unchecked(&dev_priv->irq_received);
32802
32803 /* disable master interrupt before clearing iir */
32804 de_ier = I915_READ(DEIER);
32805 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32806 {
32807 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32808
32809 - atomic_set(&dev_priv->irq_received, 0);
32810 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32811
32812 I915_WRITE(HWSTAM, 0xeffe);
32813
32814 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
32815 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32816 int pipe;
32817
32818 - atomic_set(&dev_priv->irq_received, 0);
32819 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32820
32821 /* VLV magic */
32822 I915_WRITE(VLV_IMR, 0);
32823 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
32824 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32825 int pipe;
32826
32827 - atomic_set(&dev_priv->irq_received, 0);
32828 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32829
32830 for_each_pipe(pipe)
32831 I915_WRITE(PIPESTAT(pipe), 0);
32832 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
32833 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
32834 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
32835
32836 - atomic_inc(&dev_priv->irq_received);
32837 + atomic_inc_unchecked(&dev_priv->irq_received);
32838
32839 iir = I915_READ16(IIR);
32840 if (iir == 0)
32841 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
32842 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32843 int pipe;
32844
32845 - atomic_set(&dev_priv->irq_received, 0);
32846 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32847
32848 if (I915_HAS_HOTPLUG(dev)) {
32849 I915_WRITE(PORT_HOTPLUG_EN, 0);
32850 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
32851 };
32852 int pipe, ret = IRQ_NONE;
32853
32854 - atomic_inc(&dev_priv->irq_received);
32855 + atomic_inc_unchecked(&dev_priv->irq_received);
32856
32857 iir = I915_READ(IIR);
32858 do {
32859 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
32860 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32861 int pipe;
32862
32863 - atomic_set(&dev_priv->irq_received, 0);
32864 + atomic_set_unchecked(&dev_priv->irq_received, 0);
32865
32866 I915_WRITE(PORT_HOTPLUG_EN, 0);
32867 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
32868 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
32869 int irq_received;
32870 int ret = IRQ_NONE, pipe;
32871
32872 - atomic_inc(&dev_priv->irq_received);
32873 + atomic_inc_unchecked(&dev_priv->irq_received);
32874
32875 iir = I915_READ(IIR);
32876
32877 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
32878 index 4d3c7c6..eaac87b 100644
32879 --- a/drivers/gpu/drm/i915/intel_display.c
32880 +++ b/drivers/gpu/drm/i915/intel_display.c
32881 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
32882
32883 wait_event(dev_priv->pending_flip_queue,
32884 atomic_read(&dev_priv->mm.wedged) ||
32885 - atomic_read(&obj->pending_flip) == 0);
32886 + atomic_read_unchecked(&obj->pending_flip) == 0);
32887
32888 /* Big Hammer, we also need to ensure that any pending
32889 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
32890 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
32891
32892 obj = work->old_fb_obj;
32893
32894 - atomic_clear_mask(1 << intel_crtc->plane,
32895 - &obj->pending_flip.counter);
32896 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
32897 wake_up(&dev_priv->pending_flip_queue);
32898
32899 queue_work(dev_priv->wq, &work->work);
32900 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32901 /* Block clients from rendering to the new back buffer until
32902 * the flip occurs and the object is no longer visible.
32903 */
32904 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32905 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32906 atomic_inc(&intel_crtc->unpin_work_count);
32907
32908 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
32909 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32910
32911 cleanup_pending:
32912 atomic_dec(&intel_crtc->unpin_work_count);
32913 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32914 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32915 drm_gem_object_unreference(&work->old_fb_obj->base);
32916 drm_gem_object_unreference(&obj->base);
32917 mutex_unlock(&dev->struct_mutex);
32918 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
32919 index 54558a0..2d97005 100644
32920 --- a/drivers/gpu/drm/mga/mga_drv.h
32921 +++ b/drivers/gpu/drm/mga/mga_drv.h
32922 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
32923 u32 clear_cmd;
32924 u32 maccess;
32925
32926 - atomic_t vbl_received; /**< Number of vblanks received. */
32927 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
32928 wait_queue_head_t fence_queue;
32929 - atomic_t last_fence_retired;
32930 + atomic_unchecked_t last_fence_retired;
32931 u32 next_fence_to_post;
32932
32933 unsigned int fb_cpp;
32934 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
32935 index 598c281..60d590e 100644
32936 --- a/drivers/gpu/drm/mga/mga_irq.c
32937 +++ b/drivers/gpu/drm/mga/mga_irq.c
32938 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
32939 if (crtc != 0)
32940 return 0;
32941
32942 - return atomic_read(&dev_priv->vbl_received);
32943 + return atomic_read_unchecked(&dev_priv->vbl_received);
32944 }
32945
32946
32947 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32948 /* VBLANK interrupt */
32949 if (status & MGA_VLINEPEN) {
32950 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
32951 - atomic_inc(&dev_priv->vbl_received);
32952 + atomic_inc_unchecked(&dev_priv->vbl_received);
32953 drm_handle_vblank(dev, 0);
32954 handled = 1;
32955 }
32956 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32957 if ((prim_start & ~0x03) != (prim_end & ~0x03))
32958 MGA_WRITE(MGA_PRIMEND, prim_end);
32959
32960 - atomic_inc(&dev_priv->last_fence_retired);
32961 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
32962 DRM_WAKEUP(&dev_priv->fence_queue);
32963 handled = 1;
32964 }
32965 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
32966 * using fences.
32967 */
32968 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
32969 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
32970 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
32971 - *sequence) <= (1 << 23)));
32972
32973 *sequence = cur_fence;
32974 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
32975 index 09fdef2..57f5c3b 100644
32976 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
32977 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
32978 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
32979 struct bit_table {
32980 const char id;
32981 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
32982 -};
32983 +} __no_const;
32984
32985 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
32986
32987 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
32988 index a101699..a163f0a 100644
32989 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
32990 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
32991 @@ -80,7 +80,7 @@ struct nouveau_drm {
32992 struct drm_global_reference mem_global_ref;
32993 struct ttm_bo_global_ref bo_global_ref;
32994 struct ttm_bo_device bdev;
32995 - atomic_t validate_sequence;
32996 + atomic_unchecked_t validate_sequence;
32997 int (*move)(struct nouveau_channel *,
32998 struct ttm_buffer_object *,
32999 struct ttm_mem_reg *, struct ttm_mem_reg *);
33000 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33001 index cdb83ac..27f0a16 100644
33002 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33003 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33004 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33005 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33006 struct nouveau_channel *);
33007 u32 (*read)(struct nouveau_channel *);
33008 -};
33009 +} __no_const;
33010
33011 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33012
33013 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33014 index 5e2f521..0d21436 100644
33015 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33016 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33017 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33018 int trycnt = 0;
33019 int ret, i;
33020
33021 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33022 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33023 retry:
33024 if (++trycnt > 100000) {
33025 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33026 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33027 index 6f0ac64..9c2dfb4 100644
33028 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33029 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33030 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33031 bool can_switch;
33032
33033 spin_lock(&dev->count_lock);
33034 - can_switch = (dev->open_count == 0);
33035 + can_switch = (local_read(&dev->open_count) == 0);
33036 spin_unlock(&dev->count_lock);
33037 return can_switch;
33038 }
33039 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33040 index 9f6f55c..30e3a29 100644
33041 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
33042 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33043 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33044 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33045 evo->object->oclass->ofuncs =
33046 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33047 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33048 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33049 - evo->object->oclass->ofuncs->rd08 =
33050 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33051 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33052 + *(void**)&evo->object->oclass->ofuncs->rd08 =
33053 ioremap(pci_resource_start(dev->pdev, 0) +
33054 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33055 return 0;
33056 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33057 index b562b59..9d725a8 100644
33058 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
33059 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33060 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33061 }
33062
33063 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33064 - struct dp_train_func func = {
33065 + static struct dp_train_func func = {
33066 .link_set = nv50_sor_dp_link_set,
33067 .train_set = nv50_sor_dp_train_set,
33068 .train_adj = nv50_sor_dp_train_adj
33069 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33070 index c402fca..f1d694b 100644
33071 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
33072 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33073 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33074 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33075
33076 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33077 - struct dp_train_func func = {
33078 + static struct dp_train_func func = {
33079 .link_set = nvd0_sor_dp_link_set,
33080 .train_set = nvd0_sor_dp_train_set,
33081 .train_adj = nvd0_sor_dp_train_adj
33082 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33083 index d4660cf..70dbe65 100644
33084 --- a/drivers/gpu/drm/r128/r128_cce.c
33085 +++ b/drivers/gpu/drm/r128/r128_cce.c
33086 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33087
33088 /* GH: Simple idle check.
33089 */
33090 - atomic_set(&dev_priv->idle_count, 0);
33091 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33092
33093 /* We don't support anything other than bus-mastering ring mode,
33094 * but the ring can be in either AGP or PCI space for the ring
33095 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33096 index 930c71b..499aded 100644
33097 --- a/drivers/gpu/drm/r128/r128_drv.h
33098 +++ b/drivers/gpu/drm/r128/r128_drv.h
33099 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33100 int is_pci;
33101 unsigned long cce_buffers_offset;
33102
33103 - atomic_t idle_count;
33104 + atomic_unchecked_t idle_count;
33105
33106 int page_flipping;
33107 int current_page;
33108 u32 crtc_offset;
33109 u32 crtc_offset_cntl;
33110
33111 - atomic_t vbl_received;
33112 + atomic_unchecked_t vbl_received;
33113
33114 u32 color_fmt;
33115 unsigned int front_offset;
33116 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33117 index 2ea4f09..d391371 100644
33118 --- a/drivers/gpu/drm/r128/r128_irq.c
33119 +++ b/drivers/gpu/drm/r128/r128_irq.c
33120 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33121 if (crtc != 0)
33122 return 0;
33123
33124 - return atomic_read(&dev_priv->vbl_received);
33125 + return atomic_read_unchecked(&dev_priv->vbl_received);
33126 }
33127
33128 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33129 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33130 /* VBLANK interrupt */
33131 if (status & R128_CRTC_VBLANK_INT) {
33132 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33133 - atomic_inc(&dev_priv->vbl_received);
33134 + atomic_inc_unchecked(&dev_priv->vbl_received);
33135 drm_handle_vblank(dev, 0);
33136 return IRQ_HANDLED;
33137 }
33138 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33139 index 19bb7e6..de7e2a2 100644
33140 --- a/drivers/gpu/drm/r128/r128_state.c
33141 +++ b/drivers/gpu/drm/r128/r128_state.c
33142 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33143
33144 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33145 {
33146 - if (atomic_read(&dev_priv->idle_count) == 0)
33147 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33148 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33149 else
33150 - atomic_set(&dev_priv->idle_count, 0);
33151 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33152 }
33153
33154 #endif
33155 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33156 index 5a82b6b..9e69c73 100644
33157 --- a/drivers/gpu/drm/radeon/mkregtable.c
33158 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33159 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33160 regex_t mask_rex;
33161 regmatch_t match[4];
33162 char buf[1024];
33163 - size_t end;
33164 + long end;
33165 int len;
33166 int done = 0;
33167 int r;
33168 unsigned o;
33169 struct offset *offset;
33170 char last_reg_s[10];
33171 - int last_reg;
33172 + unsigned long last_reg;
33173
33174 if (regcomp
33175 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33176 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33177 index 008d645..de03849 100644
33178 --- a/drivers/gpu/drm/radeon/radeon_device.c
33179 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33180 @@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33181 bool can_switch;
33182
33183 spin_lock(&dev->count_lock);
33184 - can_switch = (dev->open_count == 0);
33185 + can_switch = (local_read(&dev->open_count) == 0);
33186 spin_unlock(&dev->count_lock);
33187 return can_switch;
33188 }
33189 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33190 index a1b59ca..86f2d44 100644
33191 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33192 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33193 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33194
33195 /* SW interrupt */
33196 wait_queue_head_t swi_queue;
33197 - atomic_t swi_emitted;
33198 + atomic_unchecked_t swi_emitted;
33199 int vblank_crtc;
33200 uint32_t irq_enable_reg;
33201 uint32_t r500_disp_irq_reg;
33202 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33203 index c180df8..cd80dd2d 100644
33204 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33205 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33206 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33207 request = compat_alloc_user_space(sizeof(*request));
33208 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33209 || __put_user(req32.param, &request->param)
33210 - || __put_user((void __user *)(unsigned long)req32.value,
33211 + || __put_user((unsigned long)req32.value,
33212 &request->value))
33213 return -EFAULT;
33214
33215 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33216 index e771033..a0bc6b3 100644
33217 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33218 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33219 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33220 unsigned int ret;
33221 RING_LOCALS;
33222
33223 - atomic_inc(&dev_priv->swi_emitted);
33224 - ret = atomic_read(&dev_priv->swi_emitted);
33225 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33226 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33227
33228 BEGIN_RING(4);
33229 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33230 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33231 drm_radeon_private_t *dev_priv =
33232 (drm_radeon_private_t *) dev->dev_private;
33233
33234 - atomic_set(&dev_priv->swi_emitted, 0);
33235 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33236 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33237
33238 dev->max_vblank_count = 0x001fffff;
33239 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33240 index 8e9057b..af6dacb 100644
33241 --- a/drivers/gpu/drm/radeon/radeon_state.c
33242 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33243 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33244 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33245 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33246
33247 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33248 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33249 sarea_priv->nbox * sizeof(depth_boxes[0])))
33250 return -EFAULT;
33251
33252 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33253 {
33254 drm_radeon_private_t *dev_priv = dev->dev_private;
33255 drm_radeon_getparam_t *param = data;
33256 - int value;
33257 + int value = 0;
33258
33259 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33260
33261 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33262 index 5ebe1b3..cf69ba0 100644
33263 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33264 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33265 @@ -781,7 +781,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
33266 man->size = size >> PAGE_SHIFT;
33267 }
33268
33269 -static struct vm_operations_struct radeon_ttm_vm_ops;
33270 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
33271 static const struct vm_operations_struct *ttm_vm_ops = NULL;
33272
33273 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33274 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33275 }
33276 if (unlikely(ttm_vm_ops == NULL)) {
33277 ttm_vm_ops = vma->vm_ops;
33278 + pax_open_kernel();
33279 radeon_ttm_vm_ops = *ttm_vm_ops;
33280 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33281 + pax_close_kernel();
33282 }
33283 vma->vm_ops = &radeon_ttm_vm_ops;
33284 return 0;
33285 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33286 index 5706d2a..17aedaa 100644
33287 --- a/drivers/gpu/drm/radeon/rs690.c
33288 +++ b/drivers/gpu/drm/radeon/rs690.c
33289 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33290 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33291 rdev->pm.sideport_bandwidth.full)
33292 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33293 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33294 + read_delay_latency.full = dfixed_const(800 * 1000);
33295 read_delay_latency.full = dfixed_div(read_delay_latency,
33296 rdev->pm.igp_sideport_mclk);
33297 + a.full = dfixed_const(370);
33298 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33299 } else {
33300 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33301 rdev->pm.k8_bandwidth.full)
33302 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33303 index bd2a3b4..122d9ad 100644
33304 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33305 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33306 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33307 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33308 struct shrink_control *sc)
33309 {
33310 - static atomic_t start_pool = ATOMIC_INIT(0);
33311 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33312 unsigned i;
33313 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33314 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33315 struct ttm_page_pool *pool;
33316 int shrink_pages = sc->nr_to_scan;
33317
33318 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33319 index 893a650..6190d3b 100644
33320 --- a/drivers/gpu/drm/via/via_drv.h
33321 +++ b/drivers/gpu/drm/via/via_drv.h
33322 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33323 typedef uint32_t maskarray_t[5];
33324
33325 typedef struct drm_via_irq {
33326 - atomic_t irq_received;
33327 + atomic_unchecked_t irq_received;
33328 uint32_t pending_mask;
33329 uint32_t enable_mask;
33330 wait_queue_head_t irq_queue;
33331 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33332 struct timeval last_vblank;
33333 int last_vblank_valid;
33334 unsigned usec_per_vblank;
33335 - atomic_t vbl_received;
33336 + atomic_unchecked_t vbl_received;
33337 drm_via_state_t hc_state;
33338 char pci_buf[VIA_PCI_BUF_SIZE];
33339 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33340 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33341 index ac98964..5dbf512 100644
33342 --- a/drivers/gpu/drm/via/via_irq.c
33343 +++ b/drivers/gpu/drm/via/via_irq.c
33344 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33345 if (crtc != 0)
33346 return 0;
33347
33348 - return atomic_read(&dev_priv->vbl_received);
33349 + return atomic_read_unchecked(&dev_priv->vbl_received);
33350 }
33351
33352 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33353 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33354
33355 status = VIA_READ(VIA_REG_INTERRUPT);
33356 if (status & VIA_IRQ_VBLANK_PENDING) {
33357 - atomic_inc(&dev_priv->vbl_received);
33358 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33359 + atomic_inc_unchecked(&dev_priv->vbl_received);
33360 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33361 do_gettimeofday(&cur_vblank);
33362 if (dev_priv->last_vblank_valid) {
33363 dev_priv->usec_per_vblank =
33364 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33365 dev_priv->last_vblank = cur_vblank;
33366 dev_priv->last_vblank_valid = 1;
33367 }
33368 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33369 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33370 DRM_DEBUG("US per vblank is: %u\n",
33371 dev_priv->usec_per_vblank);
33372 }
33373 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33374
33375 for (i = 0; i < dev_priv->num_irqs; ++i) {
33376 if (status & cur_irq->pending_mask) {
33377 - atomic_inc(&cur_irq->irq_received);
33378 + atomic_inc_unchecked(&cur_irq->irq_received);
33379 DRM_WAKEUP(&cur_irq->irq_queue);
33380 handled = 1;
33381 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33382 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33383 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33384 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33385 masks[irq][4]));
33386 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33387 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33388 } else {
33389 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33390 (((cur_irq_sequence =
33391 - atomic_read(&cur_irq->irq_received)) -
33392 + atomic_read_unchecked(&cur_irq->irq_received)) -
33393 *sequence) <= (1 << 23)));
33394 }
33395 *sequence = cur_irq_sequence;
33396 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33397 }
33398
33399 for (i = 0; i < dev_priv->num_irqs; ++i) {
33400 - atomic_set(&cur_irq->irq_received, 0);
33401 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33402 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33403 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33404 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33405 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33406 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33407 case VIA_IRQ_RELATIVE:
33408 irqwait->request.sequence +=
33409 - atomic_read(&cur_irq->irq_received);
33410 + atomic_read_unchecked(&cur_irq->irq_received);
33411 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33412 case VIA_IRQ_ABSOLUTE:
33413 break;
33414 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33415 index 88a179e..57fe50481c 100644
33416 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33417 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33418 @@ -263,7 +263,7 @@ struct vmw_private {
33419 * Fencing and IRQs.
33420 */
33421
33422 - atomic_t marker_seq;
33423 + atomic_unchecked_t marker_seq;
33424 wait_queue_head_t fence_queue;
33425 wait_queue_head_t fifo_queue;
33426 int fence_queue_waiters; /* Protected by hw_mutex */
33427 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33428 index 3eb1486..0a47ee9 100644
33429 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33430 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33431 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33432 (unsigned int) min,
33433 (unsigned int) fifo->capabilities);
33434
33435 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33436 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33437 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33438 vmw_marker_queue_init(&fifo->marker_queue);
33439 return vmw_fifo_send_fence(dev_priv, &dummy);
33440 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33441 if (reserveable)
33442 iowrite32(bytes, fifo_mem +
33443 SVGA_FIFO_RESERVED);
33444 - return fifo_mem + (next_cmd >> 2);
33445 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33446 } else {
33447 need_bounce = true;
33448 }
33449 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33450
33451 fm = vmw_fifo_reserve(dev_priv, bytes);
33452 if (unlikely(fm == NULL)) {
33453 - *seqno = atomic_read(&dev_priv->marker_seq);
33454 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33455 ret = -ENOMEM;
33456 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33457 false, 3*HZ);
33458 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33459 }
33460
33461 do {
33462 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33463 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33464 } while (*seqno == 0);
33465
33466 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33467 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33468 index 4640adb..e1384ed 100644
33469 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33470 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33471 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33472 * emitted. Then the fence is stale and signaled.
33473 */
33474
33475 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33476 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33477 > VMW_FENCE_WRAP);
33478
33479 return ret;
33480 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33481
33482 if (fifo_idle)
33483 down_read(&fifo_state->rwsem);
33484 - signal_seq = atomic_read(&dev_priv->marker_seq);
33485 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33486 ret = 0;
33487
33488 for (;;) {
33489 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33490 index 8a8725c..afed796 100644
33491 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33492 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33493 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33494 while (!vmw_lag_lt(queue, us)) {
33495 spin_lock(&queue->lock);
33496 if (list_empty(&queue->head))
33497 - seqno = atomic_read(&dev_priv->marker_seq);
33498 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33499 else {
33500 marker = list_first_entry(&queue->head,
33501 struct vmw_marker, head);
33502 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33503 index 52146db..ae33762 100644
33504 --- a/drivers/hid/hid-core.c
33505 +++ b/drivers/hid/hid-core.c
33506 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33507
33508 int hid_add_device(struct hid_device *hdev)
33509 {
33510 - static atomic_t id = ATOMIC_INIT(0);
33511 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33512 int ret;
33513
33514 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33515 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33516 /* XXX hack, any other cleaner solution after the driver core
33517 * is converted to allow more than 20 bytes as the device name? */
33518 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33519 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33520 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33521
33522 hid_debug_register(hdev, dev_name(&hdev->dev));
33523 ret = device_add(&hdev->dev);
33524 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33525 index eec3291..8ed706b 100644
33526 --- a/drivers/hid/hid-wiimote-debug.c
33527 +++ b/drivers/hid/hid-wiimote-debug.c
33528 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33529 else if (size == 0)
33530 return -EIO;
33531
33532 - if (copy_to_user(u, buf, size))
33533 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33534 return -EFAULT;
33535
33536 *off += size;
33537 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33538 index 14599e2..711c965 100644
33539 --- a/drivers/hid/usbhid/hiddev.c
33540 +++ b/drivers/hid/usbhid/hiddev.c
33541 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33542 break;
33543
33544 case HIDIOCAPPLICATION:
33545 - if (arg < 0 || arg >= hid->maxapplication)
33546 + if (arg >= hid->maxapplication)
33547 break;
33548
33549 for (i = 0; i < hid->maxcollection; i++)
33550 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33551 index f4c3d28..82f45a9 100644
33552 --- a/drivers/hv/channel.c
33553 +++ b/drivers/hv/channel.c
33554 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33555 int ret = 0;
33556 int t;
33557
33558 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33559 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33560 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33561 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33562
33563 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33564 if (ret)
33565 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33566 index 3648f8f..30ef30d 100644
33567 --- a/drivers/hv/hv.c
33568 +++ b/drivers/hv/hv.c
33569 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33570 u64 output_address = (output) ? virt_to_phys(output) : 0;
33571 u32 output_address_hi = output_address >> 32;
33572 u32 output_address_lo = output_address & 0xFFFFFFFF;
33573 - void *hypercall_page = hv_context.hypercall_page;
33574 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33575
33576 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33577 "=a"(hv_status_lo) : "d" (control_hi),
33578 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33579 index d8d1fad..b91caf7 100644
33580 --- a/drivers/hv/hyperv_vmbus.h
33581 +++ b/drivers/hv/hyperv_vmbus.h
33582 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33583 struct vmbus_connection {
33584 enum vmbus_connect_state conn_state;
33585
33586 - atomic_t next_gpadl_handle;
33587 + atomic_unchecked_t next_gpadl_handle;
33588
33589 /*
33590 * Represents channel interrupts. Each bit position represents a
33591 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33592 index 8e1a9ec..4687821 100644
33593 --- a/drivers/hv/vmbus_drv.c
33594 +++ b/drivers/hv/vmbus_drv.c
33595 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33596 {
33597 int ret = 0;
33598
33599 - static atomic_t device_num = ATOMIC_INIT(0);
33600 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33601
33602 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33603 - atomic_inc_return(&device_num));
33604 + atomic_inc_return_unchecked(&device_num));
33605
33606 child_device_obj->device.bus = &hv_bus;
33607 child_device_obj->device.parent = &hv_acpi_dev->dev;
33608 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33609 index 07a0c1a..0cac334 100644
33610 --- a/drivers/hwmon/sht15.c
33611 +++ b/drivers/hwmon/sht15.c
33612 @@ -169,7 +169,7 @@ struct sht15_data {
33613 int supply_uV;
33614 bool supply_uV_valid;
33615 struct work_struct update_supply_work;
33616 - atomic_t interrupt_handled;
33617 + atomic_unchecked_t interrupt_handled;
33618 };
33619
33620 /**
33621 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33622 return ret;
33623
33624 gpio_direction_input(data->pdata->gpio_data);
33625 - atomic_set(&data->interrupt_handled, 0);
33626 + atomic_set_unchecked(&data->interrupt_handled, 0);
33627
33628 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33629 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33630 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33631 /* Only relevant if the interrupt hasn't occurred. */
33632 - if (!atomic_read(&data->interrupt_handled))
33633 + if (!atomic_read_unchecked(&data->interrupt_handled))
33634 schedule_work(&data->read_work);
33635 }
33636 ret = wait_event_timeout(data->wait_queue,
33637 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33638
33639 /* First disable the interrupt */
33640 disable_irq_nosync(irq);
33641 - atomic_inc(&data->interrupt_handled);
33642 + atomic_inc_unchecked(&data->interrupt_handled);
33643 /* Then schedule a reading work struct */
33644 if (data->state != SHT15_READING_NOTHING)
33645 schedule_work(&data->read_work);
33646 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33647 * If not, then start the interrupt again - care here as could
33648 * have gone low in meantime so verify it hasn't!
33649 */
33650 - atomic_set(&data->interrupt_handled, 0);
33651 + atomic_set_unchecked(&data->interrupt_handled, 0);
33652 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33653 /* If still not occurred or another handler was scheduled */
33654 if (gpio_get_value(data->pdata->gpio_data)
33655 - || atomic_read(&data->interrupt_handled))
33656 + || atomic_read_unchecked(&data->interrupt_handled))
33657 return;
33658 }
33659
33660 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33661 index 378fcb5..5e91fa8 100644
33662 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33663 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33664 @@ -43,7 +43,7 @@
33665 extern struct i2c_adapter amd756_smbus;
33666
33667 static struct i2c_adapter *s4882_adapter;
33668 -static struct i2c_algorithm *s4882_algo;
33669 +static i2c_algorithm_no_const *s4882_algo;
33670
33671 /* Wrapper access functions for multiplexed SMBus */
33672 static DEFINE_MUTEX(amd756_lock);
33673 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33674 index 29015eb..af2d8e9 100644
33675 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33676 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33677 @@ -41,7 +41,7 @@
33678 extern struct i2c_adapter *nforce2_smbus;
33679
33680 static struct i2c_adapter *s4985_adapter;
33681 -static struct i2c_algorithm *s4985_algo;
33682 +static i2c_algorithm_no_const *s4985_algo;
33683
33684 /* Wrapper access functions for multiplexed SMBus */
33685 static DEFINE_MUTEX(nforce2_lock);
33686 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33687 index 8126824..55a2798 100644
33688 --- a/drivers/ide/ide-cd.c
33689 +++ b/drivers/ide/ide-cd.c
33690 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33691 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33692 if ((unsigned long)buf & alignment
33693 || blk_rq_bytes(rq) & q->dma_pad_mask
33694 - || object_is_on_stack(buf))
33695 + || object_starts_on_stack(buf))
33696 drive->dma = 0;
33697 }
33698 }
33699 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33700 index 394fea2..c833880 100644
33701 --- a/drivers/infiniband/core/cm.c
33702 +++ b/drivers/infiniband/core/cm.c
33703 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33704
33705 struct cm_counter_group {
33706 struct kobject obj;
33707 - atomic_long_t counter[CM_ATTR_COUNT];
33708 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33709 };
33710
33711 struct cm_counter_attribute {
33712 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33713 struct ib_mad_send_buf *msg = NULL;
33714 int ret;
33715
33716 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33717 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33718 counter[CM_REQ_COUNTER]);
33719
33720 /* Quick state check to discard duplicate REQs. */
33721 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33722 if (!cm_id_priv)
33723 return;
33724
33725 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33726 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33727 counter[CM_REP_COUNTER]);
33728 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33729 if (ret)
33730 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33731 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33732 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33733 spin_unlock_irq(&cm_id_priv->lock);
33734 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33735 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33736 counter[CM_RTU_COUNTER]);
33737 goto out;
33738 }
33739 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33740 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33741 dreq_msg->local_comm_id);
33742 if (!cm_id_priv) {
33743 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33744 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33745 counter[CM_DREQ_COUNTER]);
33746 cm_issue_drep(work->port, work->mad_recv_wc);
33747 return -EINVAL;
33748 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33749 case IB_CM_MRA_REP_RCVD:
33750 break;
33751 case IB_CM_TIMEWAIT:
33752 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33753 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33754 counter[CM_DREQ_COUNTER]);
33755 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33756 goto unlock;
33757 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33758 cm_free_msg(msg);
33759 goto deref;
33760 case IB_CM_DREQ_RCVD:
33761 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33762 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33763 counter[CM_DREQ_COUNTER]);
33764 goto unlock;
33765 default:
33766 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33767 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33768 cm_id_priv->msg, timeout)) {
33769 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33770 - atomic_long_inc(&work->port->
33771 + atomic_long_inc_unchecked(&work->port->
33772 counter_group[CM_RECV_DUPLICATES].
33773 counter[CM_MRA_COUNTER]);
33774 goto out;
33775 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33776 break;
33777 case IB_CM_MRA_REQ_RCVD:
33778 case IB_CM_MRA_REP_RCVD:
33779 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33780 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33781 counter[CM_MRA_COUNTER]);
33782 /* fall through */
33783 default:
33784 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33785 case IB_CM_LAP_IDLE:
33786 break;
33787 case IB_CM_MRA_LAP_SENT:
33788 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33789 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33790 counter[CM_LAP_COUNTER]);
33791 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33792 goto unlock;
33793 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33794 cm_free_msg(msg);
33795 goto deref;
33796 case IB_CM_LAP_RCVD:
33797 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33798 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33799 counter[CM_LAP_COUNTER]);
33800 goto unlock;
33801 default:
33802 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33803 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33804 if (cur_cm_id_priv) {
33805 spin_unlock_irq(&cm.lock);
33806 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33807 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33808 counter[CM_SIDR_REQ_COUNTER]);
33809 goto out; /* Duplicate message. */
33810 }
33811 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33812 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33813 msg->retries = 1;
33814
33815 - atomic_long_add(1 + msg->retries,
33816 + atomic_long_add_unchecked(1 + msg->retries,
33817 &port->counter_group[CM_XMIT].counter[attr_index]);
33818 if (msg->retries)
33819 - atomic_long_add(msg->retries,
33820 + atomic_long_add_unchecked(msg->retries,
33821 &port->counter_group[CM_XMIT_RETRIES].
33822 counter[attr_index]);
33823
33824 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
33825 }
33826
33827 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
33828 - atomic_long_inc(&port->counter_group[CM_RECV].
33829 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
33830 counter[attr_id - CM_ATTR_ID_OFFSET]);
33831
33832 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
33833 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
33834 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
33835
33836 return sprintf(buf, "%ld\n",
33837 - atomic_long_read(&group->counter[cm_attr->index]));
33838 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
33839 }
33840
33841 static const struct sysfs_ops cm_counter_ops = {
33842 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
33843 index 176c8f9..2627b62 100644
33844 --- a/drivers/infiniband/core/fmr_pool.c
33845 +++ b/drivers/infiniband/core/fmr_pool.c
33846 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
33847
33848 struct task_struct *thread;
33849
33850 - atomic_t req_ser;
33851 - atomic_t flush_ser;
33852 + atomic_unchecked_t req_ser;
33853 + atomic_unchecked_t flush_ser;
33854
33855 wait_queue_head_t force_wait;
33856 };
33857 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33858 struct ib_fmr_pool *pool = pool_ptr;
33859
33860 do {
33861 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
33862 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
33863 ib_fmr_batch_release(pool);
33864
33865 - atomic_inc(&pool->flush_ser);
33866 + atomic_inc_unchecked(&pool->flush_ser);
33867 wake_up_interruptible(&pool->force_wait);
33868
33869 if (pool->flush_function)
33870 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33871 }
33872
33873 set_current_state(TASK_INTERRUPTIBLE);
33874 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
33875 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
33876 !kthread_should_stop())
33877 schedule();
33878 __set_current_state(TASK_RUNNING);
33879 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
33880 pool->dirty_watermark = params->dirty_watermark;
33881 pool->dirty_len = 0;
33882 spin_lock_init(&pool->pool_lock);
33883 - atomic_set(&pool->req_ser, 0);
33884 - atomic_set(&pool->flush_ser, 0);
33885 + atomic_set_unchecked(&pool->req_ser, 0);
33886 + atomic_set_unchecked(&pool->flush_ser, 0);
33887 init_waitqueue_head(&pool->force_wait);
33888
33889 pool->thread = kthread_run(ib_fmr_cleanup_thread,
33890 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
33891 }
33892 spin_unlock_irq(&pool->pool_lock);
33893
33894 - serial = atomic_inc_return(&pool->req_ser);
33895 + serial = atomic_inc_return_unchecked(&pool->req_ser);
33896 wake_up_process(pool->thread);
33897
33898 if (wait_event_interruptible(pool->force_wait,
33899 - atomic_read(&pool->flush_ser) - serial >= 0))
33900 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
33901 return -EINTR;
33902
33903 return 0;
33904 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
33905 } else {
33906 list_add_tail(&fmr->list, &pool->dirty_list);
33907 if (++pool->dirty_len >= pool->dirty_watermark) {
33908 - atomic_inc(&pool->req_ser);
33909 + atomic_inc_unchecked(&pool->req_ser);
33910 wake_up_process(pool->thread);
33911 }
33912 }
33913 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
33914 index afd8179..598063f 100644
33915 --- a/drivers/infiniband/hw/cxgb4/mem.c
33916 +++ b/drivers/infiniband/hw/cxgb4/mem.c
33917 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33918 int err;
33919 struct fw_ri_tpte tpt;
33920 u32 stag_idx;
33921 - static atomic_t key;
33922 + static atomic_unchecked_t key;
33923
33924 if (c4iw_fatal_error(rdev))
33925 return -EIO;
33926 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33927 if (rdev->stats.stag.cur > rdev->stats.stag.max)
33928 rdev->stats.stag.max = rdev->stats.stag.cur;
33929 mutex_unlock(&rdev->stats.lock);
33930 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
33931 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
33932 }
33933 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
33934 __func__, stag_state, type, pdid, stag_idx);
33935 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
33936 index 79b3dbc..96e5fcc 100644
33937 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
33938 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
33939 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33940 struct ib_atomic_eth *ateth;
33941 struct ipath_ack_entry *e;
33942 u64 vaddr;
33943 - atomic64_t *maddr;
33944 + atomic64_unchecked_t *maddr;
33945 u64 sdata;
33946 u32 rkey;
33947 u8 next;
33948 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33949 IB_ACCESS_REMOTE_ATOMIC)))
33950 goto nack_acc_unlck;
33951 /* Perform atomic OP and save result. */
33952 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33953 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33954 sdata = be64_to_cpu(ateth->swap_data);
33955 e = &qp->s_ack_queue[qp->r_head_ack_queue];
33956 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
33957 - (u64) atomic64_add_return(sdata, maddr) - sdata :
33958 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33959 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33960 be64_to_cpu(ateth->compare_data),
33961 sdata);
33962 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
33963 index 1f95bba..9530f87 100644
33964 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
33965 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
33966 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
33967 unsigned long flags;
33968 struct ib_wc wc;
33969 u64 sdata;
33970 - atomic64_t *maddr;
33971 + atomic64_unchecked_t *maddr;
33972 enum ib_wc_status send_status;
33973
33974 /*
33975 @@ -382,11 +382,11 @@ again:
33976 IB_ACCESS_REMOTE_ATOMIC)))
33977 goto acc_err;
33978 /* Perform atomic OP and save result. */
33979 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33980 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33981 sdata = wqe->wr.wr.atomic.compare_add;
33982 *(u64 *) sqp->s_sge.sge.vaddr =
33983 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
33984 - (u64) atomic64_add_return(sdata, maddr) - sdata :
33985 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33986 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33987 sdata, wqe->wr.wr.atomic.swap);
33988 goto send_comp;
33989 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
33990 index 748db2d..5f75cc3 100644
33991 --- a/drivers/infiniband/hw/nes/nes.c
33992 +++ b/drivers/infiniband/hw/nes/nes.c
33993 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
33994 LIST_HEAD(nes_adapter_list);
33995 static LIST_HEAD(nes_dev_list);
33996
33997 -atomic_t qps_destroyed;
33998 +atomic_unchecked_t qps_destroyed;
33999
34000 static unsigned int ee_flsh_adapter;
34001 static unsigned int sysfs_nonidx_addr;
34002 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34003 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34004 struct nes_adapter *nesadapter = nesdev->nesadapter;
34005
34006 - atomic_inc(&qps_destroyed);
34007 + atomic_inc_unchecked(&qps_destroyed);
34008
34009 /* Free the control structures */
34010
34011 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34012 index 33cc589..3bd6538 100644
34013 --- a/drivers/infiniband/hw/nes/nes.h
34014 +++ b/drivers/infiniband/hw/nes/nes.h
34015 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34016 extern unsigned int wqm_quanta;
34017 extern struct list_head nes_adapter_list;
34018
34019 -extern atomic_t cm_connects;
34020 -extern atomic_t cm_accepts;
34021 -extern atomic_t cm_disconnects;
34022 -extern atomic_t cm_closes;
34023 -extern atomic_t cm_connecteds;
34024 -extern atomic_t cm_connect_reqs;
34025 -extern atomic_t cm_rejects;
34026 -extern atomic_t mod_qp_timouts;
34027 -extern atomic_t qps_created;
34028 -extern atomic_t qps_destroyed;
34029 -extern atomic_t sw_qps_destroyed;
34030 +extern atomic_unchecked_t cm_connects;
34031 +extern atomic_unchecked_t cm_accepts;
34032 +extern atomic_unchecked_t cm_disconnects;
34033 +extern atomic_unchecked_t cm_closes;
34034 +extern atomic_unchecked_t cm_connecteds;
34035 +extern atomic_unchecked_t cm_connect_reqs;
34036 +extern atomic_unchecked_t cm_rejects;
34037 +extern atomic_unchecked_t mod_qp_timouts;
34038 +extern atomic_unchecked_t qps_created;
34039 +extern atomic_unchecked_t qps_destroyed;
34040 +extern atomic_unchecked_t sw_qps_destroyed;
34041 extern u32 mh_detected;
34042 extern u32 mh_pauses_sent;
34043 extern u32 cm_packets_sent;
34044 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34045 extern u32 cm_packets_received;
34046 extern u32 cm_packets_dropped;
34047 extern u32 cm_packets_retrans;
34048 -extern atomic_t cm_listens_created;
34049 -extern atomic_t cm_listens_destroyed;
34050 +extern atomic_unchecked_t cm_listens_created;
34051 +extern atomic_unchecked_t cm_listens_destroyed;
34052 extern u32 cm_backlog_drops;
34053 -extern atomic_t cm_loopbacks;
34054 -extern atomic_t cm_nodes_created;
34055 -extern atomic_t cm_nodes_destroyed;
34056 -extern atomic_t cm_accel_dropped_pkts;
34057 -extern atomic_t cm_resets_recvd;
34058 -extern atomic_t pau_qps_created;
34059 -extern atomic_t pau_qps_destroyed;
34060 +extern atomic_unchecked_t cm_loopbacks;
34061 +extern atomic_unchecked_t cm_nodes_created;
34062 +extern atomic_unchecked_t cm_nodes_destroyed;
34063 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34064 +extern atomic_unchecked_t cm_resets_recvd;
34065 +extern atomic_unchecked_t pau_qps_created;
34066 +extern atomic_unchecked_t pau_qps_destroyed;
34067
34068 extern u32 int_mod_timer_init;
34069 extern u32 int_mod_cq_depth_256;
34070 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34071 index cfaacaf..fa0722e 100644
34072 --- a/drivers/infiniband/hw/nes/nes_cm.c
34073 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34074 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34075 u32 cm_packets_retrans;
34076 u32 cm_packets_created;
34077 u32 cm_packets_received;
34078 -atomic_t cm_listens_created;
34079 -atomic_t cm_listens_destroyed;
34080 +atomic_unchecked_t cm_listens_created;
34081 +atomic_unchecked_t cm_listens_destroyed;
34082 u32 cm_backlog_drops;
34083 -atomic_t cm_loopbacks;
34084 -atomic_t cm_nodes_created;
34085 -atomic_t cm_nodes_destroyed;
34086 -atomic_t cm_accel_dropped_pkts;
34087 -atomic_t cm_resets_recvd;
34088 +atomic_unchecked_t cm_loopbacks;
34089 +atomic_unchecked_t cm_nodes_created;
34090 +atomic_unchecked_t cm_nodes_destroyed;
34091 +atomic_unchecked_t cm_accel_dropped_pkts;
34092 +atomic_unchecked_t cm_resets_recvd;
34093
34094 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34095 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34096 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34097
34098 static struct nes_cm_core *g_cm_core;
34099
34100 -atomic_t cm_connects;
34101 -atomic_t cm_accepts;
34102 -atomic_t cm_disconnects;
34103 -atomic_t cm_closes;
34104 -atomic_t cm_connecteds;
34105 -atomic_t cm_connect_reqs;
34106 -atomic_t cm_rejects;
34107 +atomic_unchecked_t cm_connects;
34108 +atomic_unchecked_t cm_accepts;
34109 +atomic_unchecked_t cm_disconnects;
34110 +atomic_unchecked_t cm_closes;
34111 +atomic_unchecked_t cm_connecteds;
34112 +atomic_unchecked_t cm_connect_reqs;
34113 +atomic_unchecked_t cm_rejects;
34114
34115 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34116 {
34117 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34118 kfree(listener);
34119 listener = NULL;
34120 ret = 0;
34121 - atomic_inc(&cm_listens_destroyed);
34122 + atomic_inc_unchecked(&cm_listens_destroyed);
34123 } else {
34124 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34125 }
34126 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34127 cm_node->rem_mac);
34128
34129 add_hte_node(cm_core, cm_node);
34130 - atomic_inc(&cm_nodes_created);
34131 + atomic_inc_unchecked(&cm_nodes_created);
34132
34133 return cm_node;
34134 }
34135 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34136 }
34137
34138 atomic_dec(&cm_core->node_cnt);
34139 - atomic_inc(&cm_nodes_destroyed);
34140 + atomic_inc_unchecked(&cm_nodes_destroyed);
34141 nesqp = cm_node->nesqp;
34142 if (nesqp) {
34143 nesqp->cm_node = NULL;
34144 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34145
34146 static void drop_packet(struct sk_buff *skb)
34147 {
34148 - atomic_inc(&cm_accel_dropped_pkts);
34149 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34150 dev_kfree_skb_any(skb);
34151 }
34152
34153 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34154 {
34155
34156 int reset = 0; /* whether to send reset in case of err.. */
34157 - atomic_inc(&cm_resets_recvd);
34158 + atomic_inc_unchecked(&cm_resets_recvd);
34159 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34160 " refcnt=%d\n", cm_node, cm_node->state,
34161 atomic_read(&cm_node->ref_count));
34162 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34163 rem_ref_cm_node(cm_node->cm_core, cm_node);
34164 return NULL;
34165 }
34166 - atomic_inc(&cm_loopbacks);
34167 + atomic_inc_unchecked(&cm_loopbacks);
34168 loopbackremotenode->loopbackpartner = cm_node;
34169 loopbackremotenode->tcp_cntxt.rcv_wscale =
34170 NES_CM_DEFAULT_RCV_WND_SCALE;
34171 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34172 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34173 else {
34174 rem_ref_cm_node(cm_core, cm_node);
34175 - atomic_inc(&cm_accel_dropped_pkts);
34176 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34177 dev_kfree_skb_any(skb);
34178 }
34179 break;
34180 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34181
34182 if ((cm_id) && (cm_id->event_handler)) {
34183 if (issue_disconn) {
34184 - atomic_inc(&cm_disconnects);
34185 + atomic_inc_unchecked(&cm_disconnects);
34186 cm_event.event = IW_CM_EVENT_DISCONNECT;
34187 cm_event.status = disconn_status;
34188 cm_event.local_addr = cm_id->local_addr;
34189 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34190 }
34191
34192 if (issue_close) {
34193 - atomic_inc(&cm_closes);
34194 + atomic_inc_unchecked(&cm_closes);
34195 nes_disconnect(nesqp, 1);
34196
34197 cm_id->provider_data = nesqp;
34198 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34199
34200 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34201 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34202 - atomic_inc(&cm_accepts);
34203 + atomic_inc_unchecked(&cm_accepts);
34204
34205 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34206 netdev_refcnt_read(nesvnic->netdev));
34207 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34208 struct nes_cm_core *cm_core;
34209 u8 *start_buff;
34210
34211 - atomic_inc(&cm_rejects);
34212 + atomic_inc_unchecked(&cm_rejects);
34213 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34214 loopback = cm_node->loopbackpartner;
34215 cm_core = cm_node->cm_core;
34216 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34217 ntohl(cm_id->local_addr.sin_addr.s_addr),
34218 ntohs(cm_id->local_addr.sin_port));
34219
34220 - atomic_inc(&cm_connects);
34221 + atomic_inc_unchecked(&cm_connects);
34222 nesqp->active_conn = 1;
34223
34224 /* cache the cm_id in the qp */
34225 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34226 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34227 return err;
34228 }
34229 - atomic_inc(&cm_listens_created);
34230 + atomic_inc_unchecked(&cm_listens_created);
34231 }
34232
34233 cm_id->add_ref(cm_id);
34234 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34235
34236 if (nesqp->destroyed)
34237 return;
34238 - atomic_inc(&cm_connecteds);
34239 + atomic_inc_unchecked(&cm_connecteds);
34240 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34241 " local port 0x%04X. jiffies = %lu.\n",
34242 nesqp->hwqp.qp_id,
34243 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34244
34245 cm_id->add_ref(cm_id);
34246 ret = cm_id->event_handler(cm_id, &cm_event);
34247 - atomic_inc(&cm_closes);
34248 + atomic_inc_unchecked(&cm_closes);
34249 cm_event.event = IW_CM_EVENT_CLOSE;
34250 cm_event.status = 0;
34251 cm_event.provider_data = cm_id->provider_data;
34252 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34253 return;
34254 cm_id = cm_node->cm_id;
34255
34256 - atomic_inc(&cm_connect_reqs);
34257 + atomic_inc_unchecked(&cm_connect_reqs);
34258 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34259 cm_node, cm_id, jiffies);
34260
34261 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34262 return;
34263 cm_id = cm_node->cm_id;
34264
34265 - atomic_inc(&cm_connect_reqs);
34266 + atomic_inc_unchecked(&cm_connect_reqs);
34267 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34268 cm_node, cm_id, jiffies);
34269
34270 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34271 index 3ba7be3..c81f6ff 100644
34272 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34273 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34274 @@ -40,8 +40,8 @@
34275 #include "nes.h"
34276 #include "nes_mgt.h"
34277
34278 -atomic_t pau_qps_created;
34279 -atomic_t pau_qps_destroyed;
34280 +atomic_unchecked_t pau_qps_created;
34281 +atomic_unchecked_t pau_qps_destroyed;
34282
34283 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34284 {
34285 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34286 {
34287 struct sk_buff *skb;
34288 unsigned long flags;
34289 - atomic_inc(&pau_qps_destroyed);
34290 + atomic_inc_unchecked(&pau_qps_destroyed);
34291
34292 /* Free packets that have not yet been forwarded */
34293 /* Lock is acquired by skb_dequeue when removing the skb */
34294 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34295 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34296 skb_queue_head_init(&nesqp->pau_list);
34297 spin_lock_init(&nesqp->pau_lock);
34298 - atomic_inc(&pau_qps_created);
34299 + atomic_inc_unchecked(&pau_qps_created);
34300 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34301 }
34302
34303 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34304 index 0564be7..f68b0f1 100644
34305 --- a/drivers/infiniband/hw/nes/nes_nic.c
34306 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34307 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34308 target_stat_values[++index] = mh_detected;
34309 target_stat_values[++index] = mh_pauses_sent;
34310 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34311 - target_stat_values[++index] = atomic_read(&cm_connects);
34312 - target_stat_values[++index] = atomic_read(&cm_accepts);
34313 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34314 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34315 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34316 - target_stat_values[++index] = atomic_read(&cm_rejects);
34317 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34318 - target_stat_values[++index] = atomic_read(&qps_created);
34319 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34320 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34321 - target_stat_values[++index] = atomic_read(&cm_closes);
34322 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34323 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34324 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34325 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34326 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34327 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34328 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34329 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34330 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34331 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34332 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34333 target_stat_values[++index] = cm_packets_sent;
34334 target_stat_values[++index] = cm_packets_bounced;
34335 target_stat_values[++index] = cm_packets_created;
34336 target_stat_values[++index] = cm_packets_received;
34337 target_stat_values[++index] = cm_packets_dropped;
34338 target_stat_values[++index] = cm_packets_retrans;
34339 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34340 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34341 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34342 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34343 target_stat_values[++index] = cm_backlog_drops;
34344 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34345 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34346 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34347 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34348 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34349 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34350 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34351 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34352 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34353 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34354 target_stat_values[++index] = nesadapter->free_4kpbl;
34355 target_stat_values[++index] = nesadapter->free_256pbl;
34356 target_stat_values[++index] = int_mod_timer_init;
34357 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34358 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34359 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34360 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34361 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34362 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34363 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34364 }
34365
34366 /**
34367 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34368 index 07e4fba..685f041 100644
34369 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34370 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34371 @@ -46,9 +46,9 @@
34372
34373 #include <rdma/ib_umem.h>
34374
34375 -atomic_t mod_qp_timouts;
34376 -atomic_t qps_created;
34377 -atomic_t sw_qps_destroyed;
34378 +atomic_unchecked_t mod_qp_timouts;
34379 +atomic_unchecked_t qps_created;
34380 +atomic_unchecked_t sw_qps_destroyed;
34381
34382 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34383
34384 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34385 if (init_attr->create_flags)
34386 return ERR_PTR(-EINVAL);
34387
34388 - atomic_inc(&qps_created);
34389 + atomic_inc_unchecked(&qps_created);
34390 switch (init_attr->qp_type) {
34391 case IB_QPT_RC:
34392 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34393 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34394 struct iw_cm_event cm_event;
34395 int ret = 0;
34396
34397 - atomic_inc(&sw_qps_destroyed);
34398 + atomic_inc_unchecked(&sw_qps_destroyed);
34399 nesqp->destroyed = 1;
34400
34401 /* Blow away the connection if it exists. */
34402 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34403 index 4d11575..3e890e5 100644
34404 --- a/drivers/infiniband/hw/qib/qib.h
34405 +++ b/drivers/infiniband/hw/qib/qib.h
34406 @@ -51,6 +51,7 @@
34407 #include <linux/completion.h>
34408 #include <linux/kref.h>
34409 #include <linux/sched.h>
34410 +#include <linux/slab.h>
34411
34412 #include "qib_common.h"
34413 #include "qib_verbs.h"
34414 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34415 index da739d9..da1c7f4 100644
34416 --- a/drivers/input/gameport/gameport.c
34417 +++ b/drivers/input/gameport/gameport.c
34418 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34419 */
34420 static void gameport_init_port(struct gameport *gameport)
34421 {
34422 - static atomic_t gameport_no = ATOMIC_INIT(0);
34423 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34424
34425 __module_get(THIS_MODULE);
34426
34427 mutex_init(&gameport->drv_mutex);
34428 device_initialize(&gameport->dev);
34429 dev_set_name(&gameport->dev, "gameport%lu",
34430 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34431 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34432 gameport->dev.bus = &gameport_bus;
34433 gameport->dev.release = gameport_release_port;
34434 if (gameport->parent)
34435 diff --git a/drivers/input/input.c b/drivers/input/input.c
34436 index 53a0dde..abffda7 100644
34437 --- a/drivers/input/input.c
34438 +++ b/drivers/input/input.c
34439 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34440 */
34441 int input_register_device(struct input_dev *dev)
34442 {
34443 - static atomic_t input_no = ATOMIC_INIT(0);
34444 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34445 struct input_handler *handler;
34446 unsigned int packet_size;
34447 const char *path;
34448 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34449 dev->setkeycode = input_default_setkeycode;
34450
34451 dev_set_name(&dev->dev, "input%ld",
34452 - (unsigned long) atomic_inc_return(&input_no) - 1);
34453 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34454
34455 error = device_add(&dev->dev);
34456 if (error)
34457 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34458 index 04c69af..5f92d00 100644
34459 --- a/drivers/input/joystick/sidewinder.c
34460 +++ b/drivers/input/joystick/sidewinder.c
34461 @@ -30,6 +30,7 @@
34462 #include <linux/kernel.h>
34463 #include <linux/module.h>
34464 #include <linux/slab.h>
34465 +#include <linux/sched.h>
34466 #include <linux/init.h>
34467 #include <linux/input.h>
34468 #include <linux/gameport.h>
34469 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34470 index 83811e4..0822b90 100644
34471 --- a/drivers/input/joystick/xpad.c
34472 +++ b/drivers/input/joystick/xpad.c
34473 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34474
34475 static int xpad_led_probe(struct usb_xpad *xpad)
34476 {
34477 - static atomic_t led_seq = ATOMIC_INIT(0);
34478 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34479 long led_no;
34480 struct xpad_led *led;
34481 struct led_classdev *led_cdev;
34482 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34483 if (!led)
34484 return -ENOMEM;
34485
34486 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34487 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34488
34489 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34490 led->xpad = xpad;
34491 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34492 index 4c842c3..590b0bf 100644
34493 --- a/drivers/input/mousedev.c
34494 +++ b/drivers/input/mousedev.c
34495 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34496
34497 spin_unlock_irq(&client->packet_lock);
34498
34499 - if (copy_to_user(buffer, data, count))
34500 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34501 return -EFAULT;
34502
34503 return count;
34504 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34505 index d0f7533..fb8215b 100644
34506 --- a/drivers/input/serio/serio.c
34507 +++ b/drivers/input/serio/serio.c
34508 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34509 */
34510 static void serio_init_port(struct serio *serio)
34511 {
34512 - static atomic_t serio_no = ATOMIC_INIT(0);
34513 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34514
34515 __module_get(THIS_MODULE);
34516
34517 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34518 mutex_init(&serio->drv_mutex);
34519 device_initialize(&serio->dev);
34520 dev_set_name(&serio->dev, "serio%ld",
34521 - (long)atomic_inc_return(&serio_no) - 1);
34522 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34523 serio->dev.bus = &serio_bus;
34524 serio->dev.release = serio_release_port;
34525 serio->dev.groups = serio_device_attr_groups;
34526 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34527 index c679867..6e2e34d 100644
34528 --- a/drivers/isdn/capi/capi.c
34529 +++ b/drivers/isdn/capi/capi.c
34530 @@ -83,8 +83,8 @@ struct capiminor {
34531
34532 struct capi20_appl *ap;
34533 u32 ncci;
34534 - atomic_t datahandle;
34535 - atomic_t msgid;
34536 + atomic_unchecked_t datahandle;
34537 + atomic_unchecked_t msgid;
34538
34539 struct tty_port port;
34540 int ttyinstop;
34541 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34542 capimsg_setu16(s, 2, mp->ap->applid);
34543 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34544 capimsg_setu8 (s, 5, CAPI_RESP);
34545 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34546 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34547 capimsg_setu32(s, 8, mp->ncci);
34548 capimsg_setu16(s, 12, datahandle);
34549 }
34550 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34551 mp->outbytes -= len;
34552 spin_unlock_bh(&mp->outlock);
34553
34554 - datahandle = atomic_inc_return(&mp->datahandle);
34555 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34556 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34557 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34558 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34559 capimsg_setu16(skb->data, 2, mp->ap->applid);
34560 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34561 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34562 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34563 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34564 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34565 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34566 capimsg_setu16(skb->data, 16, len); /* Data length */
34567 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34568 index 67abf3f..076b3a6 100644
34569 --- a/drivers/isdn/gigaset/interface.c
34570 +++ b/drivers/isdn/gigaset/interface.c
34571 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34572 }
34573 tty->driver_data = cs;
34574
34575 - ++cs->port.count;
34576 + atomic_inc(&cs->port.count);
34577
34578 - if (cs->port.count == 1) {
34579 + if (atomic_read(&cs->port.count) == 1) {
34580 tty_port_tty_set(&cs->port, tty);
34581 tty->low_latency = 1;
34582 }
34583 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34584
34585 if (!cs->connected)
34586 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34587 - else if (!cs->port.count)
34588 + else if (!atomic_read(&cs->port.count))
34589 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34590 - else if (!--cs->port.count)
34591 + else if (!atomic_dec_return(&cs->port.count))
34592 tty_port_tty_set(&cs->port, NULL);
34593
34594 mutex_unlock(&cs->mutex);
34595 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34596 index 821f7ac..28d4030 100644
34597 --- a/drivers/isdn/hardware/avm/b1.c
34598 +++ b/drivers/isdn/hardware/avm/b1.c
34599 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34600 }
34601 if (left) {
34602 if (t4file->user) {
34603 - if (copy_from_user(buf, dp, left))
34604 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34605 return -EFAULT;
34606 } else {
34607 memcpy(buf, dp, left);
34608 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34609 }
34610 if (left) {
34611 if (config->user) {
34612 - if (copy_from_user(buf, dp, left))
34613 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34614 return -EFAULT;
34615 } else {
34616 memcpy(buf, dp, left);
34617 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34618 index b817809..409caff 100644
34619 --- a/drivers/isdn/i4l/isdn_tty.c
34620 +++ b/drivers/isdn/i4l/isdn_tty.c
34621 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34622
34623 #ifdef ISDN_DEBUG_MODEM_OPEN
34624 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34625 - port->count);
34626 + atomic_read(&port->count));
34627 #endif
34628 - port->count++;
34629 + atomic_inc(&port->count);
34630 port->tty = tty;
34631 /*
34632 * Start up serial port
34633 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34634 #endif
34635 return;
34636 }
34637 - if ((tty->count == 1) && (port->count != 1)) {
34638 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34639 /*
34640 * Uh, oh. tty->count is 1, which means that the tty
34641 * structure will be freed. Info->count should always
34642 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34643 * serial port won't be shutdown.
34644 */
34645 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34646 - "info->count is %d\n", port->count);
34647 - port->count = 1;
34648 + "info->count is %d\n", atomic_read(&port->count));
34649 + atomic_set(&port->count, 1);
34650 }
34651 - if (--port->count < 0) {
34652 + if (atomic_dec_return(&port->count) < 0) {
34653 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34654 - info->line, port->count);
34655 - port->count = 0;
34656 + info->line, atomic_read(&port->count));
34657 + atomic_set(&port->count, 0);
34658 }
34659 - if (port->count) {
34660 + if (atomic_read(&port->count)) {
34661 #ifdef ISDN_DEBUG_MODEM_OPEN
34662 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34663 #endif
34664 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34665 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34666 return;
34667 isdn_tty_shutdown(info);
34668 - port->count = 0;
34669 + atomic_set(&port->count, 0);
34670 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34671 port->tty = NULL;
34672 wake_up_interruptible(&port->open_wait);
34673 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34674 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34675 modem_info *info = &dev->mdm.info[i];
34676
34677 - if (info->port.count == 0)
34678 + if (atomic_read(&info->port.count) == 0)
34679 continue;
34680 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34681 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34682 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34683 index e74df7c..03a03ba 100644
34684 --- a/drivers/isdn/icn/icn.c
34685 +++ b/drivers/isdn/icn/icn.c
34686 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34687 if (count > len)
34688 count = len;
34689 if (user) {
34690 - if (copy_from_user(msg, buf, count))
34691 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34692 return -EFAULT;
34693 } else
34694 memcpy(msg, buf, count);
34695 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34696 index b5fdcb7..5b6c59f 100644
34697 --- a/drivers/lguest/core.c
34698 +++ b/drivers/lguest/core.c
34699 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34700 * it's worked so far. The end address needs +1 because __get_vm_area
34701 * allocates an extra guard page, so we need space for that.
34702 */
34703 +
34704 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34705 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34706 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34707 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34708 +#else
34709 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34710 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34711 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34712 +#endif
34713 +
34714 if (!switcher_vma) {
34715 err = -ENOMEM;
34716 printk("lguest: could not map switcher pages high\n");
34717 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34718 * Now the Switcher is mapped at the right address, we can't fail!
34719 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34720 */
34721 - memcpy(switcher_vma->addr, start_switcher_text,
34722 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34723 end_switcher_text - start_switcher_text);
34724
34725 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34726 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34727 index 4af12e1..0e89afe 100644
34728 --- a/drivers/lguest/x86/core.c
34729 +++ b/drivers/lguest/x86/core.c
34730 @@ -59,7 +59,7 @@ static struct {
34731 /* Offset from where switcher.S was compiled to where we've copied it */
34732 static unsigned long switcher_offset(void)
34733 {
34734 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34735 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34736 }
34737
34738 /* This cpu's struct lguest_pages. */
34739 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34740 * These copies are pretty cheap, so we do them unconditionally: */
34741 /* Save the current Host top-level page directory.
34742 */
34743 +
34744 +#ifdef CONFIG_PAX_PER_CPU_PGD
34745 + pages->state.host_cr3 = read_cr3();
34746 +#else
34747 pages->state.host_cr3 = __pa(current->mm->pgd);
34748 +#endif
34749 +
34750 /*
34751 * Set up the Guest's page tables to see this CPU's pages (and no
34752 * other CPU's pages).
34753 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34754 * compiled-in switcher code and the high-mapped copy we just made.
34755 */
34756 for (i = 0; i < IDT_ENTRIES; i++)
34757 - default_idt_entries[i] += switcher_offset();
34758 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34759
34760 /*
34761 * Set up the Switcher's per-cpu areas.
34762 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34763 * it will be undisturbed when we switch. To change %cs and jump we
34764 * need this structure to feed to Intel's "lcall" instruction.
34765 */
34766 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34767 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34768 lguest_entry.segment = LGUEST_CS;
34769
34770 /*
34771 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34772 index 40634b0..4f5855e 100644
34773 --- a/drivers/lguest/x86/switcher_32.S
34774 +++ b/drivers/lguest/x86/switcher_32.S
34775 @@ -87,6 +87,7 @@
34776 #include <asm/page.h>
34777 #include <asm/segment.h>
34778 #include <asm/lguest.h>
34779 +#include <asm/processor-flags.h>
34780
34781 // We mark the start of the code to copy
34782 // It's placed in .text tho it's never run here
34783 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
34784 // Changes type when we load it: damn Intel!
34785 // For after we switch over our page tables
34786 // That entry will be read-only: we'd crash.
34787 +
34788 +#ifdef CONFIG_PAX_KERNEXEC
34789 + mov %cr0, %edx
34790 + xor $X86_CR0_WP, %edx
34791 + mov %edx, %cr0
34792 +#endif
34793 +
34794 movl $(GDT_ENTRY_TSS*8), %edx
34795 ltr %dx
34796
34797 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
34798 // Let's clear it again for our return.
34799 // The GDT descriptor of the Host
34800 // Points to the table after two "size" bytes
34801 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
34802 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
34803 // Clear "used" from type field (byte 5, bit 2)
34804 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
34805 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
34806 +
34807 +#ifdef CONFIG_PAX_KERNEXEC
34808 + mov %cr0, %eax
34809 + xor $X86_CR0_WP, %eax
34810 + mov %eax, %cr0
34811 +#endif
34812
34813 // Once our page table's switched, the Guest is live!
34814 // The Host fades as we run this final step.
34815 @@ -295,13 +309,12 @@ deliver_to_host:
34816 // I consulted gcc, and it gave
34817 // These instructions, which I gladly credit:
34818 leal (%edx,%ebx,8), %eax
34819 - movzwl (%eax),%edx
34820 - movl 4(%eax), %eax
34821 - xorw %ax, %ax
34822 - orl %eax, %edx
34823 + movl 4(%eax), %edx
34824 + movw (%eax), %dx
34825 // Now the address of the handler's in %edx
34826 // We call it now: its "iret" drops us home.
34827 - jmp *%edx
34828 + ljmp $__KERNEL_CS, $1f
34829 +1: jmp *%edx
34830
34831 // Every interrupt can come to us here
34832 // But we must truly tell each apart.
34833 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
34834 index 7155945..4bcc562 100644
34835 --- a/drivers/md/bitmap.c
34836 +++ b/drivers/md/bitmap.c
34837 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
34838 chunk_kb ? "KB" : "B");
34839 if (bitmap->storage.file) {
34840 seq_printf(seq, ", file: ");
34841 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
34842 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
34843 }
34844
34845 seq_printf(seq, "\n");
34846 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
34847 index a651d52..82f8a95 100644
34848 --- a/drivers/md/dm-ioctl.c
34849 +++ b/drivers/md/dm-ioctl.c
34850 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
34851 cmd == DM_LIST_VERSIONS_CMD)
34852 return 0;
34853
34854 - if ((cmd == DM_DEV_CREATE_CMD)) {
34855 + if (cmd == DM_DEV_CREATE_CMD) {
34856 if (!*param->name) {
34857 DMWARN("name not supplied when creating device");
34858 return -EINVAL;
34859 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
34860 index fd61f98..8050783 100644
34861 --- a/drivers/md/dm-raid1.c
34862 +++ b/drivers/md/dm-raid1.c
34863 @@ -40,7 +40,7 @@ enum dm_raid1_error {
34864
34865 struct mirror {
34866 struct mirror_set *ms;
34867 - atomic_t error_count;
34868 + atomic_unchecked_t error_count;
34869 unsigned long error_type;
34870 struct dm_dev *dev;
34871 sector_t offset;
34872 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
34873 struct mirror *m;
34874
34875 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
34876 - if (!atomic_read(&m->error_count))
34877 + if (!atomic_read_unchecked(&m->error_count))
34878 return m;
34879
34880 return NULL;
34881 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
34882 * simple way to tell if a device has encountered
34883 * errors.
34884 */
34885 - atomic_inc(&m->error_count);
34886 + atomic_inc_unchecked(&m->error_count);
34887
34888 if (test_and_set_bit(error_type, &m->error_type))
34889 return;
34890 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
34891 struct mirror *m = get_default_mirror(ms);
34892
34893 do {
34894 - if (likely(!atomic_read(&m->error_count)))
34895 + if (likely(!atomic_read_unchecked(&m->error_count)))
34896 return m;
34897
34898 if (m-- == ms->mirror)
34899 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
34900 {
34901 struct mirror *default_mirror = get_default_mirror(m->ms);
34902
34903 - return !atomic_read(&default_mirror->error_count);
34904 + return !atomic_read_unchecked(&default_mirror->error_count);
34905 }
34906
34907 static int mirror_available(struct mirror_set *ms, struct bio *bio)
34908 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
34909 */
34910 if (likely(region_in_sync(ms, region, 1)))
34911 m = choose_mirror(ms, bio->bi_sector);
34912 - else if (m && atomic_read(&m->error_count))
34913 + else if (m && atomic_read_unchecked(&m->error_count))
34914 m = NULL;
34915
34916 if (likely(m))
34917 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
34918 }
34919
34920 ms->mirror[mirror].ms = ms;
34921 - atomic_set(&(ms->mirror[mirror].error_count), 0);
34922 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
34923 ms->mirror[mirror].error_type = 0;
34924 ms->mirror[mirror].offset = offset;
34925
34926 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
34927 */
34928 static char device_status_char(struct mirror *m)
34929 {
34930 - if (!atomic_read(&(m->error_count)))
34931 + if (!atomic_read_unchecked(&(m->error_count)))
34932 return 'A';
34933
34934 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
34935 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
34936 index e2f87653..f279abe 100644
34937 --- a/drivers/md/dm-stripe.c
34938 +++ b/drivers/md/dm-stripe.c
34939 @@ -20,7 +20,7 @@ struct stripe {
34940 struct dm_dev *dev;
34941 sector_t physical_start;
34942
34943 - atomic_t error_count;
34944 + atomic_unchecked_t error_count;
34945 };
34946
34947 struct stripe_c {
34948 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
34949 kfree(sc);
34950 return r;
34951 }
34952 - atomic_set(&(sc->stripe[i].error_count), 0);
34953 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
34954 }
34955
34956 ti->private = sc;
34957 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
34958 DMEMIT("%d ", sc->stripes);
34959 for (i = 0; i < sc->stripes; i++) {
34960 DMEMIT("%s ", sc->stripe[i].dev->name);
34961 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
34962 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
34963 'D' : 'A';
34964 }
34965 buffer[i] = '\0';
34966 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
34967 */
34968 for (i = 0; i < sc->stripes; i++)
34969 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
34970 - atomic_inc(&(sc->stripe[i].error_count));
34971 - if (atomic_read(&(sc->stripe[i].error_count)) <
34972 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
34973 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
34974 DM_IO_ERROR_THRESHOLD)
34975 schedule_work(&sc->trigger_event);
34976 }
34977 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
34978 index fa29557..d24a5b7 100644
34979 --- a/drivers/md/dm-table.c
34980 +++ b/drivers/md/dm-table.c
34981 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
34982 if (!dev_size)
34983 return 0;
34984
34985 - if ((start >= dev_size) || (start + len > dev_size)) {
34986 + if ((start >= dev_size) || (len > dev_size - start)) {
34987 DMWARN("%s: %s too small for target: "
34988 "start=%llu, len=%llu, dev_size=%llu",
34989 dm_device_name(ti->table->md), bdevname(bdev, b),
34990 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
34991 index 693e149..b7e0fde 100644
34992 --- a/drivers/md/dm-thin-metadata.c
34993 +++ b/drivers/md/dm-thin-metadata.c
34994 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34995 {
34996 pmd->info.tm = pmd->tm;
34997 pmd->info.levels = 2;
34998 - pmd->info.value_type.context = pmd->data_sm;
34999 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35000 pmd->info.value_type.size = sizeof(__le64);
35001 pmd->info.value_type.inc = data_block_inc;
35002 pmd->info.value_type.dec = data_block_dec;
35003 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35004
35005 pmd->bl_info.tm = pmd->tm;
35006 pmd->bl_info.levels = 1;
35007 - pmd->bl_info.value_type.context = pmd->data_sm;
35008 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35009 pmd->bl_info.value_type.size = sizeof(__le64);
35010 pmd->bl_info.value_type.inc = data_block_inc;
35011 pmd->bl_info.value_type.dec = data_block_dec;
35012 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35013 index 77e6eff..913d695 100644
35014 --- a/drivers/md/dm.c
35015 +++ b/drivers/md/dm.c
35016 @@ -182,9 +182,9 @@ struct mapped_device {
35017 /*
35018 * Event handling.
35019 */
35020 - atomic_t event_nr;
35021 + atomic_unchecked_t event_nr;
35022 wait_queue_head_t eventq;
35023 - atomic_t uevent_seq;
35024 + atomic_unchecked_t uevent_seq;
35025 struct list_head uevent_list;
35026 spinlock_t uevent_lock; /* Protect access to uevent_list */
35027
35028 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35029 rwlock_init(&md->map_lock);
35030 atomic_set(&md->holders, 1);
35031 atomic_set(&md->open_count, 0);
35032 - atomic_set(&md->event_nr, 0);
35033 - atomic_set(&md->uevent_seq, 0);
35034 + atomic_set_unchecked(&md->event_nr, 0);
35035 + atomic_set_unchecked(&md->uevent_seq, 0);
35036 INIT_LIST_HEAD(&md->uevent_list);
35037 spin_lock_init(&md->uevent_lock);
35038
35039 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35040
35041 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35042
35043 - atomic_inc(&md->event_nr);
35044 + atomic_inc_unchecked(&md->event_nr);
35045 wake_up(&md->eventq);
35046 }
35047
35048 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35049
35050 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35051 {
35052 - return atomic_add_return(1, &md->uevent_seq);
35053 + return atomic_add_return_unchecked(1, &md->uevent_seq);
35054 }
35055
35056 uint32_t dm_get_event_nr(struct mapped_device *md)
35057 {
35058 - return atomic_read(&md->event_nr);
35059 + return atomic_read_unchecked(&md->event_nr);
35060 }
35061
35062 int dm_wait_event(struct mapped_device *md, int event_nr)
35063 {
35064 return wait_event_interruptible(md->eventq,
35065 - (event_nr != atomic_read(&md->event_nr)));
35066 + (event_nr != atomic_read_unchecked(&md->event_nr)));
35067 }
35068
35069 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35070 diff --git a/drivers/md/md.c b/drivers/md/md.c
35071 index 6120071..31d9be2 100644
35072 --- a/drivers/md/md.c
35073 +++ b/drivers/md/md.c
35074 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35075 * start build, activate spare
35076 */
35077 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35078 -static atomic_t md_event_count;
35079 +static atomic_unchecked_t md_event_count;
35080 void md_new_event(struct mddev *mddev)
35081 {
35082 - atomic_inc(&md_event_count);
35083 + atomic_inc_unchecked(&md_event_count);
35084 wake_up(&md_event_waiters);
35085 }
35086 EXPORT_SYMBOL_GPL(md_new_event);
35087 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35088 */
35089 static void md_new_event_inintr(struct mddev *mddev)
35090 {
35091 - atomic_inc(&md_event_count);
35092 + atomic_inc_unchecked(&md_event_count);
35093 wake_up(&md_event_waiters);
35094 }
35095
35096 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35097 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35098 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35099 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35100 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35101 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35102
35103 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35104 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35105 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35106 else
35107 sb->resync_offset = cpu_to_le64(0);
35108
35109 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35110 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35111
35112 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35113 sb->size = cpu_to_le64(mddev->dev_sectors);
35114 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35115 static ssize_t
35116 errors_show(struct md_rdev *rdev, char *page)
35117 {
35118 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35119 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35120 }
35121
35122 static ssize_t
35123 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35124 char *e;
35125 unsigned long n = simple_strtoul(buf, &e, 10);
35126 if (*buf && (*e == 0 || *e == '\n')) {
35127 - atomic_set(&rdev->corrected_errors, n);
35128 + atomic_set_unchecked(&rdev->corrected_errors, n);
35129 return len;
35130 }
35131 return -EINVAL;
35132 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35133 rdev->sb_loaded = 0;
35134 rdev->bb_page = NULL;
35135 atomic_set(&rdev->nr_pending, 0);
35136 - atomic_set(&rdev->read_errors, 0);
35137 - atomic_set(&rdev->corrected_errors, 0);
35138 + atomic_set_unchecked(&rdev->read_errors, 0);
35139 + atomic_set_unchecked(&rdev->corrected_errors, 0);
35140
35141 INIT_LIST_HEAD(&rdev->same_set);
35142 init_waitqueue_head(&rdev->blocked_wait);
35143 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35144
35145 spin_unlock(&pers_lock);
35146 seq_printf(seq, "\n");
35147 - seq->poll_event = atomic_read(&md_event_count);
35148 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35149 return 0;
35150 }
35151 if (v == (void*)2) {
35152 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35153 return error;
35154
35155 seq = file->private_data;
35156 - seq->poll_event = atomic_read(&md_event_count);
35157 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35158 return error;
35159 }
35160
35161 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35162 /* always allow read */
35163 mask = POLLIN | POLLRDNORM;
35164
35165 - if (seq->poll_event != atomic_read(&md_event_count))
35166 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35167 mask |= POLLERR | POLLPRI;
35168 return mask;
35169 }
35170 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35171 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35172 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35173 (int)part_stat_read(&disk->part0, sectors[1]) -
35174 - atomic_read(&disk->sync_io);
35175 + atomic_read_unchecked(&disk->sync_io);
35176 /* sync IO will cause sync_io to increase before the disk_stats
35177 * as sync_io is counted when a request starts, and
35178 * disk_stats is counted when it completes.
35179 diff --git a/drivers/md/md.h b/drivers/md/md.h
35180 index af443ab..0f93be3 100644
35181 --- a/drivers/md/md.h
35182 +++ b/drivers/md/md.h
35183 @@ -94,13 +94,13 @@ struct md_rdev {
35184 * only maintained for arrays that
35185 * support hot removal
35186 */
35187 - atomic_t read_errors; /* number of consecutive read errors that
35188 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35189 * we have tried to ignore.
35190 */
35191 struct timespec last_read_error; /* monotonic time since our
35192 * last read error
35193 */
35194 - atomic_t corrected_errors; /* number of corrected read errors,
35195 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35196 * for reporting to userspace and storing
35197 * in superblock.
35198 */
35199 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35200
35201 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35202 {
35203 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35204 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35205 }
35206
35207 struct md_personality
35208 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35209 index 1cbfc6b..56e1dbb 100644
35210 --- a/drivers/md/persistent-data/dm-space-map.h
35211 +++ b/drivers/md/persistent-data/dm-space-map.h
35212 @@ -60,6 +60,7 @@ struct dm_space_map {
35213 int (*root_size)(struct dm_space_map *sm, size_t *result);
35214 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35215 };
35216 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35217
35218 /*----------------------------------------------------------------*/
35219
35220 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35221 index a0f7309..5599dbc 100644
35222 --- a/drivers/md/raid1.c
35223 +++ b/drivers/md/raid1.c
35224 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35225 if (r1_sync_page_io(rdev, sect, s,
35226 bio->bi_io_vec[idx].bv_page,
35227 READ) != 0)
35228 - atomic_add(s, &rdev->corrected_errors);
35229 + atomic_add_unchecked(s, &rdev->corrected_errors);
35230 }
35231 sectors -= s;
35232 sect += s;
35233 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35234 test_bit(In_sync, &rdev->flags)) {
35235 if (r1_sync_page_io(rdev, sect, s,
35236 conf->tmppage, READ)) {
35237 - atomic_add(s, &rdev->corrected_errors);
35238 + atomic_add_unchecked(s, &rdev->corrected_errors);
35239 printk(KERN_INFO
35240 "md/raid1:%s: read error corrected "
35241 "(%d sectors at %llu on %s)\n",
35242 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35243 index c9acbd7..386cd3e 100644
35244 --- a/drivers/md/raid10.c
35245 +++ b/drivers/md/raid10.c
35246 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35247 /* The write handler will notice the lack of
35248 * R10BIO_Uptodate and record any errors etc
35249 */
35250 - atomic_add(r10_bio->sectors,
35251 + atomic_add_unchecked(r10_bio->sectors,
35252 &conf->mirrors[d].rdev->corrected_errors);
35253
35254 /* for reconstruct, we always reschedule after a read.
35255 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35256 {
35257 struct timespec cur_time_mon;
35258 unsigned long hours_since_last;
35259 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35260 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35261
35262 ktime_get_ts(&cur_time_mon);
35263
35264 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35265 * overflowing the shift of read_errors by hours_since_last.
35266 */
35267 if (hours_since_last >= 8 * sizeof(read_errors))
35268 - atomic_set(&rdev->read_errors, 0);
35269 + atomic_set_unchecked(&rdev->read_errors, 0);
35270 else
35271 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35272 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35273 }
35274
35275 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35276 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35277 return;
35278
35279 check_decay_read_errors(mddev, rdev);
35280 - atomic_inc(&rdev->read_errors);
35281 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35282 + atomic_inc_unchecked(&rdev->read_errors);
35283 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35284 char b[BDEVNAME_SIZE];
35285 bdevname(rdev->bdev, b);
35286
35287 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35288 "md/raid10:%s: %s: Raid device exceeded "
35289 "read_error threshold [cur %d:max %d]\n",
35290 mdname(mddev), b,
35291 - atomic_read(&rdev->read_errors), max_read_errors);
35292 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35293 printk(KERN_NOTICE
35294 "md/raid10:%s: %s: Failing raid device\n",
35295 mdname(mddev), b);
35296 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35297 sect +
35298 choose_data_offset(r10_bio, rdev)),
35299 bdevname(rdev->bdev, b));
35300 - atomic_add(s, &rdev->corrected_errors);
35301 + atomic_add_unchecked(s, &rdev->corrected_errors);
35302 }
35303
35304 rdev_dec_pending(rdev, mddev);
35305 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35306 index a450268..c4168a9 100644
35307 --- a/drivers/md/raid5.c
35308 +++ b/drivers/md/raid5.c
35309 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35310 mdname(conf->mddev), STRIPE_SECTORS,
35311 (unsigned long long)s,
35312 bdevname(rdev->bdev, b));
35313 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35314 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35315 clear_bit(R5_ReadError, &sh->dev[i].flags);
35316 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35317 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35318 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35319
35320 - if (atomic_read(&rdev->read_errors))
35321 - atomic_set(&rdev->read_errors, 0);
35322 + if (atomic_read_unchecked(&rdev->read_errors))
35323 + atomic_set_unchecked(&rdev->read_errors, 0);
35324 } else {
35325 const char *bdn = bdevname(rdev->bdev, b);
35326 int retry = 0;
35327 int set_bad = 0;
35328
35329 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35330 - atomic_inc(&rdev->read_errors);
35331 + atomic_inc_unchecked(&rdev->read_errors);
35332 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35333 printk_ratelimited(
35334 KERN_WARNING
35335 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35336 mdname(conf->mddev),
35337 (unsigned long long)s,
35338 bdn);
35339 - } else if (atomic_read(&rdev->read_errors)
35340 + } else if (atomic_read_unchecked(&rdev->read_errors)
35341 > conf->max_nr_stripes)
35342 printk(KERN_WARNING
35343 "md/raid:%s: Too many read errors, failing device %s.\n",
35344 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35345 index d33101a..6b13069 100644
35346 --- a/drivers/media/dvb-core/dvbdev.c
35347 +++ b/drivers/media/dvb-core/dvbdev.c
35348 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35349 const struct dvb_device *template, void *priv, int type)
35350 {
35351 struct dvb_device *dvbdev;
35352 - struct file_operations *dvbdevfops;
35353 + file_operations_no_const *dvbdevfops;
35354 struct device *clsdev;
35355 int minor;
35356 int id;
35357 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35358 index 404f63a..4796533 100644
35359 --- a/drivers/media/dvb-frontends/dib3000.h
35360 +++ b/drivers/media/dvb-frontends/dib3000.h
35361 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35362 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35363 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35364 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35365 -};
35366 +} __no_const;
35367
35368 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35369 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35370 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35371 index 3aa6856..435ad25 100644
35372 --- a/drivers/media/pci/cx88/cx88-alsa.c
35373 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35374 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35375 * Only boards with eeprom and byte 1 at eeprom=1 have it
35376 */
35377
35378 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35379 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35380 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35381 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35382 {0, }
35383 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35384 index feff57e..66a2c67 100644
35385 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35386 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35387 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35388 .subvendor = _subvend, .subdevice = _subdev, \
35389 .driver_data = (unsigned long)&_driverdata }
35390
35391 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35392 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35393 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35394 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35395 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35396 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35397 index 96a13ed..6df45b4 100644
35398 --- a/drivers/media/pci/ngene/ngene-cards.c
35399 +++ b/drivers/media/pci/ngene/ngene-cards.c
35400 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35401
35402 /****************************************************************************/
35403
35404 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35405 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35406 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35407 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35408 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35409 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35410 index a3b1a34..71ce0e3 100644
35411 --- a/drivers/media/platform/omap/omap_vout.c
35412 +++ b/drivers/media/platform/omap/omap_vout.c
35413 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35414 OMAP_VIDEO2,
35415 };
35416
35417 -static struct videobuf_queue_ops video_vbq_ops;
35418 /* Variables configurable through module params*/
35419 static u32 video1_numbuffers = 3;
35420 static u32 video2_numbuffers = 3;
35421 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35422 {
35423 struct videobuf_queue *q;
35424 struct omap_vout_device *vout = NULL;
35425 + static struct videobuf_queue_ops video_vbq_ops = {
35426 + .buf_setup = omap_vout_buffer_setup,
35427 + .buf_prepare = omap_vout_buffer_prepare,
35428 + .buf_release = omap_vout_buffer_release,
35429 + .buf_queue = omap_vout_buffer_queue,
35430 + };
35431
35432 vout = video_drvdata(file);
35433 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35434 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35435 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35436
35437 q = &vout->vbq;
35438 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35439 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35440 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35441 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35442 spin_lock_init(&vout->vbq_lock);
35443
35444 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35445 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35446 index ddb422e..8cf008e 100644
35447 --- a/drivers/media/platform/s5p-tv/mixer.h
35448 +++ b/drivers/media/platform/s5p-tv/mixer.h
35449 @@ -155,7 +155,7 @@ struct mxr_layer {
35450 /** layer index (unique identifier) */
35451 int idx;
35452 /** callbacks for layer methods */
35453 - struct mxr_layer_ops ops;
35454 + struct mxr_layer_ops *ops;
35455 /** format array */
35456 const struct mxr_format **fmt_array;
35457 /** size of format array */
35458 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35459 index b93a21f..2535195 100644
35460 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35461 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35462 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35463 {
35464 struct mxr_layer *layer;
35465 int ret;
35466 - struct mxr_layer_ops ops = {
35467 + static struct mxr_layer_ops ops = {
35468 .release = mxr_graph_layer_release,
35469 .buffer_set = mxr_graph_buffer_set,
35470 .stream_set = mxr_graph_stream_set,
35471 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35472 index 3b1670a..595c939 100644
35473 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
35474 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35475 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35476 layer->update_buf = next;
35477 }
35478
35479 - layer->ops.buffer_set(layer, layer->update_buf);
35480 + layer->ops->buffer_set(layer, layer->update_buf);
35481
35482 if (done && done != layer->shadow_buf)
35483 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35484 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35485 index 0c1cd89..6574647 100644
35486 --- a/drivers/media/platform/s5p-tv/mixer_video.c
35487 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
35488 @@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35489 layer->geo.src.height = layer->geo.src.full_height;
35490
35491 mxr_geometry_dump(mdev, &layer->geo);
35492 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35493 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35494 mxr_geometry_dump(mdev, &layer->geo);
35495 }
35496
35497 @@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35498 layer->geo.dst.full_width = mbus_fmt.width;
35499 layer->geo.dst.full_height = mbus_fmt.height;
35500 layer->geo.dst.field = mbus_fmt.field;
35501 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35502 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35503
35504 mxr_geometry_dump(mdev, &layer->geo);
35505 }
35506 @@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35507 /* set source size to highest accepted value */
35508 geo->src.full_width = max(geo->dst.full_width, pix->width);
35509 geo->src.full_height = max(geo->dst.full_height, pix->height);
35510 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35511 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35512 mxr_geometry_dump(mdev, &layer->geo);
35513 /* set cropping to total visible screen */
35514 geo->src.width = pix->width;
35515 @@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35516 geo->src.x_offset = 0;
35517 geo->src.y_offset = 0;
35518 /* assure consistency of geometry */
35519 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35520 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35521 mxr_geometry_dump(mdev, &layer->geo);
35522 /* set full size to lowest possible value */
35523 geo->src.full_width = 0;
35524 geo->src.full_height = 0;
35525 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35526 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35527 mxr_geometry_dump(mdev, &layer->geo);
35528
35529 /* returning results */
35530 @@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35531 target->width = s->r.width;
35532 target->height = s->r.height;
35533
35534 - layer->ops.fix_geometry(layer, stage, s->flags);
35535 + layer->ops->fix_geometry(layer, stage, s->flags);
35536
35537 /* retrieve update selection rectangle */
35538 res.left = target->x_offset;
35539 @@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35540 mxr_output_get(mdev);
35541
35542 mxr_layer_update_output(layer);
35543 - layer->ops.format_set(layer);
35544 + layer->ops->format_set(layer);
35545 /* enabling layer in hardware */
35546 spin_lock_irqsave(&layer->enq_slock, flags);
35547 layer->state = MXR_LAYER_STREAMING;
35548 spin_unlock_irqrestore(&layer->enq_slock, flags);
35549
35550 - layer->ops.stream_set(layer, MXR_ENABLE);
35551 + layer->ops->stream_set(layer, MXR_ENABLE);
35552 mxr_streamer_get(mdev);
35553
35554 return 0;
35555 @@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35556 spin_unlock_irqrestore(&layer->enq_slock, flags);
35557
35558 /* disabling layer in hardware */
35559 - layer->ops.stream_set(layer, MXR_DISABLE);
35560 + layer->ops->stream_set(layer, MXR_DISABLE);
35561 /* remove one streamer */
35562 mxr_streamer_put(mdev);
35563 /* allow changes in output configuration */
35564 @@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35565
35566 void mxr_layer_release(struct mxr_layer *layer)
35567 {
35568 - if (layer->ops.release)
35569 - layer->ops.release(layer);
35570 + if (layer->ops->release)
35571 + layer->ops->release(layer);
35572 }
35573
35574 void mxr_base_layer_release(struct mxr_layer *layer)
35575 @@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35576
35577 layer->mdev = mdev;
35578 layer->idx = idx;
35579 - layer->ops = *ops;
35580 + layer->ops = ops;
35581
35582 spin_lock_init(&layer->enq_slock);
35583 INIT_LIST_HEAD(&layer->enq_list);
35584 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35585 index 3d13a63..da31bf1 100644
35586 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35587 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35588 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35589 {
35590 struct mxr_layer *layer;
35591 int ret;
35592 - struct mxr_layer_ops ops = {
35593 + static struct mxr_layer_ops ops = {
35594 .release = mxr_vp_layer_release,
35595 .buffer_set = mxr_vp_buffer_set,
35596 .stream_set = mxr_vp_stream_set,
35597 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35598 index 02194c0..36d69c1 100644
35599 --- a/drivers/media/platform/timblogiw.c
35600 +++ b/drivers/media/platform/timblogiw.c
35601 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35602
35603 /* Platform device functions */
35604
35605 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35606 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35607 .vidioc_querycap = timblogiw_querycap,
35608 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35609 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35610 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35611 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35612 };
35613
35614 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35615 +static struct v4l2_file_operations timblogiw_fops = {
35616 .owner = THIS_MODULE,
35617 .open = timblogiw_open,
35618 .release = timblogiw_close,
35619 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35620 index 697a421..16c5a5f 100644
35621 --- a/drivers/media/radio/radio-cadet.c
35622 +++ b/drivers/media/radio/radio-cadet.c
35623 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35624 unsigned char readbuf[RDS_BUFFER];
35625 int i = 0;
35626
35627 + if (count > RDS_BUFFER)
35628 + return -EFAULT;
35629 mutex_lock(&dev->lock);
35630 if (dev->rdsstat == 0)
35631 cadet_start_rds(dev);
35632 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35633 while (i < count && dev->rdsin != dev->rdsout)
35634 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35635
35636 - if (i && copy_to_user(data, readbuf, i))
35637 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35638 i = -EFAULT;
35639 unlock:
35640 mutex_unlock(&dev->lock);
35641 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35642 index 3940bb0..fb3952a 100644
35643 --- a/drivers/media/usb/dvb-usb/cxusb.c
35644 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35645 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35646
35647 struct dib0700_adapter_state {
35648 int (*set_param_save) (struct dvb_frontend *);
35649 -};
35650 +} __no_const;
35651
35652 static int dib7070_set_param_override(struct dvb_frontend *fe)
35653 {
35654 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35655 index 9382895..ac8093c 100644
35656 --- a/drivers/media/usb/dvb-usb/dw2102.c
35657 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35658 @@ -95,7 +95,7 @@ struct su3000_state {
35659
35660 struct s6x0_state {
35661 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35662 -};
35663 +} __no_const;
35664
35665 /* debug */
35666 static int dvb_usb_dw2102_debug;
35667 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35668 index fb69baa..cf7ad22 100644
35669 --- a/drivers/message/fusion/mptbase.c
35670 +++ b/drivers/message/fusion/mptbase.c
35671 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35672 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35673 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35674
35675 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35676 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35677 +#else
35678 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35679 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35680 +#endif
35681 +
35682 /*
35683 * Rounding UP to nearest 4-kB boundary here...
35684 */
35685 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35686 index 551262e..7551198 100644
35687 --- a/drivers/message/fusion/mptsas.c
35688 +++ b/drivers/message/fusion/mptsas.c
35689 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35690 return 0;
35691 }
35692
35693 +static inline void
35694 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35695 +{
35696 + if (phy_info->port_details) {
35697 + phy_info->port_details->rphy = rphy;
35698 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35699 + ioc->name, rphy));
35700 + }
35701 +
35702 + if (rphy) {
35703 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35704 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35705 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35706 + ioc->name, rphy, rphy->dev.release));
35707 + }
35708 +}
35709 +
35710 /* no mutex */
35711 static void
35712 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35713 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35714 return NULL;
35715 }
35716
35717 -static inline void
35718 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35719 -{
35720 - if (phy_info->port_details) {
35721 - phy_info->port_details->rphy = rphy;
35722 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35723 - ioc->name, rphy));
35724 - }
35725 -
35726 - if (rphy) {
35727 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35728 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35729 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35730 - ioc->name, rphy, rphy->dev.release));
35731 - }
35732 -}
35733 -
35734 static inline struct sas_port *
35735 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35736 {
35737 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35738 index 0c3ced7..1fe34ec 100644
35739 --- a/drivers/message/fusion/mptscsih.c
35740 +++ b/drivers/message/fusion/mptscsih.c
35741 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35742
35743 h = shost_priv(SChost);
35744
35745 - if (h) {
35746 - if (h->info_kbuf == NULL)
35747 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35748 - return h->info_kbuf;
35749 - h->info_kbuf[0] = '\0';
35750 + if (!h)
35751 + return NULL;
35752
35753 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35754 - h->info_kbuf[size-1] = '\0';
35755 - }
35756 + if (h->info_kbuf == NULL)
35757 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35758 + return h->info_kbuf;
35759 + h->info_kbuf[0] = '\0';
35760 +
35761 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35762 + h->info_kbuf[size-1] = '\0';
35763
35764 return h->info_kbuf;
35765 }
35766 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35767 index 8001aa6..b137580 100644
35768 --- a/drivers/message/i2o/i2o_proc.c
35769 +++ b/drivers/message/i2o/i2o_proc.c
35770 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35771 "Array Controller Device"
35772 };
35773
35774 -static char *chtostr(char *tmp, u8 *chars, int n)
35775 -{
35776 - tmp[0] = 0;
35777 - return strncat(tmp, (char *)chars, n);
35778 -}
35779 -
35780 static int i2o_report_query_status(struct seq_file *seq, int block_status,
35781 char *group)
35782 {
35783 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35784 } *result;
35785
35786 i2o_exec_execute_ddm_table ddm_table;
35787 - char tmp[28 + 1];
35788
35789 result = kmalloc(sizeof(*result), GFP_KERNEL);
35790 if (!result)
35791 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35792
35793 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
35794 seq_printf(seq, "%-#8x", ddm_table.module_id);
35795 - seq_printf(seq, "%-29s",
35796 - chtostr(tmp, ddm_table.module_name_version, 28));
35797 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
35798 seq_printf(seq, "%9d ", ddm_table.data_size);
35799 seq_printf(seq, "%8d", ddm_table.code_size);
35800
35801 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35802
35803 i2o_driver_result_table *result;
35804 i2o_driver_store_table *dst;
35805 - char tmp[28 + 1];
35806
35807 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
35808 if (result == NULL)
35809 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35810
35811 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
35812 seq_printf(seq, "%-#8x", dst->module_id);
35813 - seq_printf(seq, "%-29s",
35814 - chtostr(tmp, dst->module_name_version, 28));
35815 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
35816 + seq_printf(seq, "%-.28s", dst->module_name_version);
35817 + seq_printf(seq, "%-.8s", dst->date);
35818 seq_printf(seq, "%8d ", dst->module_size);
35819 seq_printf(seq, "%8d ", dst->mpb_size);
35820 seq_printf(seq, "0x%04x", dst->module_flags);
35821 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35822 // == (allow) 512d bytes (max)
35823 static u16 *work16 = (u16 *) work32;
35824 int token;
35825 - char tmp[16 + 1];
35826
35827 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
35828
35829 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35830 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
35831 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
35832 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
35833 - seq_printf(seq, "Vendor info : %s\n",
35834 - chtostr(tmp, (u8 *) (work32 + 2), 16));
35835 - seq_printf(seq, "Product info : %s\n",
35836 - chtostr(tmp, (u8 *) (work32 + 6), 16));
35837 - seq_printf(seq, "Description : %s\n",
35838 - chtostr(tmp, (u8 *) (work32 + 10), 16));
35839 - seq_printf(seq, "Product rev. : %s\n",
35840 - chtostr(tmp, (u8 *) (work32 + 14), 8));
35841 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
35842 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
35843 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
35844 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
35845
35846 seq_printf(seq, "Serial number : ");
35847 print_serial_number(seq, (u8 *) (work32 + 16),
35848 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35849 u8 pad[256]; // allow up to 256 byte (max) serial number
35850 } result;
35851
35852 - char tmp[24 + 1];
35853 -
35854 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
35855
35856 if (token < 0) {
35857 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35858 }
35859
35860 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
35861 - seq_printf(seq, "Module name : %s\n",
35862 - chtostr(tmp, result.module_name, 24));
35863 - seq_printf(seq, "Module revision : %s\n",
35864 - chtostr(tmp, result.module_rev, 8));
35865 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
35866 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
35867
35868 seq_printf(seq, "Serial number : ");
35869 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
35870 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35871 u8 instance_number[4];
35872 } result;
35873
35874 - char tmp[64 + 1];
35875 -
35876 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
35877
35878 if (token < 0) {
35879 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35880 return 0;
35881 }
35882
35883 - seq_printf(seq, "Device name : %s\n",
35884 - chtostr(tmp, result.device_name, 64));
35885 - seq_printf(seq, "Service name : %s\n",
35886 - chtostr(tmp, result.service_name, 64));
35887 - seq_printf(seq, "Physical name : %s\n",
35888 - chtostr(tmp, result.physical_location, 64));
35889 - seq_printf(seq, "Instance number : %s\n",
35890 - chtostr(tmp, result.instance_number, 4));
35891 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
35892 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
35893 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
35894 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
35895
35896 return 0;
35897 }
35898 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
35899 index a8c08f3..155fe3d 100644
35900 --- a/drivers/message/i2o/iop.c
35901 +++ b/drivers/message/i2o/iop.c
35902 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
35903
35904 spin_lock_irqsave(&c->context_list_lock, flags);
35905
35906 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
35907 - atomic_inc(&c->context_list_counter);
35908 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
35909 + atomic_inc_unchecked(&c->context_list_counter);
35910
35911 - entry->context = atomic_read(&c->context_list_counter);
35912 + entry->context = atomic_read_unchecked(&c->context_list_counter);
35913
35914 list_add(&entry->list, &c->context_list);
35915
35916 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
35917
35918 #if BITS_PER_LONG == 64
35919 spin_lock_init(&c->context_list_lock);
35920 - atomic_set(&c->context_list_counter, 0);
35921 + atomic_set_unchecked(&c->context_list_counter, 0);
35922 INIT_LIST_HEAD(&c->context_list);
35923 #endif
35924
35925 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35926 index 965c480..71f2db9 100644
35927 --- a/drivers/mfd/janz-cmodio.c
35928 +++ b/drivers/mfd/janz-cmodio.c
35929 @@ -13,6 +13,7 @@
35930
35931 #include <linux/kernel.h>
35932 #include <linux/module.h>
35933 +#include <linux/slab.h>
35934 #include <linux/init.h>
35935 #include <linux/pci.h>
35936 #include <linux/interrupt.h>
35937 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
35938 index 3aa9a96..59cf685 100644
35939 --- a/drivers/misc/kgdbts.c
35940 +++ b/drivers/misc/kgdbts.c
35941 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
35942 char before[BREAK_INSTR_SIZE];
35943 char after[BREAK_INSTR_SIZE];
35944
35945 - probe_kernel_read(before, (char *)kgdbts_break_test,
35946 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
35947 BREAK_INSTR_SIZE);
35948 init_simple_test();
35949 ts.tst = plant_and_detach_test;
35950 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
35951 /* Activate test with initial breakpoint */
35952 if (!is_early)
35953 kgdb_breakpoint();
35954 - probe_kernel_read(after, (char *)kgdbts_break_test,
35955 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
35956 BREAK_INSTR_SIZE);
35957 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
35958 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
35959 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35960 index 4a87e5c..76bdf5c 100644
35961 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
35962 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35963 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35964 * the lid is closed. This leads to interrupts as soon as a little move
35965 * is done.
35966 */
35967 - atomic_inc(&lis3->count);
35968 + atomic_inc_unchecked(&lis3->count);
35969
35970 wake_up_interruptible(&lis3->misc_wait);
35971 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35972 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35973 if (lis3->pm_dev)
35974 pm_runtime_get_sync(lis3->pm_dev);
35975
35976 - atomic_set(&lis3->count, 0);
35977 + atomic_set_unchecked(&lis3->count, 0);
35978 return 0;
35979 }
35980
35981 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35982 add_wait_queue(&lis3->misc_wait, &wait);
35983 while (true) {
35984 set_current_state(TASK_INTERRUPTIBLE);
35985 - data = atomic_xchg(&lis3->count, 0);
35986 + data = atomic_xchg_unchecked(&lis3->count, 0);
35987 if (data)
35988 break;
35989
35990 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35991 struct lis3lv02d, miscdev);
35992
35993 poll_wait(file, &lis3->misc_wait, wait);
35994 - if (atomic_read(&lis3->count))
35995 + if (atomic_read_unchecked(&lis3->count))
35996 return POLLIN | POLLRDNORM;
35997 return 0;
35998 }
35999 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36000 index c439c82..1f20f57 100644
36001 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36002 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36003 @@ -297,7 +297,7 @@ struct lis3lv02d {
36004 struct input_polled_dev *idev; /* input device */
36005 struct platform_device *pdev; /* platform device */
36006 struct regulator_bulk_data regulators[2];
36007 - atomic_t count; /* interrupt count after last read */
36008 + atomic_unchecked_t count; /* interrupt count after last read */
36009 union axis_conversion ac; /* hw -> logical axis */
36010 int mapped_btns[3];
36011
36012 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36013 index 2f30bad..c4c13d0 100644
36014 --- a/drivers/misc/sgi-gru/gruhandles.c
36015 +++ b/drivers/misc/sgi-gru/gruhandles.c
36016 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36017 unsigned long nsec;
36018
36019 nsec = CLKS2NSEC(clks);
36020 - atomic_long_inc(&mcs_op_statistics[op].count);
36021 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36022 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36023 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36024 if (mcs_op_statistics[op].max < nsec)
36025 mcs_op_statistics[op].max = nsec;
36026 }
36027 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36028 index 950dbe9..eeef0f8 100644
36029 --- a/drivers/misc/sgi-gru/gruprocfs.c
36030 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36031 @@ -32,9 +32,9 @@
36032
36033 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36034
36035 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36036 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36037 {
36038 - unsigned long val = atomic_long_read(v);
36039 + unsigned long val = atomic_long_read_unchecked(v);
36040
36041 seq_printf(s, "%16lu %s\n", val, id);
36042 }
36043 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36044
36045 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36046 for (op = 0; op < mcsop_last; op++) {
36047 - count = atomic_long_read(&mcs_op_statistics[op].count);
36048 - total = atomic_long_read(&mcs_op_statistics[op].total);
36049 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36050 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36051 max = mcs_op_statistics[op].max;
36052 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36053 count ? total / count : 0, max);
36054 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36055 index 5c3ce24..4915ccb 100644
36056 --- a/drivers/misc/sgi-gru/grutables.h
36057 +++ b/drivers/misc/sgi-gru/grutables.h
36058 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36059 * GRU statistics.
36060 */
36061 struct gru_stats_s {
36062 - atomic_long_t vdata_alloc;
36063 - atomic_long_t vdata_free;
36064 - atomic_long_t gts_alloc;
36065 - atomic_long_t gts_free;
36066 - atomic_long_t gms_alloc;
36067 - atomic_long_t gms_free;
36068 - atomic_long_t gts_double_allocate;
36069 - atomic_long_t assign_context;
36070 - atomic_long_t assign_context_failed;
36071 - atomic_long_t free_context;
36072 - atomic_long_t load_user_context;
36073 - atomic_long_t load_kernel_context;
36074 - atomic_long_t lock_kernel_context;
36075 - atomic_long_t unlock_kernel_context;
36076 - atomic_long_t steal_user_context;
36077 - atomic_long_t steal_kernel_context;
36078 - atomic_long_t steal_context_failed;
36079 - atomic_long_t nopfn;
36080 - atomic_long_t asid_new;
36081 - atomic_long_t asid_next;
36082 - atomic_long_t asid_wrap;
36083 - atomic_long_t asid_reuse;
36084 - atomic_long_t intr;
36085 - atomic_long_t intr_cbr;
36086 - atomic_long_t intr_tfh;
36087 - atomic_long_t intr_spurious;
36088 - atomic_long_t intr_mm_lock_failed;
36089 - atomic_long_t call_os;
36090 - atomic_long_t call_os_wait_queue;
36091 - atomic_long_t user_flush_tlb;
36092 - atomic_long_t user_unload_context;
36093 - atomic_long_t user_exception;
36094 - atomic_long_t set_context_option;
36095 - atomic_long_t check_context_retarget_intr;
36096 - atomic_long_t check_context_unload;
36097 - atomic_long_t tlb_dropin;
36098 - atomic_long_t tlb_preload_page;
36099 - atomic_long_t tlb_dropin_fail_no_asid;
36100 - atomic_long_t tlb_dropin_fail_upm;
36101 - atomic_long_t tlb_dropin_fail_invalid;
36102 - atomic_long_t tlb_dropin_fail_range_active;
36103 - atomic_long_t tlb_dropin_fail_idle;
36104 - atomic_long_t tlb_dropin_fail_fmm;
36105 - atomic_long_t tlb_dropin_fail_no_exception;
36106 - atomic_long_t tfh_stale_on_fault;
36107 - atomic_long_t mmu_invalidate_range;
36108 - atomic_long_t mmu_invalidate_page;
36109 - atomic_long_t flush_tlb;
36110 - atomic_long_t flush_tlb_gru;
36111 - atomic_long_t flush_tlb_gru_tgh;
36112 - atomic_long_t flush_tlb_gru_zero_asid;
36113 + atomic_long_unchecked_t vdata_alloc;
36114 + atomic_long_unchecked_t vdata_free;
36115 + atomic_long_unchecked_t gts_alloc;
36116 + atomic_long_unchecked_t gts_free;
36117 + atomic_long_unchecked_t gms_alloc;
36118 + atomic_long_unchecked_t gms_free;
36119 + atomic_long_unchecked_t gts_double_allocate;
36120 + atomic_long_unchecked_t assign_context;
36121 + atomic_long_unchecked_t assign_context_failed;
36122 + atomic_long_unchecked_t free_context;
36123 + atomic_long_unchecked_t load_user_context;
36124 + atomic_long_unchecked_t load_kernel_context;
36125 + atomic_long_unchecked_t lock_kernel_context;
36126 + atomic_long_unchecked_t unlock_kernel_context;
36127 + atomic_long_unchecked_t steal_user_context;
36128 + atomic_long_unchecked_t steal_kernel_context;
36129 + atomic_long_unchecked_t steal_context_failed;
36130 + atomic_long_unchecked_t nopfn;
36131 + atomic_long_unchecked_t asid_new;
36132 + atomic_long_unchecked_t asid_next;
36133 + atomic_long_unchecked_t asid_wrap;
36134 + atomic_long_unchecked_t asid_reuse;
36135 + atomic_long_unchecked_t intr;
36136 + atomic_long_unchecked_t intr_cbr;
36137 + atomic_long_unchecked_t intr_tfh;
36138 + atomic_long_unchecked_t intr_spurious;
36139 + atomic_long_unchecked_t intr_mm_lock_failed;
36140 + atomic_long_unchecked_t call_os;
36141 + atomic_long_unchecked_t call_os_wait_queue;
36142 + atomic_long_unchecked_t user_flush_tlb;
36143 + atomic_long_unchecked_t user_unload_context;
36144 + atomic_long_unchecked_t user_exception;
36145 + atomic_long_unchecked_t set_context_option;
36146 + atomic_long_unchecked_t check_context_retarget_intr;
36147 + atomic_long_unchecked_t check_context_unload;
36148 + atomic_long_unchecked_t tlb_dropin;
36149 + atomic_long_unchecked_t tlb_preload_page;
36150 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36151 + atomic_long_unchecked_t tlb_dropin_fail_upm;
36152 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
36153 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
36154 + atomic_long_unchecked_t tlb_dropin_fail_idle;
36155 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
36156 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36157 + atomic_long_unchecked_t tfh_stale_on_fault;
36158 + atomic_long_unchecked_t mmu_invalidate_range;
36159 + atomic_long_unchecked_t mmu_invalidate_page;
36160 + atomic_long_unchecked_t flush_tlb;
36161 + atomic_long_unchecked_t flush_tlb_gru;
36162 + atomic_long_unchecked_t flush_tlb_gru_tgh;
36163 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36164
36165 - atomic_long_t copy_gpa;
36166 - atomic_long_t read_gpa;
36167 + atomic_long_unchecked_t copy_gpa;
36168 + atomic_long_unchecked_t read_gpa;
36169
36170 - atomic_long_t mesq_receive;
36171 - atomic_long_t mesq_receive_none;
36172 - atomic_long_t mesq_send;
36173 - atomic_long_t mesq_send_failed;
36174 - atomic_long_t mesq_noop;
36175 - atomic_long_t mesq_send_unexpected_error;
36176 - atomic_long_t mesq_send_lb_overflow;
36177 - atomic_long_t mesq_send_qlimit_reached;
36178 - atomic_long_t mesq_send_amo_nacked;
36179 - atomic_long_t mesq_send_put_nacked;
36180 - atomic_long_t mesq_page_overflow;
36181 - atomic_long_t mesq_qf_locked;
36182 - atomic_long_t mesq_qf_noop_not_full;
36183 - atomic_long_t mesq_qf_switch_head_failed;
36184 - atomic_long_t mesq_qf_unexpected_error;
36185 - atomic_long_t mesq_noop_unexpected_error;
36186 - atomic_long_t mesq_noop_lb_overflow;
36187 - atomic_long_t mesq_noop_qlimit_reached;
36188 - atomic_long_t mesq_noop_amo_nacked;
36189 - atomic_long_t mesq_noop_put_nacked;
36190 - atomic_long_t mesq_noop_page_overflow;
36191 + atomic_long_unchecked_t mesq_receive;
36192 + atomic_long_unchecked_t mesq_receive_none;
36193 + atomic_long_unchecked_t mesq_send;
36194 + atomic_long_unchecked_t mesq_send_failed;
36195 + atomic_long_unchecked_t mesq_noop;
36196 + atomic_long_unchecked_t mesq_send_unexpected_error;
36197 + atomic_long_unchecked_t mesq_send_lb_overflow;
36198 + atomic_long_unchecked_t mesq_send_qlimit_reached;
36199 + atomic_long_unchecked_t mesq_send_amo_nacked;
36200 + atomic_long_unchecked_t mesq_send_put_nacked;
36201 + atomic_long_unchecked_t mesq_page_overflow;
36202 + atomic_long_unchecked_t mesq_qf_locked;
36203 + atomic_long_unchecked_t mesq_qf_noop_not_full;
36204 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
36205 + atomic_long_unchecked_t mesq_qf_unexpected_error;
36206 + atomic_long_unchecked_t mesq_noop_unexpected_error;
36207 + atomic_long_unchecked_t mesq_noop_lb_overflow;
36208 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
36209 + atomic_long_unchecked_t mesq_noop_amo_nacked;
36210 + atomic_long_unchecked_t mesq_noop_put_nacked;
36211 + atomic_long_unchecked_t mesq_noop_page_overflow;
36212
36213 };
36214
36215 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36216 tghop_invalidate, mcsop_last};
36217
36218 struct mcs_op_statistic {
36219 - atomic_long_t count;
36220 - atomic_long_t total;
36221 + atomic_long_unchecked_t count;
36222 + atomic_long_unchecked_t total;
36223 unsigned long max;
36224 };
36225
36226 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36227
36228 #define STAT(id) do { \
36229 if (gru_options & OPT_STATS) \
36230 - atomic_long_inc(&gru_stats.id); \
36231 + atomic_long_inc_unchecked(&gru_stats.id); \
36232 } while (0)
36233
36234 #ifdef CONFIG_SGI_GRU_DEBUG
36235 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36236 index c862cd4..0d176fe 100644
36237 --- a/drivers/misc/sgi-xp/xp.h
36238 +++ b/drivers/misc/sgi-xp/xp.h
36239 @@ -288,7 +288,7 @@ struct xpc_interface {
36240 xpc_notify_func, void *);
36241 void (*received) (short, int, void *);
36242 enum xp_retval (*partid_to_nasids) (short, void *);
36243 -};
36244 +} __no_const;
36245
36246 extern struct xpc_interface xpc_interface;
36247
36248 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36249 index b94d5f7..7f494c5 100644
36250 --- a/drivers/misc/sgi-xp/xpc.h
36251 +++ b/drivers/misc/sgi-xp/xpc.h
36252 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
36253 void (*received_payload) (struct xpc_channel *, void *);
36254 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36255 };
36256 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36257
36258 /* struct xpc_partition act_state values (for XPC HB) */
36259
36260 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36261 /* found in xpc_main.c */
36262 extern struct device *xpc_part;
36263 extern struct device *xpc_chan;
36264 -extern struct xpc_arch_operations xpc_arch_ops;
36265 +extern xpc_arch_operations_no_const xpc_arch_ops;
36266 extern int xpc_disengage_timelimit;
36267 extern int xpc_disengage_timedout;
36268 extern int xpc_activate_IRQ_rcvd;
36269 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36270 index d971817..33bdca5 100644
36271 --- a/drivers/misc/sgi-xp/xpc_main.c
36272 +++ b/drivers/misc/sgi-xp/xpc_main.c
36273 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36274 .notifier_call = xpc_system_die,
36275 };
36276
36277 -struct xpc_arch_operations xpc_arch_ops;
36278 +xpc_arch_operations_no_const xpc_arch_ops;
36279
36280 /*
36281 * Timer function to enforce the timelimit on the partition disengage.
36282 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36283
36284 if (((die_args->trapnr == X86_TRAP_MF) ||
36285 (die_args->trapnr == X86_TRAP_XF)) &&
36286 - !user_mode_vm(die_args->regs))
36287 + !user_mode(die_args->regs))
36288 xpc_die_deactivate();
36289
36290 break;
36291 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36292 index a0e1720..ee63d0b 100644
36293 --- a/drivers/mmc/core/mmc_ops.c
36294 +++ b/drivers/mmc/core/mmc_ops.c
36295 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36296 void *data_buf;
36297 int is_on_stack;
36298
36299 - is_on_stack = object_is_on_stack(buf);
36300 + is_on_stack = object_starts_on_stack(buf);
36301 if (is_on_stack) {
36302 /*
36303 * dma onto stack is unsafe/nonportable, but callers to this
36304 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36305 index 53b8fd9..615b462 100644
36306 --- a/drivers/mmc/host/dw_mmc.h
36307 +++ b/drivers/mmc/host/dw_mmc.h
36308 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36309 int (*parse_dt)(struct dw_mci *host);
36310 int (*setup_bus)(struct dw_mci *host,
36311 struct device_node *slot_np, u8 bus_width);
36312 -};
36313 +} __do_const;
36314 #endif /* _DW_MMC_H_ */
36315 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36316 index c9ec725..178e79a 100644
36317 --- a/drivers/mmc/host/sdhci-s3c.c
36318 +++ b/drivers/mmc/host/sdhci-s3c.c
36319 @@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36320 * we can use overriding functions instead of default.
36321 */
36322 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36323 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36324 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36325 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36326 + pax_open_kernel();
36327 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36328 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36329 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36330 + pax_close_kernel();
36331 }
36332
36333 /* It supports additional host capabilities if needed */
36334 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36335 index a4eb8b5..8c0628f 100644
36336 --- a/drivers/mtd/devices/doc2000.c
36337 +++ b/drivers/mtd/devices/doc2000.c
36338 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36339
36340 /* The ECC will not be calculated correctly if less than 512 is written */
36341 /* DBB-
36342 - if (len != 0x200 && eccbuf)
36343 + if (len != 0x200)
36344 printk(KERN_WARNING
36345 "ECC needs a full sector write (adr: %lx size %lx)\n",
36346 (long) to, (long) len);
36347 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36348 index e706a23..b3d262f 100644
36349 --- a/drivers/mtd/nand/denali.c
36350 +++ b/drivers/mtd/nand/denali.c
36351 @@ -26,6 +26,7 @@
36352 #include <linux/pci.h>
36353 #include <linux/mtd/mtd.h>
36354 #include <linux/module.h>
36355 +#include <linux/slab.h>
36356
36357 #include "denali.h"
36358
36359 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36360 index 51b9d6a..52af9a7 100644
36361 --- a/drivers/mtd/nftlmount.c
36362 +++ b/drivers/mtd/nftlmount.c
36363 @@ -24,6 +24,7 @@
36364 #include <asm/errno.h>
36365 #include <linux/delay.h>
36366 #include <linux/slab.h>
36367 +#include <linux/sched.h>
36368 #include <linux/mtd/mtd.h>
36369 #include <linux/mtd/nand.h>
36370 #include <linux/mtd/nftl.h>
36371 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36372 index 203ff9d..0968ca8 100644
36373 --- a/drivers/net/ethernet/8390/ax88796.c
36374 +++ b/drivers/net/ethernet/8390/ax88796.c
36375 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36376 if (ax->plat->reg_offsets)
36377 ei_local->reg_offset = ax->plat->reg_offsets;
36378 else {
36379 + resource_size_t _mem_size = mem_size;
36380 + do_div(_mem_size, 0x18);
36381 ei_local->reg_offset = ax->reg_offsets;
36382 for (ret = 0; ret < 0x18; ret++)
36383 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36384 + ax->reg_offsets[ret] = _mem_size * ret;
36385 }
36386
36387 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36388 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36389 index 9c5ea6c..eaad276 100644
36390 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36391 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36392 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36393 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36394 {
36395 /* RX_MODE controlling object */
36396 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36397 + bnx2x_init_rx_mode_obj(bp);
36398
36399 /* multicast configuration controlling object */
36400 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36401 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36402 index 614981c..11216c7 100644
36403 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36404 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36405 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36406 return rc;
36407 }
36408
36409 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36410 - struct bnx2x_rx_mode_obj *o)
36411 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36412 {
36413 if (CHIP_IS_E1x(bp)) {
36414 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36415 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36416 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36417 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36418 } else {
36419 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36420 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36421 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36422 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36423 }
36424 }
36425
36426 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36427 index acf2fe4..efb96df 100644
36428 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36429 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36430 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36431
36432 /********************* RX MODE ****************/
36433
36434 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36435 - struct bnx2x_rx_mode_obj *o);
36436 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36437
36438 /**
36439 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36440 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36441 index d9308c32..d87b824 100644
36442 --- a/drivers/net/ethernet/broadcom/tg3.h
36443 +++ b/drivers/net/ethernet/broadcom/tg3.h
36444 @@ -140,6 +140,7 @@
36445 #define CHIPREV_ID_5750_A0 0x4000
36446 #define CHIPREV_ID_5750_A1 0x4001
36447 #define CHIPREV_ID_5750_A3 0x4003
36448 +#define CHIPREV_ID_5750_C1 0x4201
36449 #define CHIPREV_ID_5750_C2 0x4202
36450 #define CHIPREV_ID_5752_A0_HW 0x5000
36451 #define CHIPREV_ID_5752_A0 0x6000
36452 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36453 index 8cffcdf..aadf043 100644
36454 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36455 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36456 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36457 */
36458 struct l2t_skb_cb {
36459 arp_failure_handler_func arp_failure_handler;
36460 -};
36461 +} __no_const;
36462
36463 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36464
36465 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36466 index f879e92..726f20f 100644
36467 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36468 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36469 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36470 for (i=0; i<ETH_ALEN; i++) {
36471 tmp.addr[i] = dev->dev_addr[i];
36472 }
36473 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36474 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36475 break;
36476
36477 case DE4X5_SET_HWADDR: /* Set the hardware address */
36478 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36479 spin_lock_irqsave(&lp->lock, flags);
36480 memcpy(&statbuf, &lp->pktStats, ioc->len);
36481 spin_unlock_irqrestore(&lp->lock, flags);
36482 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36483 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36484 return -EFAULT;
36485 break;
36486 }
36487 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36488 index d1b6cc5..cde0d97 100644
36489 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36490 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36491 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36492
36493 if (wrapped)
36494 newacc += 65536;
36495 - ACCESS_ONCE(*acc) = newacc;
36496 + ACCESS_ONCE_RW(*acc) = newacc;
36497 }
36498
36499 void be_parse_stats(struct be_adapter *adapter)
36500 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36501 index 74d749e..eefb1bd 100644
36502 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36503 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36504 @@ -31,6 +31,8 @@
36505 #include <linux/netdevice.h>
36506 #include <linux/phy.h>
36507 #include <linux/platform_device.h>
36508 +#include <linux/interrupt.h>
36509 +#include <linux/irqreturn.h>
36510 #include <net/ip.h>
36511
36512 #include "ftgmac100.h"
36513 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36514 index b901a01..1ff32ee 100644
36515 --- a/drivers/net/ethernet/faraday/ftmac100.c
36516 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36517 @@ -31,6 +31,8 @@
36518 #include <linux/module.h>
36519 #include <linux/netdevice.h>
36520 #include <linux/platform_device.h>
36521 +#include <linux/interrupt.h>
36522 +#include <linux/irqreturn.h>
36523
36524 #include "ftmac100.h"
36525
36526 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36527 index d929131..aed108f 100644
36528 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36529 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36530 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36531 /* store the new cycle speed */
36532 adapter->cycle_speed = cycle_speed;
36533
36534 - ACCESS_ONCE(adapter->base_incval) = incval;
36535 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36536 smp_mb();
36537
36538 /* grab the ptp lock */
36539 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36540 index c2e420a..26a75e0 100644
36541 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36542 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36543 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36544 struct __vxge_hw_fifo *fifo;
36545 struct vxge_hw_fifo_config *config;
36546 u32 txdl_size, txdl_per_memblock;
36547 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36548 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36549 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36550 + };
36551 +
36552 struct __vxge_hw_virtualpath *vpath;
36553
36554 if ((vp == NULL) || (attr == NULL)) {
36555 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36556 goto exit;
36557 }
36558
36559 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36560 -
36561 fifo->mempool =
36562 __vxge_hw_mempool_create(vpath->hldev,
36563 fifo->config->memblock_size,
36564 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36565 index 6afe74e..2e2950f 100644
36566 --- a/drivers/net/ethernet/realtek/r8169.c
36567 +++ b/drivers/net/ethernet/realtek/r8169.c
36568 @@ -747,22 +747,22 @@ struct rtl8169_private {
36569 struct mdio_ops {
36570 void (*write)(struct rtl8169_private *, int, int);
36571 int (*read)(struct rtl8169_private *, int);
36572 - } mdio_ops;
36573 + } __no_const mdio_ops;
36574
36575 struct pll_power_ops {
36576 void (*down)(struct rtl8169_private *);
36577 void (*up)(struct rtl8169_private *);
36578 - } pll_power_ops;
36579 + } __no_const pll_power_ops;
36580
36581 struct jumbo_ops {
36582 void (*enable)(struct rtl8169_private *);
36583 void (*disable)(struct rtl8169_private *);
36584 - } jumbo_ops;
36585 + } __no_const jumbo_ops;
36586
36587 struct csi_ops {
36588 void (*write)(struct rtl8169_private *, int, int);
36589 u32 (*read)(struct rtl8169_private *, int);
36590 - } csi_ops;
36591 + } __no_const csi_ops;
36592
36593 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36594 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36595 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36596 index 0767043f..08c2553 100644
36597 --- a/drivers/net/ethernet/sfc/ptp.c
36598 +++ b/drivers/net/ethernet/sfc/ptp.c
36599 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36600 (u32)((u64)ptp->start.dma_addr >> 32));
36601
36602 /* Clear flag that signals MC ready */
36603 - ACCESS_ONCE(*start) = 0;
36604 + ACCESS_ONCE_RW(*start) = 0;
36605 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36606 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36607
36608 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36609 index 0c74a70..3bc6f68 100644
36610 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36611 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36612 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36613
36614 writel(value, ioaddr + MMC_CNTRL);
36615
36616 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36617 - MMC_CNTRL, value);
36618 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36619 +// MMC_CNTRL, value);
36620 }
36621
36622 /* To mask all all interrupts.*/
36623 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36624 index 5fd6f46..ee1f265 100644
36625 --- a/drivers/net/hyperv/hyperv_net.h
36626 +++ b/drivers/net/hyperv/hyperv_net.h
36627 @@ -101,7 +101,7 @@ struct rndis_device {
36628
36629 enum rndis_device_state state;
36630 bool link_state;
36631 - atomic_t new_req_id;
36632 + atomic_unchecked_t new_req_id;
36633
36634 spinlock_t request_lock;
36635 struct list_head req_list;
36636 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36637 index 928148c..d83298e 100644
36638 --- a/drivers/net/hyperv/rndis_filter.c
36639 +++ b/drivers/net/hyperv/rndis_filter.c
36640 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36641 * template
36642 */
36643 set = &rndis_msg->msg.set_req;
36644 - set->req_id = atomic_inc_return(&dev->new_req_id);
36645 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36646
36647 /* Add to the request list */
36648 spin_lock_irqsave(&dev->request_lock, flags);
36649 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36650
36651 /* Setup the rndis set */
36652 halt = &request->request_msg.msg.halt_req;
36653 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36654 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36655
36656 /* Ignore return since this msg is optional. */
36657 rndis_filter_send_request(dev, request);
36658 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36659 index 7d39add..037e1da 100644
36660 --- a/drivers/net/ieee802154/fakehard.c
36661 +++ b/drivers/net/ieee802154/fakehard.c
36662 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36663 phy->transmit_power = 0xbf;
36664
36665 dev->netdev_ops = &fake_ops;
36666 - dev->ml_priv = &fake_mlme;
36667 + dev->ml_priv = (void *)&fake_mlme;
36668
36669 priv = netdev_priv(dev);
36670 priv->phy = phy;
36671 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36672 index 0f0f9ce..0ca5819 100644
36673 --- a/drivers/net/macvtap.c
36674 +++ b/drivers/net/macvtap.c
36675 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36676 return NOTIFY_DONE;
36677 }
36678
36679 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36680 +static struct notifier_block macvtap_notifier_block = {
36681 .notifier_call = macvtap_device_event,
36682 };
36683
36684 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36685 index daec9b0..6428fcb 100644
36686 --- a/drivers/net/phy/mdio-bitbang.c
36687 +++ b/drivers/net/phy/mdio-bitbang.c
36688 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36689 struct mdiobb_ctrl *ctrl = bus->priv;
36690
36691 module_put(ctrl->ops->owner);
36692 + mdiobus_unregister(bus);
36693 mdiobus_free(bus);
36694 }
36695 EXPORT_SYMBOL(free_mdio_bitbang);
36696 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36697 index eb3f5ce..d773730 100644
36698 --- a/drivers/net/ppp/ppp_generic.c
36699 +++ b/drivers/net/ppp/ppp_generic.c
36700 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36701 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36702 struct ppp_stats stats;
36703 struct ppp_comp_stats cstats;
36704 - char *vers;
36705
36706 switch (cmd) {
36707 case SIOCGPPPSTATS:
36708 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36709 break;
36710
36711 case SIOCGPPPVER:
36712 - vers = PPP_VERSION;
36713 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36714 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36715 break;
36716 err = 0;
36717 break;
36718 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36719 index ad86660..9fd0884 100644
36720 --- a/drivers/net/team/team.c
36721 +++ b/drivers/net/team/team.c
36722 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36723 return NOTIFY_DONE;
36724 }
36725
36726 -static struct notifier_block team_notifier_block __read_mostly = {
36727 +static struct notifier_block team_notifier_block = {
36728 .notifier_call = team_device_event,
36729 };
36730
36731 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36732 index 0873cdc..ddb178e 100644
36733 --- a/drivers/net/tun.c
36734 +++ b/drivers/net/tun.c
36735 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36736 }
36737
36738 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36739 - unsigned long arg, int ifreq_len)
36740 + unsigned long arg, size_t ifreq_len)
36741 {
36742 struct tun_file *tfile = file->private_data;
36743 struct tun_struct *tun;
36744 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36745 int vnet_hdr_sz;
36746 int ret;
36747
36748 + if (ifreq_len > sizeof ifr)
36749 + return -EFAULT;
36750 +
36751 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36752 if (copy_from_user(&ifr, argp, ifreq_len))
36753 return -EFAULT;
36754 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36755 index 605a4ba..a883dd1 100644
36756 --- a/drivers/net/usb/hso.c
36757 +++ b/drivers/net/usb/hso.c
36758 @@ -71,7 +71,7 @@
36759 #include <asm/byteorder.h>
36760 #include <linux/serial_core.h>
36761 #include <linux/serial.h>
36762 -
36763 +#include <asm/local.h>
36764
36765 #define MOD_AUTHOR "Option Wireless"
36766 #define MOD_DESCRIPTION "USB High Speed Option driver"
36767 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36768 struct urb *urb;
36769
36770 urb = serial->rx_urb[0];
36771 - if (serial->port.count > 0) {
36772 + if (atomic_read(&serial->port.count) > 0) {
36773 count = put_rxbuf_data(urb, serial);
36774 if (count == -1)
36775 return;
36776 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36777 DUMP1(urb->transfer_buffer, urb->actual_length);
36778
36779 /* Anyone listening? */
36780 - if (serial->port.count == 0)
36781 + if (atomic_read(&serial->port.count) == 0)
36782 return;
36783
36784 if (status == 0) {
36785 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36786 tty_port_tty_set(&serial->port, tty);
36787
36788 /* check for port already opened, if not set the termios */
36789 - serial->port.count++;
36790 - if (serial->port.count == 1) {
36791 + if (atomic_inc_return(&serial->port.count) == 1) {
36792 serial->rx_state = RX_IDLE;
36793 /* Force default termio settings */
36794 _hso_serial_set_termios(tty, NULL);
36795 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36796 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36797 if (result) {
36798 hso_stop_serial_device(serial->parent);
36799 - serial->port.count--;
36800 + atomic_dec(&serial->port.count);
36801 kref_put(&serial->parent->ref, hso_serial_ref_free);
36802 }
36803 } else {
36804 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36805
36806 /* reset the rts and dtr */
36807 /* do the actual close */
36808 - serial->port.count--;
36809 + atomic_dec(&serial->port.count);
36810
36811 - if (serial->port.count <= 0) {
36812 - serial->port.count = 0;
36813 + if (atomic_read(&serial->port.count) <= 0) {
36814 + atomic_set(&serial->port.count, 0);
36815 tty_port_tty_set(&serial->port, NULL);
36816 if (!usb_gone)
36817 hso_stop_serial_device(serial->parent);
36818 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36819
36820 /* the actual setup */
36821 spin_lock_irqsave(&serial->serial_lock, flags);
36822 - if (serial->port.count)
36823 + if (atomic_read(&serial->port.count))
36824 _hso_serial_set_termios(tty, old);
36825 else
36826 tty->termios = *old;
36827 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
36828 D1("Pending read interrupt on port %d\n", i);
36829 spin_lock(&serial->serial_lock);
36830 if (serial->rx_state == RX_IDLE &&
36831 - serial->port.count > 0) {
36832 + atomic_read(&serial->port.count) > 0) {
36833 /* Setup and send a ctrl req read on
36834 * port i */
36835 if (!serial->rx_urb_filled[0]) {
36836 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
36837 /* Start all serial ports */
36838 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36839 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36840 - if (dev2ser(serial_table[i])->port.count) {
36841 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
36842 result =
36843 hso_start_serial_device(serial_table[i], GFP_NOIO);
36844 hso_kick_transmit(dev2ser(serial_table[i]));
36845 diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
36846 index edb81ed..ab8931c 100644
36847 --- a/drivers/net/usb/usbnet.c
36848 +++ b/drivers/net/usb/usbnet.c
36849 @@ -380,6 +380,12 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
36850 unsigned long lockflags;
36851 size_t size = dev->rx_urb_size;
36852
36853 + /* prevent rx skb allocation when error ratio is high */
36854 + if (test_bit(EVENT_RX_KILL, &dev->flags)) {
36855 + usb_free_urb(urb);
36856 + return -ENOLINK;
36857 + }
36858 +
36859 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags);
36860 if (!skb) {
36861 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
36862 @@ -539,6 +545,17 @@ block:
36863 break;
36864 }
36865
36866 + /* stop rx if packet error rate is high */
36867 + if (++dev->pkt_cnt > 30) {
36868 + dev->pkt_cnt = 0;
36869 + dev->pkt_err = 0;
36870 + } else {
36871 + if (state == rx_cleanup)
36872 + dev->pkt_err++;
36873 + if (dev->pkt_err > 20)
36874 + set_bit(EVENT_RX_KILL, &dev->flags);
36875 + }
36876 +
36877 state = defer_bh(dev, skb, &dev->rxq, state);
36878
36879 if (urb) {
36880 @@ -790,6 +807,11 @@ int usbnet_open (struct net_device *net)
36881 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" :
36882 "simple");
36883
36884 + /* reset rx error state */
36885 + dev->pkt_cnt = 0;
36886 + dev->pkt_err = 0;
36887 + clear_bit(EVENT_RX_KILL, &dev->flags);
36888 +
36889 // delay posting reads until we're fully open
36890 tasklet_schedule (&dev->bh);
36891 if (info->manage_power) {
36892 @@ -1253,6 +1275,9 @@ static void usbnet_bh (unsigned long param)
36893 }
36894 }
36895
36896 + /* restart RX again after disabling due to high error rate */
36897 + clear_bit(EVENT_RX_KILL, &dev->flags);
36898 +
36899 // waiting for all pending urbs to complete?
36900 if (dev->wait) {
36901 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
36902 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36903 index 8d78253..bebbb68 100644
36904 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36905 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36906 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36907 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36908 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36909
36910 - ACCESS_ONCE(ads->ds_link) = i->link;
36911 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36912 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
36913 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36914
36915 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36916 ctl6 = SM(i->keytype, AR_EncrType);
36917 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36918
36919 if ((i->is_first || i->is_last) &&
36920 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36921 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36922 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36923 | set11nTries(i->rates, 1)
36924 | set11nTries(i->rates, 2)
36925 | set11nTries(i->rates, 3)
36926 | (i->dur_update ? AR_DurUpdateEna : 0)
36927 | SM(0, AR_BurstDur);
36928
36929 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36930 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36931 | set11nRate(i->rates, 1)
36932 | set11nRate(i->rates, 2)
36933 | set11nRate(i->rates, 3);
36934 } else {
36935 - ACCESS_ONCE(ads->ds_ctl2) = 0;
36936 - ACCESS_ONCE(ads->ds_ctl3) = 0;
36937 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36938 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36939 }
36940
36941 if (!i->is_first) {
36942 - ACCESS_ONCE(ads->ds_ctl0) = 0;
36943 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36944 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36945 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36946 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36947 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36948 return;
36949 }
36950
36951 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36952 break;
36953 }
36954
36955 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36956 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36957 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36958 | SM(i->txpower, AR_XmitPower)
36959 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36960 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36961 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36962 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36963
36964 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36965 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36966 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36967 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36968
36969 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36970 return;
36971
36972 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36973 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36974 | set11nPktDurRTSCTS(i->rates, 1);
36975
36976 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36977 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36978 | set11nPktDurRTSCTS(i->rates, 3);
36979
36980 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36981 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36982 | set11nRateFlags(i->rates, 1)
36983 | set11nRateFlags(i->rates, 2)
36984 | set11nRateFlags(i->rates, 3)
36985 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36986 index 301bf72..3f5654f 100644
36987 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36988 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36989 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36990 (i->qcu << AR_TxQcuNum_S) | desc_len;
36991
36992 checksum += val;
36993 - ACCESS_ONCE(ads->info) = val;
36994 + ACCESS_ONCE_RW(ads->info) = val;
36995
36996 checksum += i->link;
36997 - ACCESS_ONCE(ads->link) = i->link;
36998 + ACCESS_ONCE_RW(ads->link) = i->link;
36999
37000 checksum += i->buf_addr[0];
37001 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37002 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37003 checksum += i->buf_addr[1];
37004 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37005 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37006 checksum += i->buf_addr[2];
37007 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37008 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37009 checksum += i->buf_addr[3];
37010 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37011 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37012
37013 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37014 - ACCESS_ONCE(ads->ctl3) = val;
37015 + ACCESS_ONCE_RW(ads->ctl3) = val;
37016 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37017 - ACCESS_ONCE(ads->ctl5) = val;
37018 + ACCESS_ONCE_RW(ads->ctl5) = val;
37019 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37020 - ACCESS_ONCE(ads->ctl7) = val;
37021 + ACCESS_ONCE_RW(ads->ctl7) = val;
37022 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37023 - ACCESS_ONCE(ads->ctl9) = val;
37024 + ACCESS_ONCE_RW(ads->ctl9) = val;
37025
37026 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37027 - ACCESS_ONCE(ads->ctl10) = checksum;
37028 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37029
37030 if (i->is_first || i->is_last) {
37031 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37032 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37033 | set11nTries(i->rates, 1)
37034 | set11nTries(i->rates, 2)
37035 | set11nTries(i->rates, 3)
37036 | (i->dur_update ? AR_DurUpdateEna : 0)
37037 | SM(0, AR_BurstDur);
37038
37039 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37040 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37041 | set11nRate(i->rates, 1)
37042 | set11nRate(i->rates, 2)
37043 | set11nRate(i->rates, 3);
37044 } else {
37045 - ACCESS_ONCE(ads->ctl13) = 0;
37046 - ACCESS_ONCE(ads->ctl14) = 0;
37047 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37048 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37049 }
37050
37051 ads->ctl20 = 0;
37052 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37053
37054 ctl17 = SM(i->keytype, AR_EncrType);
37055 if (!i->is_first) {
37056 - ACCESS_ONCE(ads->ctl11) = 0;
37057 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37058 - ACCESS_ONCE(ads->ctl15) = 0;
37059 - ACCESS_ONCE(ads->ctl16) = 0;
37060 - ACCESS_ONCE(ads->ctl17) = ctl17;
37061 - ACCESS_ONCE(ads->ctl18) = 0;
37062 - ACCESS_ONCE(ads->ctl19) = 0;
37063 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37064 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37065 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37066 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37067 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37068 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37069 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37070 return;
37071 }
37072
37073 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37074 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37075 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37076 | SM(i->txpower, AR_XmitPower)
37077 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37078 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37079 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37080 ctl12 |= SM(val, AR_PAPRDChainMask);
37081
37082 - ACCESS_ONCE(ads->ctl12) = ctl12;
37083 - ACCESS_ONCE(ads->ctl17) = ctl17;
37084 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37085 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37086
37087 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37088 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37089 | set11nPktDurRTSCTS(i->rates, 1);
37090
37091 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37092 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37093 | set11nPktDurRTSCTS(i->rates, 3);
37094
37095 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37096 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37097 | set11nRateFlags(i->rates, 1)
37098 | set11nRateFlags(i->rates, 2)
37099 | set11nRateFlags(i->rates, 3)
37100 | SM(i->rtscts_rate, AR_RTSCTSRate);
37101
37102 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37103 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37104 }
37105
37106 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37107 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37108 index b68aaf5..fb20845 100644
37109 --- a/drivers/net/wireless/ath/ath9k/hw.h
37110 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37111 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37112
37113 /* ANI */
37114 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37115 -};
37116 +} __no_const;
37117
37118 /**
37119 * struct ath_hw_ops - callbacks used by hardware code and driver code
37120 @@ -687,7 +687,7 @@ struct ath_hw_ops {
37121 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37122 struct ath_hw_antcomb_conf *antconf);
37123 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37124 -};
37125 +} __no_const;
37126
37127 struct ath_nf_limits {
37128 s16 max;
37129 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37130 index 71ced17..cd82b12 100644
37131 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37132 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37133 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37134 struct net_device *ndev,
37135 const struct brcmf_event_msg *e,
37136 void *data);
37137 -};
37138 +} __no_const;
37139
37140 /* basic structure of scan request */
37141 struct brcmf_cfg80211_scan_req {
37142 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37143 struct brcmf_cfg80211_iscan_eloop {
37144 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37145 (struct brcmf_cfg80211_info *cfg);
37146 -};
37147 +} __no_const;
37148
37149 /* dongle iscan controller */
37150 struct brcmf_cfg80211_iscan_ctrl {
37151 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37152 index e252acb..6ad1e65 100644
37153 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37154 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37155 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37156 */
37157 if (il3945_mod_params.disable_hw_scan) {
37158 D_INFO("Disabling hw_scan\n");
37159 - il3945_mac_ops.hw_scan = NULL;
37160 + pax_open_kernel();
37161 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37162 + pax_close_kernel();
37163 }
37164
37165 D_INFO("*** LOAD DRIVER ***\n");
37166 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37167 index 1a98fa3..51e6661 100644
37168 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37169 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37170 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37171 {
37172 struct iwl_priv *priv = file->private_data;
37173 char buf[64];
37174 - int buf_size;
37175 + size_t buf_size;
37176 u32 offset, len;
37177
37178 memset(buf, 0, sizeof(buf));
37179 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37180 struct iwl_priv *priv = file->private_data;
37181
37182 char buf[8];
37183 - int buf_size;
37184 + size_t buf_size;
37185 u32 reset_flag;
37186
37187 memset(buf, 0, sizeof(buf));
37188 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37189 {
37190 struct iwl_priv *priv = file->private_data;
37191 char buf[8];
37192 - int buf_size;
37193 + size_t buf_size;
37194 int ht40;
37195
37196 memset(buf, 0, sizeof(buf));
37197 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37198 {
37199 struct iwl_priv *priv = file->private_data;
37200 char buf[8];
37201 - int buf_size;
37202 + size_t buf_size;
37203 int value;
37204
37205 memset(buf, 0, sizeof(buf));
37206 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37207 {
37208 struct iwl_priv *priv = file->private_data;
37209 char buf[8];
37210 - int buf_size;
37211 + size_t buf_size;
37212 int clear;
37213
37214 memset(buf, 0, sizeof(buf));
37215 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37216 {
37217 struct iwl_priv *priv = file->private_data;
37218 char buf[8];
37219 - int buf_size;
37220 + size_t buf_size;
37221 int trace;
37222
37223 memset(buf, 0, sizeof(buf));
37224 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37225 {
37226 struct iwl_priv *priv = file->private_data;
37227 char buf[8];
37228 - int buf_size;
37229 + size_t buf_size;
37230 int missed;
37231
37232 memset(buf, 0, sizeof(buf));
37233 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37234
37235 struct iwl_priv *priv = file->private_data;
37236 char buf[8];
37237 - int buf_size;
37238 + size_t buf_size;
37239 int plcp;
37240
37241 memset(buf, 0, sizeof(buf));
37242 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37243
37244 struct iwl_priv *priv = file->private_data;
37245 char buf[8];
37246 - int buf_size;
37247 + size_t buf_size;
37248 int flush;
37249
37250 memset(buf, 0, sizeof(buf));
37251 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37252
37253 struct iwl_priv *priv = file->private_data;
37254 char buf[8];
37255 - int buf_size;
37256 + size_t buf_size;
37257 int rts;
37258
37259 if (!priv->cfg->ht_params)
37260 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37261 {
37262 struct iwl_priv *priv = file->private_data;
37263 char buf[8];
37264 - int buf_size;
37265 + size_t buf_size;
37266
37267 memset(buf, 0, sizeof(buf));
37268 buf_size = min(count, sizeof(buf) - 1);
37269 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37270 struct iwl_priv *priv = file->private_data;
37271 u32 event_log_flag;
37272 char buf[8];
37273 - int buf_size;
37274 + size_t buf_size;
37275
37276 /* check that the interface is up */
37277 if (!iwl_is_ready(priv))
37278 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37279 struct iwl_priv *priv = file->private_data;
37280 char buf[8];
37281 u32 calib_disabled;
37282 - int buf_size;
37283 + size_t buf_size;
37284
37285 memset(buf, 0, sizeof(buf));
37286 buf_size = min(count, sizeof(buf) - 1);
37287 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37288 index fe0fffd..b4c5724 100644
37289 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37290 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37291 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37292 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37293
37294 char buf[8];
37295 - int buf_size;
37296 + size_t buf_size;
37297 u32 reset_flag;
37298
37299 memset(buf, 0, sizeof(buf));
37300 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37301 {
37302 struct iwl_trans *trans = file->private_data;
37303 char buf[8];
37304 - int buf_size;
37305 + size_t buf_size;
37306 int csr;
37307
37308 memset(buf, 0, sizeof(buf));
37309 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37310 index 429ca32..f86236b 100644
37311 --- a/drivers/net/wireless/mac80211_hwsim.c
37312 +++ b/drivers/net/wireless/mac80211_hwsim.c
37313 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37314 return -EINVAL;
37315
37316 if (fake_hw_scan) {
37317 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37318 - mac80211_hwsim_ops.sw_scan_start = NULL;
37319 - mac80211_hwsim_ops.sw_scan_complete = NULL;
37320 + pax_open_kernel();
37321 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37322 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37323 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37324 + pax_close_kernel();
37325 }
37326
37327 spin_lock_init(&hwsim_radio_lock);
37328 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37329 index bd1f0cb..db85ab0 100644
37330 --- a/drivers/net/wireless/rndis_wlan.c
37331 +++ b/drivers/net/wireless/rndis_wlan.c
37332 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37333
37334 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37335
37336 - if (rts_threshold < 0 || rts_threshold > 2347)
37337 + if (rts_threshold > 2347)
37338 rts_threshold = 2347;
37339
37340 tmp = cpu_to_le32(rts_threshold);
37341 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37342 index 0751b35..246ba3e 100644
37343 --- a/drivers/net/wireless/rt2x00/rt2x00.h
37344 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
37345 @@ -398,7 +398,7 @@ struct rt2x00_intf {
37346 * for hardware which doesn't support hardware
37347 * sequence counting.
37348 */
37349 - atomic_t seqno;
37350 + atomic_unchecked_t seqno;
37351 };
37352
37353 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37354 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37355 index e488b94..14b6a0c 100644
37356 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37357 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37358 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37359 * sequence counter given by mac80211.
37360 */
37361 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37362 - seqno = atomic_add_return(0x10, &intf->seqno);
37363 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37364 else
37365 - seqno = atomic_read(&intf->seqno);
37366 + seqno = atomic_read_unchecked(&intf->seqno);
37367
37368 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37369 hdr->seq_ctrl |= cpu_to_le16(seqno);
37370 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37371 index e2750a1..797e179 100644
37372 --- a/drivers/net/wireless/ti/wl1251/sdio.c
37373 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
37374 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37375
37376 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37377
37378 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37379 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37380 + pax_open_kernel();
37381 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37382 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37383 + pax_close_kernel();
37384
37385 wl1251_info("using dedicated interrupt line");
37386 } else {
37387 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37388 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37389 + pax_open_kernel();
37390 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37391 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37392 + pax_close_kernel();
37393
37394 wl1251_info("using SDIO interrupt");
37395 }
37396 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37397 index dadf1db..d9db7a7 100644
37398 --- a/drivers/net/wireless/ti/wl12xx/main.c
37399 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37400 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37401 sizeof(wl->conf.mem));
37402
37403 /* read data preparation is only needed by wl127x */
37404 - wl->ops->prepare_read = wl127x_prepare_read;
37405 + pax_open_kernel();
37406 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37407 + pax_close_kernel();
37408
37409 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37410 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37411 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37412 sizeof(wl->conf.mem));
37413
37414 /* read data preparation is only needed by wl127x */
37415 - wl->ops->prepare_read = wl127x_prepare_read;
37416 + pax_open_kernel();
37417 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37418 + pax_close_kernel();
37419
37420 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37421 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37422 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37423 index a39682a..1e8220c 100644
37424 --- a/drivers/net/wireless/ti/wl18xx/main.c
37425 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37426 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37427 }
37428
37429 if (!checksum_param) {
37430 - wl18xx_ops.set_rx_csum = NULL;
37431 - wl18xx_ops.init_vif = NULL;
37432 + pax_open_kernel();
37433 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37434 + *(void **)&wl18xx_ops.init_vif = NULL;
37435 + pax_close_kernel();
37436 }
37437
37438 /* Enable 11a Band only if we have 5G antennas */
37439 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37440 index d93b2b6..ae50401 100644
37441 --- a/drivers/oprofile/buffer_sync.c
37442 +++ b/drivers/oprofile/buffer_sync.c
37443 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37444 if (cookie == NO_COOKIE)
37445 offset = pc;
37446 if (cookie == INVALID_COOKIE) {
37447 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37448 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37449 offset = pc;
37450 }
37451 if (cookie != last_cookie) {
37452 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37453 /* add userspace sample */
37454
37455 if (!mm) {
37456 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37457 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37458 return 0;
37459 }
37460
37461 cookie = lookup_dcookie(mm, s->eip, &offset);
37462
37463 if (cookie == INVALID_COOKIE) {
37464 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37465 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37466 return 0;
37467 }
37468
37469 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37470 /* ignore backtraces if failed to add a sample */
37471 if (state == sb_bt_start) {
37472 state = sb_bt_ignore;
37473 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37474 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37475 }
37476 }
37477 release_mm(mm);
37478 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37479 index c0cc4e7..44d4e54 100644
37480 --- a/drivers/oprofile/event_buffer.c
37481 +++ b/drivers/oprofile/event_buffer.c
37482 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37483 }
37484
37485 if (buffer_pos == buffer_size) {
37486 - atomic_inc(&oprofile_stats.event_lost_overflow);
37487 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37488 return;
37489 }
37490
37491 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37492 index ed2c3ec..deda85a 100644
37493 --- a/drivers/oprofile/oprof.c
37494 +++ b/drivers/oprofile/oprof.c
37495 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37496 if (oprofile_ops.switch_events())
37497 return;
37498
37499 - atomic_inc(&oprofile_stats.multiplex_counter);
37500 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37501 start_switch_worker();
37502 }
37503
37504 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37505 index 917d28e..d62d981 100644
37506 --- a/drivers/oprofile/oprofile_stats.c
37507 +++ b/drivers/oprofile/oprofile_stats.c
37508 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37509 cpu_buf->sample_invalid_eip = 0;
37510 }
37511
37512 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37513 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37514 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37515 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37516 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37517 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37518 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37519 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37520 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37521 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37522 }
37523
37524
37525 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37526 index 38b6fc0..b5cbfce 100644
37527 --- a/drivers/oprofile/oprofile_stats.h
37528 +++ b/drivers/oprofile/oprofile_stats.h
37529 @@ -13,11 +13,11 @@
37530 #include <linux/atomic.h>
37531
37532 struct oprofile_stat_struct {
37533 - atomic_t sample_lost_no_mm;
37534 - atomic_t sample_lost_no_mapping;
37535 - atomic_t bt_lost_no_mapping;
37536 - atomic_t event_lost_overflow;
37537 - atomic_t multiplex_counter;
37538 + atomic_unchecked_t sample_lost_no_mm;
37539 + atomic_unchecked_t sample_lost_no_mapping;
37540 + atomic_unchecked_t bt_lost_no_mapping;
37541 + atomic_unchecked_t event_lost_overflow;
37542 + atomic_unchecked_t multiplex_counter;
37543 };
37544
37545 extern struct oprofile_stat_struct oprofile_stats;
37546 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37547 index 849357c..b83c1e0 100644
37548 --- a/drivers/oprofile/oprofilefs.c
37549 +++ b/drivers/oprofile/oprofilefs.c
37550 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37551
37552
37553 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37554 - char const *name, atomic_t *val)
37555 + char const *name, atomic_unchecked_t *val)
37556 {
37557 return __oprofilefs_create_file(sb, root, name,
37558 &atomic_ro_fops, 0444, val);
37559 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37560 index 3f56bc0..707d642 100644
37561 --- a/drivers/parport/procfs.c
37562 +++ b/drivers/parport/procfs.c
37563 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37564
37565 *ppos += len;
37566
37567 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37568 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37569 }
37570
37571 #ifdef CONFIG_PARPORT_1284
37572 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37573
37574 *ppos += len;
37575
37576 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37577 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37578 }
37579 #endif /* IEEE1284.3 support. */
37580
37581 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37582 index a6a71c4..c91097b 100644
37583 --- a/drivers/pci/hotplug/cpcihp_generic.c
37584 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37585 @@ -73,7 +73,6 @@ static u16 port;
37586 static unsigned int enum_bit;
37587 static u8 enum_mask;
37588
37589 -static struct cpci_hp_controller_ops generic_hpc_ops;
37590 static struct cpci_hp_controller generic_hpc;
37591
37592 static int __init validate_parameters(void)
37593 @@ -139,6 +138,10 @@ static int query_enum(void)
37594 return ((value & enum_mask) == enum_mask);
37595 }
37596
37597 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37598 + .query_enum = query_enum,
37599 +};
37600 +
37601 static int __init cpcihp_generic_init(void)
37602 {
37603 int status;
37604 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37605 pci_dev_put(dev);
37606
37607 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37608 - generic_hpc_ops.query_enum = query_enum;
37609 generic_hpc.ops = &generic_hpc_ops;
37610
37611 status = cpci_hp_register_controller(&generic_hpc);
37612 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37613 index 6bf8d2a..9711ce0 100644
37614 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37615 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37616 @@ -59,7 +59,6 @@
37617 /* local variables */
37618 static bool debug;
37619 static bool poll;
37620 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37621 static struct cpci_hp_controller zt5550_hpc;
37622
37623 /* Primary cPCI bus bridge device */
37624 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37625 return 0;
37626 }
37627
37628 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37629 + .query_enum = zt5550_hc_query_enum,
37630 +};
37631 +
37632 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37633 {
37634 int status;
37635 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37636 dbg("returned from zt5550_hc_config");
37637
37638 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37639 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37640 zt5550_hpc.ops = &zt5550_hpc_ops;
37641 if(!poll) {
37642 zt5550_hpc.irq = hc_dev->irq;
37643 zt5550_hpc.irq_flags = IRQF_SHARED;
37644 zt5550_hpc.dev_id = hc_dev;
37645
37646 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37647 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37648 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37649 + pax_open_kernel();
37650 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37651 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37652 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37653 + pax_open_kernel();
37654 } else {
37655 info("using ENUM# polling mode");
37656 }
37657 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37658 index 76ba8a1..20ca857 100644
37659 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37660 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37661 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37662
37663 void compaq_nvram_init (void __iomem *rom_start)
37664 {
37665 +
37666 +#ifndef CONFIG_PAX_KERNEXEC
37667 if (rom_start) {
37668 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37669 }
37670 +#endif
37671 +
37672 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37673
37674 /* initialize our int15 lock */
37675 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37676 index 449f257..0731e96 100644
37677 --- a/drivers/pci/pcie/aspm.c
37678 +++ b/drivers/pci/pcie/aspm.c
37679 @@ -27,9 +27,9 @@
37680 #define MODULE_PARAM_PREFIX "pcie_aspm."
37681
37682 /* Note: those are not register definitions */
37683 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37684 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37685 -#define ASPM_STATE_L1 (4) /* L1 state */
37686 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37687 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37688 +#define ASPM_STATE_L1 (4U) /* L1 state */
37689 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37690 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37691
37692 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37693 index ec909af..e7517f3 100644
37694 --- a/drivers/pci/probe.c
37695 +++ b/drivers/pci/probe.c
37696 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37697 struct pci_bus_region region;
37698 bool bar_too_big = false, bar_disabled = false;
37699
37700 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37701 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37702
37703 /* No printks while decoding is disabled! */
37704 if (!dev->mmio_always_on) {
37705 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37706 index 9b8505c..f00870a 100644
37707 --- a/drivers/pci/proc.c
37708 +++ b/drivers/pci/proc.c
37709 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37710 static int __init pci_proc_init(void)
37711 {
37712 struct pci_dev *dev = NULL;
37713 +
37714 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37715 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37716 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37717 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37718 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37719 +#endif
37720 +#else
37721 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37722 +#endif
37723 proc_create("devices", 0, proc_bus_pci_dir,
37724 &proc_bus_pci_dev_operations);
37725 proc_initialized = 1;
37726 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37727 index 75dd651..2af4c9a 100644
37728 --- a/drivers/platform/x86/thinkpad_acpi.c
37729 +++ b/drivers/platform/x86/thinkpad_acpi.c
37730 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37731 return 0;
37732 }
37733
37734 -void static hotkey_mask_warn_incomplete_mask(void)
37735 +static void hotkey_mask_warn_incomplete_mask(void)
37736 {
37737 /* log only what the user can fix... */
37738 const u32 wantedmask = hotkey_driver_mask &
37739 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37740 }
37741 }
37742
37743 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37744 - struct tp_nvram_state *newn,
37745 - const u32 event_mask)
37746 -{
37747 -
37748 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37749 do { \
37750 if ((event_mask & (1 << __scancode)) && \
37751 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37752 tpacpi_hotkey_send_key(__scancode); \
37753 } while (0)
37754
37755 - void issue_volchange(const unsigned int oldvol,
37756 - const unsigned int newvol)
37757 - {
37758 - unsigned int i = oldvol;
37759 +static void issue_volchange(const unsigned int oldvol,
37760 + const unsigned int newvol,
37761 + const u32 event_mask)
37762 +{
37763 + unsigned int i = oldvol;
37764
37765 - while (i > newvol) {
37766 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37767 - i--;
37768 - }
37769 - while (i < newvol) {
37770 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37771 - i++;
37772 - }
37773 + while (i > newvol) {
37774 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37775 + i--;
37776 }
37777 + while (i < newvol) {
37778 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37779 + i++;
37780 + }
37781 +}
37782
37783 - void issue_brightnesschange(const unsigned int oldbrt,
37784 - const unsigned int newbrt)
37785 - {
37786 - unsigned int i = oldbrt;
37787 +static void issue_brightnesschange(const unsigned int oldbrt,
37788 + const unsigned int newbrt,
37789 + const u32 event_mask)
37790 +{
37791 + unsigned int i = oldbrt;
37792
37793 - while (i > newbrt) {
37794 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37795 - i--;
37796 - }
37797 - while (i < newbrt) {
37798 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37799 - i++;
37800 - }
37801 + while (i > newbrt) {
37802 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37803 + i--;
37804 + }
37805 + while (i < newbrt) {
37806 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37807 + i++;
37808 }
37809 +}
37810
37811 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37812 + struct tp_nvram_state *newn,
37813 + const u32 event_mask)
37814 +{
37815 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37816 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37817 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37818 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37819 oldn->volume_level != newn->volume_level) {
37820 /* recently muted, or repeated mute keypress, or
37821 * multiple presses ending in mute */
37822 - issue_volchange(oldn->volume_level, newn->volume_level);
37823 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37824 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37825 }
37826 } else {
37827 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37828 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37829 }
37830 if (oldn->volume_level != newn->volume_level) {
37831 - issue_volchange(oldn->volume_level, newn->volume_level);
37832 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37833 } else if (oldn->volume_toggle != newn->volume_toggle) {
37834 /* repeated vol up/down keypress at end of scale ? */
37835 if (newn->volume_level == 0)
37836 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37837 /* handle brightness */
37838 if (oldn->brightness_level != newn->brightness_level) {
37839 issue_brightnesschange(oldn->brightness_level,
37840 - newn->brightness_level);
37841 + newn->brightness_level,
37842 + event_mask);
37843 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37844 /* repeated key presses that didn't change state */
37845 if (newn->brightness_level == 0)
37846 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37847 && !tp_features.bright_unkfw)
37848 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37849 }
37850 +}
37851
37852 #undef TPACPI_COMPARE_KEY
37853 #undef TPACPI_MAY_SEND_KEY
37854 -}
37855
37856 /*
37857 * Polling driver
37858 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37859 index 769d265..a3a05ca 100644
37860 --- a/drivers/pnp/pnpbios/bioscalls.c
37861 +++ b/drivers/pnp/pnpbios/bioscalls.c
37862 @@ -58,7 +58,7 @@ do { \
37863 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37864 } while(0)
37865
37866 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37867 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37868 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37869
37870 /*
37871 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37872
37873 cpu = get_cpu();
37874 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37875 +
37876 + pax_open_kernel();
37877 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37878 + pax_close_kernel();
37879
37880 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37881 spin_lock_irqsave(&pnp_bios_lock, flags);
37882 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37883 :"memory");
37884 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37885
37886 + pax_open_kernel();
37887 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37888 + pax_close_kernel();
37889 +
37890 put_cpu();
37891
37892 /* If we get here and this is set then the PnP BIOS faulted on us. */
37893 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37894 return status;
37895 }
37896
37897 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37898 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37899 {
37900 int i;
37901
37902 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37903 pnp_bios_callpoint.offset = header->fields.pm16offset;
37904 pnp_bios_callpoint.segment = PNP_CS16;
37905
37906 + pax_open_kernel();
37907 +
37908 for_each_possible_cpu(i) {
37909 struct desc_struct *gdt = get_cpu_gdt_table(i);
37910 if (!gdt)
37911 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37912 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37913 (unsigned long)__va(header->fields.pm16dseg));
37914 }
37915 +
37916 + pax_close_kernel();
37917 }
37918 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37919 index b0ecacb..7c9da2e 100644
37920 --- a/drivers/pnp/resource.c
37921 +++ b/drivers/pnp/resource.c
37922 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37923 return 1;
37924
37925 /* check if the resource is valid */
37926 - if (*irq < 0 || *irq > 15)
37927 + if (*irq > 15)
37928 return 0;
37929
37930 /* check if the resource is reserved */
37931 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37932 return 1;
37933
37934 /* check if the resource is valid */
37935 - if (*dma < 0 || *dma == 4 || *dma > 7)
37936 + if (*dma == 4 || *dma > 7)
37937 return 0;
37938
37939 /* check if the resource is reserved */
37940 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
37941 index 7df7c5f..bd48c47 100644
37942 --- a/drivers/power/pda_power.c
37943 +++ b/drivers/power/pda_power.c
37944 @@ -37,7 +37,11 @@ static int polling;
37945
37946 #ifdef CONFIG_USB_OTG_UTILS
37947 static struct usb_phy *transceiver;
37948 -static struct notifier_block otg_nb;
37949 +static int otg_handle_notification(struct notifier_block *nb,
37950 + unsigned long event, void *unused);
37951 +static struct notifier_block otg_nb = {
37952 + .notifier_call = otg_handle_notification
37953 +};
37954 #endif
37955
37956 static struct regulator *ac_draw;
37957 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
37958
37959 #ifdef CONFIG_USB_OTG_UTILS
37960 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
37961 - otg_nb.notifier_call = otg_handle_notification;
37962 ret = usb_register_notifier(transceiver, &otg_nb);
37963 if (ret) {
37964 dev_err(dev, "failure to register otg notifier\n");
37965 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37966 index 8d53174..04c65de 100644
37967 --- a/drivers/regulator/max8660.c
37968 +++ b/drivers/regulator/max8660.c
37969 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37970 max8660->shadow_regs[MAX8660_OVER1] = 5;
37971 } else {
37972 /* Otherwise devices can be toggled via software */
37973 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
37974 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
37975 + pax_open_kernel();
37976 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37977 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37978 + pax_close_kernel();
37979 }
37980
37981 /*
37982 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37983 index 1fa6381..f58834e 100644
37984 --- a/drivers/regulator/mc13892-regulator.c
37985 +++ b/drivers/regulator/mc13892-regulator.c
37986 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37987 }
37988 mc13xxx_unlock(mc13892);
37989
37990 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37991 + pax_open_kernel();
37992 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37993 = mc13892_vcam_set_mode;
37994 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37995 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37996 = mc13892_vcam_get_mode;
37997 + pax_close_kernel();
37998
37999 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38000 ARRAY_SIZE(mc13892_regulators));
38001 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38002 index cace6d3..f623fda 100644
38003 --- a/drivers/rtc/rtc-dev.c
38004 +++ b/drivers/rtc/rtc-dev.c
38005 @@ -14,6 +14,7 @@
38006 #include <linux/module.h>
38007 #include <linux/rtc.h>
38008 #include <linux/sched.h>
38009 +#include <linux/grsecurity.h>
38010 #include "rtc-core.h"
38011
38012 static dev_t rtc_devt;
38013 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38014 if (copy_from_user(&tm, uarg, sizeof(tm)))
38015 return -EFAULT;
38016
38017 + gr_log_timechange();
38018 +
38019 return rtc_set_time(rtc, &tm);
38020
38021 case RTC_PIE_ON:
38022 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38023 index 4ad7e36..d004679 100644
38024 --- a/drivers/scsi/bfa/bfa.h
38025 +++ b/drivers/scsi/bfa/bfa.h
38026 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38027 u32 *end);
38028 int cpe_vec_q0;
38029 int rme_vec_q0;
38030 -};
38031 +} __no_const;
38032 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38033
38034 struct bfa_faa_cbfn_s {
38035 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38036 index e693af6..2e525b6 100644
38037 --- a/drivers/scsi/bfa/bfa_fcpim.h
38038 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38039 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38040
38041 struct bfa_itn_s {
38042 bfa_isr_func_t isr;
38043 -};
38044 +} __no_const;
38045
38046 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38047 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38048 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38049 index 23a90e7..9cf04ee 100644
38050 --- a/drivers/scsi/bfa/bfa_ioc.h
38051 +++ b/drivers/scsi/bfa/bfa_ioc.h
38052 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38053 bfa_ioc_disable_cbfn_t disable_cbfn;
38054 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38055 bfa_ioc_reset_cbfn_t reset_cbfn;
38056 -};
38057 +} __no_const;
38058
38059 /*
38060 * IOC event notification mechanism.
38061 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38062 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38063 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38064 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38065 -};
38066 +} __no_const;
38067
38068 /*
38069 * Queue element to wait for room in request queue. FIFO order is
38070 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38071 index 593085a..47aa999 100644
38072 --- a/drivers/scsi/hosts.c
38073 +++ b/drivers/scsi/hosts.c
38074 @@ -42,7 +42,7 @@
38075 #include "scsi_logging.h"
38076
38077
38078 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38079 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38080
38081
38082 static void scsi_host_cls_release(struct device *dev)
38083 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38084 * subtract one because we increment first then return, but we need to
38085 * know what the next host number was before increment
38086 */
38087 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38088 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38089 shost->dma_channel = 0xff;
38090
38091 /* These three are default values which can be overridden */
38092 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38093 index 4217e49..9c77e3e 100644
38094 --- a/drivers/scsi/hpsa.c
38095 +++ b/drivers/scsi/hpsa.c
38096 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38097 unsigned long flags;
38098
38099 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38100 - return h->access.command_completed(h, q);
38101 + return h->access->command_completed(h, q);
38102
38103 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38104 a = rq->head[rq->current_entry];
38105 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38106 while (!list_empty(&h->reqQ)) {
38107 c = list_entry(h->reqQ.next, struct CommandList, list);
38108 /* can't do anything if fifo is full */
38109 - if ((h->access.fifo_full(h))) {
38110 + if ((h->access->fifo_full(h))) {
38111 dev_warn(&h->pdev->dev, "fifo full\n");
38112 break;
38113 }
38114 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38115
38116 /* Tell the controller execute command */
38117 spin_unlock_irqrestore(&h->lock, flags);
38118 - h->access.submit_command(h, c);
38119 + h->access->submit_command(h, c);
38120 spin_lock_irqsave(&h->lock, flags);
38121 }
38122 spin_unlock_irqrestore(&h->lock, flags);
38123 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38124
38125 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38126 {
38127 - return h->access.command_completed(h, q);
38128 + return h->access->command_completed(h, q);
38129 }
38130
38131 static inline bool interrupt_pending(struct ctlr_info *h)
38132 {
38133 - return h->access.intr_pending(h);
38134 + return h->access->intr_pending(h);
38135 }
38136
38137 static inline long interrupt_not_for_us(struct ctlr_info *h)
38138 {
38139 - return (h->access.intr_pending(h) == 0) ||
38140 + return (h->access->intr_pending(h) == 0) ||
38141 (h->interrupts_enabled == 0);
38142 }
38143
38144 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38145 if (prod_index < 0)
38146 return -ENODEV;
38147 h->product_name = products[prod_index].product_name;
38148 - h->access = *(products[prod_index].access);
38149 + h->access = products[prod_index].access;
38150
38151 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38152 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38153 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38154
38155 assert_spin_locked(&lockup_detector_lock);
38156 remove_ctlr_from_lockup_detector_list(h);
38157 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38158 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38159 spin_lock_irqsave(&h->lock, flags);
38160 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38161 spin_unlock_irqrestore(&h->lock, flags);
38162 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38163 }
38164
38165 /* make sure the board interrupts are off */
38166 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38167 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38168
38169 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38170 goto clean2;
38171 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38172 * fake ones to scoop up any residual completions.
38173 */
38174 spin_lock_irqsave(&h->lock, flags);
38175 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38176 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38177 spin_unlock_irqrestore(&h->lock, flags);
38178 free_irqs(h);
38179 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38180 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38181 dev_info(&h->pdev->dev, "Board READY.\n");
38182 dev_info(&h->pdev->dev,
38183 "Waiting for stale completions to drain.\n");
38184 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38185 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38186 msleep(10000);
38187 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38188 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38189
38190 rc = controller_reset_failed(h->cfgtable);
38191 if (rc)
38192 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38193 }
38194
38195 /* Turn the interrupts on so we can service requests */
38196 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38197 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38198
38199 hpsa_hba_inquiry(h);
38200 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38201 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38202 * To write all data in the battery backed cache to disks
38203 */
38204 hpsa_flush_cache(h);
38205 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38206 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38207 hpsa_free_irqs_and_disable_msix(h);
38208 }
38209
38210 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38211 return;
38212 }
38213 /* Change the access methods to the performant access methods */
38214 - h->access = SA5_performant_access;
38215 + h->access = &SA5_performant_access;
38216 h->transMethod = CFGTBL_Trans_Performant;
38217 }
38218
38219 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38220 index 9816479..c5d4e97 100644
38221 --- a/drivers/scsi/hpsa.h
38222 +++ b/drivers/scsi/hpsa.h
38223 @@ -79,7 +79,7 @@ struct ctlr_info {
38224 unsigned int msix_vector;
38225 unsigned int msi_vector;
38226 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38227 - struct access_method access;
38228 + struct access_method *access;
38229
38230 /* queue and queue Info */
38231 struct list_head reqQ;
38232 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38233 index c772d8d..35c362c 100644
38234 --- a/drivers/scsi/libfc/fc_exch.c
38235 +++ b/drivers/scsi/libfc/fc_exch.c
38236 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
38237 u16 pool_max_index;
38238
38239 struct {
38240 - atomic_t no_free_exch;
38241 - atomic_t no_free_exch_xid;
38242 - atomic_t xid_not_found;
38243 - atomic_t xid_busy;
38244 - atomic_t seq_not_found;
38245 - atomic_t non_bls_resp;
38246 + atomic_unchecked_t no_free_exch;
38247 + atomic_unchecked_t no_free_exch_xid;
38248 + atomic_unchecked_t xid_not_found;
38249 + atomic_unchecked_t xid_busy;
38250 + atomic_unchecked_t seq_not_found;
38251 + atomic_unchecked_t non_bls_resp;
38252 } stats;
38253 };
38254
38255 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38256 /* allocate memory for exchange */
38257 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38258 if (!ep) {
38259 - atomic_inc(&mp->stats.no_free_exch);
38260 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38261 goto out;
38262 }
38263 memset(ep, 0, sizeof(*ep));
38264 @@ -786,7 +786,7 @@ out:
38265 return ep;
38266 err:
38267 spin_unlock_bh(&pool->lock);
38268 - atomic_inc(&mp->stats.no_free_exch_xid);
38269 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38270 mempool_free(ep, mp->ep_pool);
38271 return NULL;
38272 }
38273 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38274 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38275 ep = fc_exch_find(mp, xid);
38276 if (!ep) {
38277 - atomic_inc(&mp->stats.xid_not_found);
38278 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38279 reject = FC_RJT_OX_ID;
38280 goto out;
38281 }
38282 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38283 ep = fc_exch_find(mp, xid);
38284 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38285 if (ep) {
38286 - atomic_inc(&mp->stats.xid_busy);
38287 + atomic_inc_unchecked(&mp->stats.xid_busy);
38288 reject = FC_RJT_RX_ID;
38289 goto rel;
38290 }
38291 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38292 }
38293 xid = ep->xid; /* get our XID */
38294 } else if (!ep) {
38295 - atomic_inc(&mp->stats.xid_not_found);
38296 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38297 reject = FC_RJT_RX_ID; /* XID not found */
38298 goto out;
38299 }
38300 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38301 } else {
38302 sp = &ep->seq;
38303 if (sp->id != fh->fh_seq_id) {
38304 - atomic_inc(&mp->stats.seq_not_found);
38305 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38306 if (f_ctl & FC_FC_END_SEQ) {
38307 /*
38308 * Update sequence_id based on incoming last
38309 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38310
38311 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38312 if (!ep) {
38313 - atomic_inc(&mp->stats.xid_not_found);
38314 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38315 goto out;
38316 }
38317 if (ep->esb_stat & ESB_ST_COMPLETE) {
38318 - atomic_inc(&mp->stats.xid_not_found);
38319 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38320 goto rel;
38321 }
38322 if (ep->rxid == FC_XID_UNKNOWN)
38323 ep->rxid = ntohs(fh->fh_rx_id);
38324 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38325 - atomic_inc(&mp->stats.xid_not_found);
38326 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38327 goto rel;
38328 }
38329 if (ep->did != ntoh24(fh->fh_s_id) &&
38330 ep->did != FC_FID_FLOGI) {
38331 - atomic_inc(&mp->stats.xid_not_found);
38332 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38333 goto rel;
38334 }
38335 sof = fr_sof(fp);
38336 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38337 sp->ssb_stat |= SSB_ST_RESP;
38338 sp->id = fh->fh_seq_id;
38339 } else if (sp->id != fh->fh_seq_id) {
38340 - atomic_inc(&mp->stats.seq_not_found);
38341 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38342 goto rel;
38343 }
38344
38345 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38346 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38347
38348 if (!sp)
38349 - atomic_inc(&mp->stats.xid_not_found);
38350 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38351 else
38352 - atomic_inc(&mp->stats.non_bls_resp);
38353 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38354
38355 fc_frame_free(fp);
38356 }
38357 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38358
38359 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38360 mp = ema->mp;
38361 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38362 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38363 st->fc_no_free_exch_xid +=
38364 - atomic_read(&mp->stats.no_free_exch_xid);
38365 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38366 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38367 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38368 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38369 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38370 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38371 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38372 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38373 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38374 }
38375 }
38376 EXPORT_SYMBOL(fc_exch_update_stats);
38377 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38378 index bdb81cd..d3c7c2c 100644
38379 --- a/drivers/scsi/libsas/sas_ata.c
38380 +++ b/drivers/scsi/libsas/sas_ata.c
38381 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38382 .postreset = ata_std_postreset,
38383 .error_handler = ata_std_error_handler,
38384 .post_internal_cmd = sas_ata_post_internal,
38385 - .qc_defer = ata_std_qc_defer,
38386 + .qc_defer = ata_std_qc_defer,
38387 .qc_prep = ata_noop_qc_prep,
38388 .qc_issue = sas_ata_qc_issue,
38389 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38390 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38391 index 69b5993..1ac9dce 100644
38392 --- a/drivers/scsi/lpfc/lpfc.h
38393 +++ b/drivers/scsi/lpfc/lpfc.h
38394 @@ -424,7 +424,7 @@ struct lpfc_vport {
38395 struct dentry *debug_nodelist;
38396 struct dentry *vport_debugfs_root;
38397 struct lpfc_debugfs_trc *disc_trc;
38398 - atomic_t disc_trc_cnt;
38399 + atomic_unchecked_t disc_trc_cnt;
38400 #endif
38401 uint8_t stat_data_enabled;
38402 uint8_t stat_data_blocked;
38403 @@ -840,8 +840,8 @@ struct lpfc_hba {
38404 struct timer_list fabric_block_timer;
38405 unsigned long bit_flags;
38406 #define FABRIC_COMANDS_BLOCKED 0
38407 - atomic_t num_rsrc_err;
38408 - atomic_t num_cmd_success;
38409 + atomic_unchecked_t num_rsrc_err;
38410 + atomic_unchecked_t num_cmd_success;
38411 unsigned long last_rsrc_error_time;
38412 unsigned long last_ramp_down_time;
38413 unsigned long last_ramp_up_time;
38414 @@ -877,7 +877,7 @@ struct lpfc_hba {
38415
38416 struct dentry *debug_slow_ring_trc;
38417 struct lpfc_debugfs_trc *slow_ring_trc;
38418 - atomic_t slow_ring_trc_cnt;
38419 + atomic_unchecked_t slow_ring_trc_cnt;
38420 /* iDiag debugfs sub-directory */
38421 struct dentry *idiag_root;
38422 struct dentry *idiag_pci_cfg;
38423 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38424 index f63f5ff..de29189 100644
38425 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38426 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38427 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38428
38429 #include <linux/debugfs.h>
38430
38431 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38432 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38433 static unsigned long lpfc_debugfs_start_time = 0L;
38434
38435 /* iDiag */
38436 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38437 lpfc_debugfs_enable = 0;
38438
38439 len = 0;
38440 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38441 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38442 (lpfc_debugfs_max_disc_trc - 1);
38443 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38444 dtp = vport->disc_trc + i;
38445 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38446 lpfc_debugfs_enable = 0;
38447
38448 len = 0;
38449 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38450 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38451 (lpfc_debugfs_max_slow_ring_trc - 1);
38452 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38453 dtp = phba->slow_ring_trc + i;
38454 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38455 !vport || !vport->disc_trc)
38456 return;
38457
38458 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38459 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38460 (lpfc_debugfs_max_disc_trc - 1);
38461 dtp = vport->disc_trc + index;
38462 dtp->fmt = fmt;
38463 dtp->data1 = data1;
38464 dtp->data2 = data2;
38465 dtp->data3 = data3;
38466 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38467 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38468 dtp->jif = jiffies;
38469 #endif
38470 return;
38471 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38472 !phba || !phba->slow_ring_trc)
38473 return;
38474
38475 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38476 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38477 (lpfc_debugfs_max_slow_ring_trc - 1);
38478 dtp = phba->slow_ring_trc + index;
38479 dtp->fmt = fmt;
38480 dtp->data1 = data1;
38481 dtp->data2 = data2;
38482 dtp->data3 = data3;
38483 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38484 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38485 dtp->jif = jiffies;
38486 #endif
38487 return;
38488 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38489 "slow_ring buffer\n");
38490 goto debug_failed;
38491 }
38492 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38493 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38494 memset(phba->slow_ring_trc, 0,
38495 (sizeof(struct lpfc_debugfs_trc) *
38496 lpfc_debugfs_max_slow_ring_trc));
38497 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38498 "buffer\n");
38499 goto debug_failed;
38500 }
38501 - atomic_set(&vport->disc_trc_cnt, 0);
38502 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38503
38504 snprintf(name, sizeof(name), "discovery_trace");
38505 vport->debug_disc_trc =
38506 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38507 index 7dc4218..3436f08 100644
38508 --- a/drivers/scsi/lpfc/lpfc_init.c
38509 +++ b/drivers/scsi/lpfc/lpfc_init.c
38510 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38511 "misc_register returned with status %d", error);
38512
38513 if (lpfc_enable_npiv) {
38514 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38515 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38516 + pax_open_kernel();
38517 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38518 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38519 + pax_close_kernel();
38520 }
38521 lpfc_transport_template =
38522 fc_attach_transport(&lpfc_transport_functions);
38523 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38524 index 7f45ac9..cf62eda 100644
38525 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38526 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38527 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38528 uint32_t evt_posted;
38529
38530 spin_lock_irqsave(&phba->hbalock, flags);
38531 - atomic_inc(&phba->num_rsrc_err);
38532 + atomic_inc_unchecked(&phba->num_rsrc_err);
38533 phba->last_rsrc_error_time = jiffies;
38534
38535 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38536 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38537 unsigned long flags;
38538 struct lpfc_hba *phba = vport->phba;
38539 uint32_t evt_posted;
38540 - atomic_inc(&phba->num_cmd_success);
38541 + atomic_inc_unchecked(&phba->num_cmd_success);
38542
38543 if (vport->cfg_lun_queue_depth <= queue_depth)
38544 return;
38545 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38546 unsigned long num_rsrc_err, num_cmd_success;
38547 int i;
38548
38549 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38550 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38551 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38552 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38553
38554 /*
38555 * The error and success command counters are global per
38556 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38557 }
38558 }
38559 lpfc_destroy_vport_work_array(phba, vports);
38560 - atomic_set(&phba->num_rsrc_err, 0);
38561 - atomic_set(&phba->num_cmd_success, 0);
38562 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38563 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38564 }
38565
38566 /**
38567 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38568 }
38569 }
38570 lpfc_destroy_vport_work_array(phba, vports);
38571 - atomic_set(&phba->num_rsrc_err, 0);
38572 - atomic_set(&phba->num_cmd_success, 0);
38573 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38574 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38575 }
38576
38577 /**
38578 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38579 index af763ea..41904f7 100644
38580 --- a/drivers/scsi/pmcraid.c
38581 +++ b/drivers/scsi/pmcraid.c
38582 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38583 res->scsi_dev = scsi_dev;
38584 scsi_dev->hostdata = res;
38585 res->change_detected = 0;
38586 - atomic_set(&res->read_failures, 0);
38587 - atomic_set(&res->write_failures, 0);
38588 + atomic_set_unchecked(&res->read_failures, 0);
38589 + atomic_set_unchecked(&res->write_failures, 0);
38590 rc = 0;
38591 }
38592 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38593 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38594
38595 /* If this was a SCSI read/write command keep count of errors */
38596 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38597 - atomic_inc(&res->read_failures);
38598 + atomic_inc_unchecked(&res->read_failures);
38599 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38600 - atomic_inc(&res->write_failures);
38601 + atomic_inc_unchecked(&res->write_failures);
38602
38603 if (!RES_IS_GSCSI(res->cfg_entry) &&
38604 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38605 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38606 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38607 * hrrq_id assigned here in queuecommand
38608 */
38609 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38610 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38611 pinstance->num_hrrq;
38612 cmd->cmd_done = pmcraid_io_done;
38613
38614 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38615 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38616 * hrrq_id assigned here in queuecommand
38617 */
38618 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38619 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38620 pinstance->num_hrrq;
38621
38622 if (request_size) {
38623 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38624
38625 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38626 /* add resources only after host is added into system */
38627 - if (!atomic_read(&pinstance->expose_resources))
38628 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38629 return;
38630
38631 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38632 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38633 init_waitqueue_head(&pinstance->reset_wait_q);
38634
38635 atomic_set(&pinstance->outstanding_cmds, 0);
38636 - atomic_set(&pinstance->last_message_id, 0);
38637 - atomic_set(&pinstance->expose_resources, 0);
38638 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38639 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38640
38641 INIT_LIST_HEAD(&pinstance->free_res_q);
38642 INIT_LIST_HEAD(&pinstance->used_res_q);
38643 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38644 /* Schedule worker thread to handle CCN and take care of adding and
38645 * removing devices to OS
38646 */
38647 - atomic_set(&pinstance->expose_resources, 1);
38648 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38649 schedule_work(&pinstance->worker_q);
38650 return rc;
38651
38652 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38653 index e1d150f..6c6df44 100644
38654 --- a/drivers/scsi/pmcraid.h
38655 +++ b/drivers/scsi/pmcraid.h
38656 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38657 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38658
38659 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38660 - atomic_t last_message_id;
38661 + atomic_unchecked_t last_message_id;
38662
38663 /* configuration table */
38664 struct pmcraid_config_table *cfg_table;
38665 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38666 atomic_t outstanding_cmds;
38667
38668 /* should add/delete resources to mid-layer now ?*/
38669 - atomic_t expose_resources;
38670 + atomic_unchecked_t expose_resources;
38671
38672
38673
38674 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38675 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38676 };
38677 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38678 - atomic_t read_failures; /* count of failed READ commands */
38679 - atomic_t write_failures; /* count of failed WRITE commands */
38680 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38681 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38682
38683 /* To indicate add/delete/modify during CCN */
38684 u8 change_detected;
38685 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38686 index 83d7984..a27d947 100644
38687 --- a/drivers/scsi/qla2xxx/qla_attr.c
38688 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38689 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38690 return 0;
38691 }
38692
38693 -struct fc_function_template qla2xxx_transport_functions = {
38694 +fc_function_template_no_const qla2xxx_transport_functions = {
38695
38696 .show_host_node_name = 1,
38697 .show_host_port_name = 1,
38698 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38699 .bsg_timeout = qla24xx_bsg_timeout,
38700 };
38701
38702 -struct fc_function_template qla2xxx_transport_vport_functions = {
38703 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38704
38705 .show_host_node_name = 1,
38706 .show_host_port_name = 1,
38707 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38708 index 6acb397..d86e3e0 100644
38709 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38710 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38711 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38712 struct device_attribute;
38713 extern struct device_attribute *qla2x00_host_attrs[];
38714 struct fc_function_template;
38715 -extern struct fc_function_template qla2xxx_transport_functions;
38716 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38717 +extern fc_function_template_no_const qla2xxx_transport_functions;
38718 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38719 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38720 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38721 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38722 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38723 index f4b1fc8..a1ce4dd 100644
38724 --- a/drivers/scsi/qla2xxx/qla_os.c
38725 +++ b/drivers/scsi/qla2xxx/qla_os.c
38726 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38727 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38728 /* Ok, a 64bit DMA mask is applicable. */
38729 ha->flags.enable_64bit_addressing = 1;
38730 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38731 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38732 + pax_open_kernel();
38733 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38734 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38735 + pax_close_kernel();
38736 return;
38737 }
38738 }
38739 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38740 index 329d553..f20d31d 100644
38741 --- a/drivers/scsi/qla4xxx/ql4_def.h
38742 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38743 @@ -273,7 +273,7 @@ struct ddb_entry {
38744 * (4000 only) */
38745 atomic_t relogin_timer; /* Max Time to wait for
38746 * relogin to complete */
38747 - atomic_t relogin_retry_count; /* Num of times relogin has been
38748 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38749 * retried */
38750 uint32_t default_time2wait; /* Default Min time between
38751 * relogins (+aens) */
38752 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38753 index fbc546e..c7d1b48 100644
38754 --- a/drivers/scsi/qla4xxx/ql4_os.c
38755 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38756 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38757 */
38758 if (!iscsi_is_session_online(cls_sess)) {
38759 /* Reset retry relogin timer */
38760 - atomic_inc(&ddb_entry->relogin_retry_count);
38761 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38762 DEBUG2(ql4_printk(KERN_INFO, ha,
38763 "%s: index[%d] relogin timed out-retrying"
38764 " relogin (%d), retry (%d)\n", __func__,
38765 ddb_entry->fw_ddb_index,
38766 - atomic_read(&ddb_entry->relogin_retry_count),
38767 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38768 ddb_entry->default_time2wait + 4));
38769 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38770 atomic_set(&ddb_entry->retry_relogin_timer,
38771 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38772
38773 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38774 atomic_set(&ddb_entry->relogin_timer, 0);
38775 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38776 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38777 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38778 ddb_entry->default_relogin_timeout =
38779 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38780 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38781 index 2c0d0ec..4e8681a 100644
38782 --- a/drivers/scsi/scsi.c
38783 +++ b/drivers/scsi/scsi.c
38784 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38785 unsigned long timeout;
38786 int rtn = 0;
38787
38788 - atomic_inc(&cmd->device->iorequest_cnt);
38789 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38790
38791 /* check if the device is still usable */
38792 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38793 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38794 index 9032e91..7a805d0 100644
38795 --- a/drivers/scsi/scsi_lib.c
38796 +++ b/drivers/scsi/scsi_lib.c
38797 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38798 shost = sdev->host;
38799 scsi_init_cmd_errh(cmd);
38800 cmd->result = DID_NO_CONNECT << 16;
38801 - atomic_inc(&cmd->device->iorequest_cnt);
38802 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38803
38804 /*
38805 * SCSI request completion path will do scsi_device_unbusy(),
38806 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38807
38808 INIT_LIST_HEAD(&cmd->eh_entry);
38809
38810 - atomic_inc(&cmd->device->iodone_cnt);
38811 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38812 if (cmd->result)
38813 - atomic_inc(&cmd->device->ioerr_cnt);
38814 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38815
38816 disposition = scsi_decide_disposition(cmd);
38817 if (disposition != SUCCESS &&
38818 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38819 index 931a7d9..0c2a754 100644
38820 --- a/drivers/scsi/scsi_sysfs.c
38821 +++ b/drivers/scsi/scsi_sysfs.c
38822 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38823 char *buf) \
38824 { \
38825 struct scsi_device *sdev = to_scsi_device(dev); \
38826 - unsigned long long count = atomic_read(&sdev->field); \
38827 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38828 return snprintf(buf, 20, "0x%llx\n", count); \
38829 } \
38830 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38831 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38832 index 84a1fdf..693b0d6 100644
38833 --- a/drivers/scsi/scsi_tgt_lib.c
38834 +++ b/drivers/scsi/scsi_tgt_lib.c
38835 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38836 int err;
38837
38838 dprintk("%lx %u\n", uaddr, len);
38839 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38840 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38841 if (err) {
38842 /*
38843 * TODO: need to fixup sg_tablesize, max_segment_size,
38844 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38845 index e894ca7..de9d7660 100644
38846 --- a/drivers/scsi/scsi_transport_fc.c
38847 +++ b/drivers/scsi/scsi_transport_fc.c
38848 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38849 * Netlink Infrastructure
38850 */
38851
38852 -static atomic_t fc_event_seq;
38853 +static atomic_unchecked_t fc_event_seq;
38854
38855 /**
38856 * fc_get_event_number - Obtain the next sequential FC event number
38857 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
38858 u32
38859 fc_get_event_number(void)
38860 {
38861 - return atomic_add_return(1, &fc_event_seq);
38862 + return atomic_add_return_unchecked(1, &fc_event_seq);
38863 }
38864 EXPORT_SYMBOL(fc_get_event_number);
38865
38866 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
38867 {
38868 int error;
38869
38870 - atomic_set(&fc_event_seq, 0);
38871 + atomic_set_unchecked(&fc_event_seq, 0);
38872
38873 error = transport_class_register(&fc_host_class);
38874 if (error)
38875 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38876 char *cp;
38877
38878 *val = simple_strtoul(buf, &cp, 0);
38879 - if ((*cp && (*cp != '\n')) || (*val < 0))
38880 + if (*cp && (*cp != '\n'))
38881 return -EINVAL;
38882 /*
38883 * Check for overflow; dev_loss_tmo is u32
38884 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38885 index 31969f2..2b348f0 100644
38886 --- a/drivers/scsi/scsi_transport_iscsi.c
38887 +++ b/drivers/scsi/scsi_transport_iscsi.c
38888 @@ -79,7 +79,7 @@ struct iscsi_internal {
38889 struct transport_container session_cont;
38890 };
38891
38892 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38893 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38894 static struct workqueue_struct *iscsi_eh_timer_workq;
38895
38896 static DEFINE_IDA(iscsi_sess_ida);
38897 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38898 int err;
38899
38900 ihost = shost->shost_data;
38901 - session->sid = atomic_add_return(1, &iscsi_session_nr);
38902 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38903
38904 if (target_id == ISCSI_MAX_TARGET) {
38905 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38906 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
38907 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38908 ISCSI_TRANSPORT_VERSION);
38909
38910 - atomic_set(&iscsi_session_nr, 0);
38911 + atomic_set_unchecked(&iscsi_session_nr, 0);
38912
38913 err = class_register(&iscsi_transport_class);
38914 if (err)
38915 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38916 index 21a045e..ec89e03 100644
38917 --- a/drivers/scsi/scsi_transport_srp.c
38918 +++ b/drivers/scsi/scsi_transport_srp.c
38919 @@ -33,7 +33,7 @@
38920 #include "scsi_transport_srp_internal.h"
38921
38922 struct srp_host_attrs {
38923 - atomic_t next_port_id;
38924 + atomic_unchecked_t next_port_id;
38925 };
38926 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38927
38928 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38929 struct Scsi_Host *shost = dev_to_shost(dev);
38930 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38931
38932 - atomic_set(&srp_host->next_port_id, 0);
38933 + atomic_set_unchecked(&srp_host->next_port_id, 0);
38934 return 0;
38935 }
38936
38937 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38938 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38939 rport->roles = ids->roles;
38940
38941 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38942 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38943 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38944
38945 transport_setup_device(&rport->dev);
38946 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
38947 index a45e12a..d9120cb 100644
38948 --- a/drivers/scsi/sd.c
38949 +++ b/drivers/scsi/sd.c
38950 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
38951 sdkp->disk = gd;
38952 sdkp->index = index;
38953 atomic_set(&sdkp->openers, 0);
38954 - atomic_set(&sdkp->device->ioerr_cnt, 0);
38955 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
38956
38957 if (!sdp->request_queue->rq_timeout) {
38958 if (sdp->type != TYPE_MOD)
38959 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38960 index be2c9a6..275525c 100644
38961 --- a/drivers/scsi/sg.c
38962 +++ b/drivers/scsi/sg.c
38963 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38964 sdp->disk->disk_name,
38965 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38966 NULL,
38967 - (char *)arg);
38968 + (char __user *)arg);
38969 case BLKTRACESTART:
38970 return blk_trace_startstop(sdp->device->request_queue, 1);
38971 case BLKTRACESTOP:
38972 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38973 index 84c2861..ece0a31 100644
38974 --- a/drivers/spi/spi.c
38975 +++ b/drivers/spi/spi.c
38976 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
38977 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38978
38979 /* portable code must never pass more than 32 bytes */
38980 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38981 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38982
38983 static u8 *buf;
38984
38985 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38986 index 34afc16..ffe44dd 100644
38987 --- a/drivers/staging/octeon/ethernet-rx.c
38988 +++ b/drivers/staging/octeon/ethernet-rx.c
38989 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38990 /* Increment RX stats for virtual ports */
38991 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38992 #ifdef CONFIG_64BIT
38993 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38994 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38995 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38996 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38997 #else
38998 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38999 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39000 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39001 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39002 #endif
39003 }
39004 netif_receive_skb(skb);
39005 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39006 dev->name);
39007 */
39008 #ifdef CONFIG_64BIT
39009 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39010 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39011 #else
39012 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39013 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39014 #endif
39015 dev_kfree_skb_irq(skb);
39016 }
39017 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39018 index 683bedc..86dba9a 100644
39019 --- a/drivers/staging/octeon/ethernet.c
39020 +++ b/drivers/staging/octeon/ethernet.c
39021 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39022 * since the RX tasklet also increments it.
39023 */
39024 #ifdef CONFIG_64BIT
39025 - atomic64_add(rx_status.dropped_packets,
39026 - (atomic64_t *)&priv->stats.rx_dropped);
39027 + atomic64_add_unchecked(rx_status.dropped_packets,
39028 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39029 #else
39030 - atomic_add(rx_status.dropped_packets,
39031 - (atomic_t *)&priv->stats.rx_dropped);
39032 + atomic_add_unchecked(rx_status.dropped_packets,
39033 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39034 #endif
39035 }
39036
39037 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39038 index a2b7e03..aaf3630 100644
39039 --- a/drivers/staging/ramster/tmem.c
39040 +++ b/drivers/staging/ramster/tmem.c
39041 @@ -50,25 +50,25 @@
39042 * A tmem host implementation must use this function to register callbacks
39043 * for memory allocation.
39044 */
39045 -static struct tmem_hostops tmem_hostops;
39046 +static struct tmem_hostops *tmem_hostops;
39047
39048 static void tmem_objnode_tree_init(void);
39049
39050 void tmem_register_hostops(struct tmem_hostops *m)
39051 {
39052 tmem_objnode_tree_init();
39053 - tmem_hostops = *m;
39054 + tmem_hostops = m;
39055 }
39056
39057 /*
39058 * A tmem host implementation must use this function to register
39059 * callbacks for a page-accessible memory (PAM) implementation.
39060 */
39061 -static struct tmem_pamops tmem_pamops;
39062 +static struct tmem_pamops *tmem_pamops;
39063
39064 void tmem_register_pamops(struct tmem_pamops *m)
39065 {
39066 - tmem_pamops = *m;
39067 + tmem_pamops = m;
39068 }
39069
39070 /*
39071 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39072 obj->pampd_count = 0;
39073 #ifdef CONFIG_RAMSTER
39074 if (tmem_pamops.new_obj != NULL)
39075 - (*tmem_pamops.new_obj)(obj);
39076 + (tmem_pamops->new_obj)(obj);
39077 #endif
39078 SET_SENTINEL(obj, OBJ);
39079
39080 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39081 rbnode = rb_next(rbnode);
39082 tmem_pampd_destroy_all_in_obj(obj, true);
39083 tmem_obj_free(obj, hb);
39084 - (*tmem_hostops.obj_free)(obj, pool);
39085 + (tmem_hostops->obj_free)(obj, pool);
39086 }
39087 spin_unlock(&hb->lock);
39088 }
39089 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39090 ASSERT_SENTINEL(obj, OBJ);
39091 BUG_ON(obj->pool == NULL);
39092 ASSERT_SENTINEL(obj->pool, POOL);
39093 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39094 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39095 if (unlikely(objnode == NULL))
39096 goto out;
39097 objnode->obj = obj;
39098 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39099 ASSERT_SENTINEL(pool, POOL);
39100 objnode->obj->objnode_count--;
39101 objnode->obj = NULL;
39102 - (*tmem_hostops.objnode_free)(objnode, pool);
39103 + (tmem_hostops->objnode_free)(objnode, pool);
39104 }
39105
39106 /*
39107 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39108 void *old_pampd = *(void **)slot;
39109 *(void **)slot = new_pampd;
39110 if (!no_free)
39111 - (*tmem_pamops.free)(old_pampd, obj->pool,
39112 + (tmem_pamops->free)(old_pampd, obj->pool,
39113 NULL, 0, false);
39114 ret = new_pampd;
39115 }
39116 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39117 if (objnode->slots[i]) {
39118 if (ht == 1) {
39119 obj->pampd_count--;
39120 - (*tmem_pamops.free)(objnode->slots[i],
39121 + (tmem_pamops->free)(objnode->slots[i],
39122 obj->pool, NULL, 0, true);
39123 objnode->slots[i] = NULL;
39124 continue;
39125 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39126 return;
39127 if (obj->objnode_tree_height == 0) {
39128 obj->pampd_count--;
39129 - (*tmem_pamops.free)(obj->objnode_tree_root,
39130 + (tmem_pamops->free)(obj->objnode_tree_root,
39131 obj->pool, NULL, 0, true);
39132 } else {
39133 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39134 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39135 obj->objnode_tree_root = NULL;
39136 #ifdef CONFIG_RAMSTER
39137 if (tmem_pamops.free_obj != NULL)
39138 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39139 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39140 #endif
39141 }
39142
39143 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39144 /* if found, is a dup put, flush the old one */
39145 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39146 BUG_ON(pampd_del != pampd);
39147 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39148 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39149 if (obj->pampd_count == 0) {
39150 objnew = obj;
39151 objfound = NULL;
39152 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39153 pampd = NULL;
39154 }
39155 } else {
39156 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39157 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
39158 if (unlikely(obj == NULL)) {
39159 ret = -ENOMEM;
39160 goto out;
39161 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39162 if (unlikely(ret == -ENOMEM))
39163 /* may have partially built objnode tree ("stump") */
39164 goto delete_and_free;
39165 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39166 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39167 goto out;
39168
39169 delete_and_free:
39170 (void)tmem_pampd_delete_from_obj(obj, index);
39171 if (pampd)
39172 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39173 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39174 if (objnew) {
39175 tmem_obj_free(objnew, hb);
39176 - (*tmem_hostops.obj_free)(objnew, pool);
39177 + (tmem_hostops->obj_free)(objnew, pool);
39178 }
39179 out:
39180 spin_unlock(&hb->lock);
39181 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39182 if (pampd != NULL) {
39183 BUG_ON(obj == NULL);
39184 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39185 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39186 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39187 } else if (delete) {
39188 BUG_ON(obj == NULL);
39189 (void)tmem_pampd_delete_from_obj(obj, index);
39190 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39191 int ret = 0;
39192
39193 if (!is_ephemeral(pool))
39194 - new_pampd = (*tmem_pamops.repatriate_preload)(
39195 + new_pampd = (tmem_pamops->repatriate_preload)(
39196 old_pampd, pool, oidp, index, &intransit);
39197 if (intransit)
39198 ret = -EAGAIN;
39199 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39200 /* must release the hb->lock else repatriate can't sleep */
39201 spin_unlock(&hb->lock);
39202 if (!intransit)
39203 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39204 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39205 oidp, index, free, data);
39206 if (ret == -EAGAIN) {
39207 /* rare I think, but should cond_resched()??? */
39208 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39209 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39210 /* if we bug here, pamops wasn't properly set up for ramster */
39211 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39212 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39213 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39214 out:
39215 spin_unlock(&hb->lock);
39216 return ret;
39217 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39218 if (free) {
39219 if (obj->pampd_count == 0) {
39220 tmem_obj_free(obj, hb);
39221 - (*tmem_hostops.obj_free)(obj, pool);
39222 + (tmem_hostops->obj_free)(obj, pool);
39223 obj = NULL;
39224 }
39225 }
39226 if (free)
39227 - ret = (*tmem_pamops.get_data_and_free)(
39228 + ret = (tmem_pamops->get_data_and_free)(
39229 data, sizep, raw, pampd, pool, oidp, index);
39230 else
39231 - ret = (*tmem_pamops.get_data)(
39232 + ret = (tmem_pamops->get_data)(
39233 data, sizep, raw, pampd, pool, oidp, index);
39234 if (ret < 0)
39235 goto out;
39236 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39237 pampd = tmem_pampd_delete_from_obj(obj, index);
39238 if (pampd == NULL)
39239 goto out;
39240 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39241 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39242 if (obj->pampd_count == 0) {
39243 tmem_obj_free(obj, hb);
39244 - (*tmem_hostops.obj_free)(obj, pool);
39245 + (tmem_hostops->obj_free)(obj, pool);
39246 }
39247 ret = 0;
39248
39249 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39250 goto out;
39251 tmem_pampd_destroy_all_in_obj(obj, false);
39252 tmem_obj_free(obj, hb);
39253 - (*tmem_hostops.obj_free)(obj, pool);
39254 + (tmem_hostops->obj_free)(obj, pool);
39255 ret = 0;
39256
39257 out:
39258 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39259 index dc23395..cf7e9b1 100644
39260 --- a/drivers/staging/rtl8712/rtl871x_io.h
39261 +++ b/drivers/staging/rtl8712/rtl871x_io.h
39262 @@ -108,7 +108,7 @@ struct _io_ops {
39263 u8 *pmem);
39264 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39265 u8 *pmem);
39266 -};
39267 +} __no_const;
39268
39269 struct io_req {
39270 struct list_head list;
39271 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39272 index 180c963..1f18377 100644
39273 --- a/drivers/staging/sbe-2t3e3/netdev.c
39274 +++ b/drivers/staging/sbe-2t3e3/netdev.c
39275 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39276 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39277
39278 if (rlen)
39279 - if (copy_to_user(data, &resp, rlen))
39280 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39281 return -EFAULT;
39282
39283 return 0;
39284 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39285 index c66b8b3..a4a035b 100644
39286 --- a/drivers/staging/usbip/vhci.h
39287 +++ b/drivers/staging/usbip/vhci.h
39288 @@ -83,7 +83,7 @@ struct vhci_hcd {
39289 unsigned resuming:1;
39290 unsigned long re_timeout;
39291
39292 - atomic_t seqnum;
39293 + atomic_unchecked_t seqnum;
39294
39295 /*
39296 * NOTE:
39297 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39298 index 620d1be..1cd6711 100644
39299 --- a/drivers/staging/usbip/vhci_hcd.c
39300 +++ b/drivers/staging/usbip/vhci_hcd.c
39301 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39302 return;
39303 }
39304
39305 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39306 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39307 if (priv->seqnum == 0xffff)
39308 dev_info(&urb->dev->dev, "seqnum max\n");
39309
39310 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39311 return -ENOMEM;
39312 }
39313
39314 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39315 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39316 if (unlink->seqnum == 0xffff)
39317 pr_info("seqnum max\n");
39318
39319 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39320 vdev->rhport = rhport;
39321 }
39322
39323 - atomic_set(&vhci->seqnum, 0);
39324 + atomic_set_unchecked(&vhci->seqnum, 0);
39325 spin_lock_init(&vhci->lock);
39326
39327 hcd->power_budget = 0; /* no limit */
39328 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39329 index f0eaf04..5a82e06 100644
39330 --- a/drivers/staging/usbip/vhci_rx.c
39331 +++ b/drivers/staging/usbip/vhci_rx.c
39332 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39333 if (!urb) {
39334 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39335 pr_info("max seqnum %d\n",
39336 - atomic_read(&the_controller->seqnum));
39337 + atomic_read_unchecked(&the_controller->seqnum));
39338 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39339 return;
39340 }
39341 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39342 index 67b1b88..6392fe9 100644
39343 --- a/drivers/staging/vt6655/hostap.c
39344 +++ b/drivers/staging/vt6655/hostap.c
39345 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39346 *
39347 */
39348
39349 +static net_device_ops_no_const apdev_netdev_ops;
39350 +
39351 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39352 {
39353 PSDevice apdev_priv;
39354 struct net_device *dev = pDevice->dev;
39355 int ret;
39356 - const struct net_device_ops apdev_netdev_ops = {
39357 - .ndo_start_xmit = pDevice->tx_80211,
39358 - };
39359
39360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39361
39362 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39363 *apdev_priv = *pDevice;
39364 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39365
39366 + /* only half broken now */
39367 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39368 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39369
39370 pDevice->apdev->type = ARPHRD_IEEE80211;
39371 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39372 index 0a73d40..6fda560 100644
39373 --- a/drivers/staging/vt6656/hostap.c
39374 +++ b/drivers/staging/vt6656/hostap.c
39375 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39376 *
39377 */
39378
39379 +static net_device_ops_no_const apdev_netdev_ops;
39380 +
39381 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39382 {
39383 PSDevice apdev_priv;
39384 struct net_device *dev = pDevice->dev;
39385 int ret;
39386 - const struct net_device_ops apdev_netdev_ops = {
39387 - .ndo_start_xmit = pDevice->tx_80211,
39388 - };
39389
39390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39391
39392 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39393 *apdev_priv = *pDevice;
39394 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39395
39396 + /* only half broken now */
39397 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39398 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39399
39400 pDevice->apdev->type = ARPHRD_IEEE80211;
39401 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39402 index 56c8e60..1920c63 100644
39403 --- a/drivers/staging/zcache/tmem.c
39404 +++ b/drivers/staging/zcache/tmem.c
39405 @@ -39,7 +39,7 @@
39406 * A tmem host implementation must use this function to register callbacks
39407 * for memory allocation.
39408 */
39409 -static struct tmem_hostops tmem_hostops;
39410 +static tmem_hostops_no_const tmem_hostops;
39411
39412 static void tmem_objnode_tree_init(void);
39413
39414 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39415 * A tmem host implementation must use this function to register
39416 * callbacks for a page-accessible memory (PAM) implementation
39417 */
39418 -static struct tmem_pamops tmem_pamops;
39419 +static tmem_pamops_no_const tmem_pamops;
39420
39421 void tmem_register_pamops(struct tmem_pamops *m)
39422 {
39423 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39424 index 0d4aa82..f7832d4 100644
39425 --- a/drivers/staging/zcache/tmem.h
39426 +++ b/drivers/staging/zcache/tmem.h
39427 @@ -180,6 +180,7 @@ struct tmem_pamops {
39428 void (*new_obj)(struct tmem_obj *);
39429 int (*replace_in_obj)(void *, struct tmem_obj *);
39430 };
39431 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39432 extern void tmem_register_pamops(struct tmem_pamops *m);
39433
39434 /* memory allocation methods provided by the host implementation */
39435 @@ -189,6 +190,7 @@ struct tmem_hostops {
39436 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39437 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39438 };
39439 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39440 extern void tmem_register_hostops(struct tmem_hostops *m);
39441
39442 /* core tmem accessor functions */
39443 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39444 index 13fe16c..cbdc39a 100644
39445 --- a/drivers/target/target_core_transport.c
39446 +++ b/drivers/target/target_core_transport.c
39447 @@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39448 spin_lock_init(&dev->se_port_lock);
39449 spin_lock_init(&dev->se_tmr_lock);
39450 spin_lock_init(&dev->qf_cmd_lock);
39451 - atomic_set(&dev->dev_ordered_id, 0);
39452 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39453
39454 se_dev_set_default_attribs(dev, dev_limits);
39455
39456 @@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39457 * Used to determine when ORDERED commands should go from
39458 * Dormant to Active status.
39459 */
39460 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39461 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39462 smp_mb__after_atomic_inc();
39463 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39464 cmd->se_ordered_id, cmd->sam_task_attr,
39465 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39466 index 0a6a0bc..5501b06 100644
39467 --- a/drivers/tty/cyclades.c
39468 +++ b/drivers/tty/cyclades.c
39469 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39470 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39471 info->port.count);
39472 #endif
39473 - info->port.count++;
39474 + atomic_inc(&info->port.count);
39475 #ifdef CY_DEBUG_COUNT
39476 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39477 - current->pid, info->port.count);
39478 + current->pid, atomic_read(&info->port.count));
39479 #endif
39480
39481 /*
39482 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39483 for (j = 0; j < cy_card[i].nports; j++) {
39484 info = &cy_card[i].ports[j];
39485
39486 - if (info->port.count) {
39487 + if (atomic_read(&info->port.count)) {
39488 /* XXX is the ldisc num worth this? */
39489 struct tty_struct *tty;
39490 struct tty_ldisc *ld;
39491 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39492 index 13ee53b..418d164 100644
39493 --- a/drivers/tty/hvc/hvc_console.c
39494 +++ b/drivers/tty/hvc/hvc_console.c
39495 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39496
39497 spin_lock_irqsave(&hp->port.lock, flags);
39498 /* Check and then increment for fast path open. */
39499 - if (hp->port.count++ > 0) {
39500 + if (atomic_inc_return(&hp->port.count) > 1) {
39501 spin_unlock_irqrestore(&hp->port.lock, flags);
39502 hvc_kick();
39503 return 0;
39504 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39505
39506 spin_lock_irqsave(&hp->port.lock, flags);
39507
39508 - if (--hp->port.count == 0) {
39509 + if (atomic_dec_return(&hp->port.count) == 0) {
39510 spin_unlock_irqrestore(&hp->port.lock, flags);
39511 /* We are done with the tty pointer now. */
39512 tty_port_tty_set(&hp->port, NULL);
39513 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39514 */
39515 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39516 } else {
39517 - if (hp->port.count < 0)
39518 + if (atomic_read(&hp->port.count) < 0)
39519 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39520 - hp->vtermno, hp->port.count);
39521 + hp->vtermno, atomic_read(&hp->port.count));
39522 spin_unlock_irqrestore(&hp->port.lock, flags);
39523 }
39524 }
39525 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39526 * open->hangup case this can be called after the final close so prevent
39527 * that from happening for now.
39528 */
39529 - if (hp->port.count <= 0) {
39530 + if (atomic_read(&hp->port.count) <= 0) {
39531 spin_unlock_irqrestore(&hp->port.lock, flags);
39532 return;
39533 }
39534
39535 - hp->port.count = 0;
39536 + atomic_set(&hp->port.count, 0);
39537 spin_unlock_irqrestore(&hp->port.lock, flags);
39538 tty_port_tty_set(&hp->port, NULL);
39539
39540 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39541 return -EPIPE;
39542
39543 /* FIXME what's this (unprotected) check for? */
39544 - if (hp->port.count <= 0)
39545 + if (atomic_read(&hp->port.count) <= 0)
39546 return -EIO;
39547
39548 spin_lock_irqsave(&hp->lock, flags);
39549 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39550 index cab5c7a..4cc66ea 100644
39551 --- a/drivers/tty/hvc/hvcs.c
39552 +++ b/drivers/tty/hvc/hvcs.c
39553 @@ -83,6 +83,7 @@
39554 #include <asm/hvcserver.h>
39555 #include <asm/uaccess.h>
39556 #include <asm/vio.h>
39557 +#include <asm/local.h>
39558
39559 /*
39560 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39561 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39562
39563 spin_lock_irqsave(&hvcsd->lock, flags);
39564
39565 - if (hvcsd->port.count > 0) {
39566 + if (atomic_read(&hvcsd->port.count) > 0) {
39567 spin_unlock_irqrestore(&hvcsd->lock, flags);
39568 printk(KERN_INFO "HVCS: vterm state unchanged. "
39569 "The hvcs device node is still in use.\n");
39570 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39571 }
39572 }
39573
39574 - hvcsd->port.count = 0;
39575 + atomic_set(&hvcsd->port.count, 0);
39576 hvcsd->port.tty = tty;
39577 tty->driver_data = hvcsd;
39578
39579 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39580 unsigned long flags;
39581
39582 spin_lock_irqsave(&hvcsd->lock, flags);
39583 - hvcsd->port.count++;
39584 + atomic_inc(&hvcsd->port.count);
39585 hvcsd->todo_mask |= HVCS_SCHED_READ;
39586 spin_unlock_irqrestore(&hvcsd->lock, flags);
39587
39588 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39589 hvcsd = tty->driver_data;
39590
39591 spin_lock_irqsave(&hvcsd->lock, flags);
39592 - if (--hvcsd->port.count == 0) {
39593 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39594
39595 vio_disable_interrupts(hvcsd->vdev);
39596
39597 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39598
39599 free_irq(irq, hvcsd);
39600 return;
39601 - } else if (hvcsd->port.count < 0) {
39602 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39603 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39604 " is missmanaged.\n",
39605 - hvcsd->vdev->unit_address, hvcsd->port.count);
39606 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39607 }
39608
39609 spin_unlock_irqrestore(&hvcsd->lock, flags);
39610 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39611
39612 spin_lock_irqsave(&hvcsd->lock, flags);
39613 /* Preserve this so that we know how many kref refs to put */
39614 - temp_open_count = hvcsd->port.count;
39615 + temp_open_count = atomic_read(&hvcsd->port.count);
39616
39617 /*
39618 * Don't kref put inside the spinlock because the destruction
39619 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39620 tty->driver_data = NULL;
39621 hvcsd->port.tty = NULL;
39622
39623 - hvcsd->port.count = 0;
39624 + atomic_set(&hvcsd->port.count, 0);
39625
39626 /* This will drop any buffered data on the floor which is OK in a hangup
39627 * scenario. */
39628 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39629 * the middle of a write operation? This is a crummy place to do this
39630 * but we want to keep it all in the spinlock.
39631 */
39632 - if (hvcsd->port.count <= 0) {
39633 + if (atomic_read(&hvcsd->port.count) <= 0) {
39634 spin_unlock_irqrestore(&hvcsd->lock, flags);
39635 return -ENODEV;
39636 }
39637 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39638 {
39639 struct hvcs_struct *hvcsd = tty->driver_data;
39640
39641 - if (!hvcsd || hvcsd->port.count <= 0)
39642 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39643 return 0;
39644
39645 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39646 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39647 index 160f0ad..588b853 100644
39648 --- a/drivers/tty/ipwireless/tty.c
39649 +++ b/drivers/tty/ipwireless/tty.c
39650 @@ -29,6 +29,7 @@
39651 #include <linux/tty_driver.h>
39652 #include <linux/tty_flip.h>
39653 #include <linux/uaccess.h>
39654 +#include <asm/local.h>
39655
39656 #include "tty.h"
39657 #include "network.h"
39658 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39659 mutex_unlock(&tty->ipw_tty_mutex);
39660 return -ENODEV;
39661 }
39662 - if (tty->port.count == 0)
39663 + if (atomic_read(&tty->port.count) == 0)
39664 tty->tx_bytes_queued = 0;
39665
39666 - tty->port.count++;
39667 + atomic_inc(&tty->port.count);
39668
39669 tty->port.tty = linux_tty;
39670 linux_tty->driver_data = tty;
39671 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39672
39673 static void do_ipw_close(struct ipw_tty *tty)
39674 {
39675 - tty->port.count--;
39676 -
39677 - if (tty->port.count == 0) {
39678 + if (atomic_dec_return(&tty->port.count) == 0) {
39679 struct tty_struct *linux_tty = tty->port.tty;
39680
39681 if (linux_tty != NULL) {
39682 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39683 return;
39684
39685 mutex_lock(&tty->ipw_tty_mutex);
39686 - if (tty->port.count == 0) {
39687 + if (atomic_read(&tty->port.count) == 0) {
39688 mutex_unlock(&tty->ipw_tty_mutex);
39689 return;
39690 }
39691 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39692 return;
39693 }
39694
39695 - if (!tty->port.count) {
39696 + if (!atomic_read(&tty->port.count)) {
39697 mutex_unlock(&tty->ipw_tty_mutex);
39698 return;
39699 }
39700 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39701 return -ENODEV;
39702
39703 mutex_lock(&tty->ipw_tty_mutex);
39704 - if (!tty->port.count) {
39705 + if (!atomic_read(&tty->port.count)) {
39706 mutex_unlock(&tty->ipw_tty_mutex);
39707 return -EINVAL;
39708 }
39709 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39710 if (!tty)
39711 return -ENODEV;
39712
39713 - if (!tty->port.count)
39714 + if (!atomic_read(&tty->port.count))
39715 return -EINVAL;
39716
39717 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39718 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39719 if (!tty)
39720 return 0;
39721
39722 - if (!tty->port.count)
39723 + if (!atomic_read(&tty->port.count))
39724 return 0;
39725
39726 return tty->tx_bytes_queued;
39727 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39728 if (!tty)
39729 return -ENODEV;
39730
39731 - if (!tty->port.count)
39732 + if (!atomic_read(&tty->port.count))
39733 return -EINVAL;
39734
39735 return get_control_lines(tty);
39736 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39737 if (!tty)
39738 return -ENODEV;
39739
39740 - if (!tty->port.count)
39741 + if (!atomic_read(&tty->port.count))
39742 return -EINVAL;
39743
39744 return set_control_lines(tty, set, clear);
39745 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39746 if (!tty)
39747 return -ENODEV;
39748
39749 - if (!tty->port.count)
39750 + if (!atomic_read(&tty->port.count))
39751 return -EINVAL;
39752
39753 /* FIXME: Exactly how is the tty object locked here .. */
39754 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39755 * are gone */
39756 mutex_lock(&ttyj->ipw_tty_mutex);
39757 }
39758 - while (ttyj->port.count)
39759 + while (atomic_read(&ttyj->port.count))
39760 do_ipw_close(ttyj);
39761 ipwireless_disassociate_network_ttys(network,
39762 ttyj->channel_idx);
39763 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39764 index 56e616b..9d9f10a 100644
39765 --- a/drivers/tty/moxa.c
39766 +++ b/drivers/tty/moxa.c
39767 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39768 }
39769
39770 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39771 - ch->port.count++;
39772 + atomic_inc(&ch->port.count);
39773 tty->driver_data = ch;
39774 tty_port_tty_set(&ch->port, tty);
39775 mutex_lock(&ch->port.mutex);
39776 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39777 index 1e8e8ce..a9efc93 100644
39778 --- a/drivers/tty/n_gsm.c
39779 +++ b/drivers/tty/n_gsm.c
39780 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39781 kref_init(&dlci->ref);
39782 mutex_init(&dlci->mutex);
39783 dlci->fifo = &dlci->_fifo;
39784 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39785 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39786 kfree(dlci);
39787 return NULL;
39788 }
39789 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39790 struct gsm_dlci *dlci = tty->driver_data;
39791 struct tty_port *port = &dlci->port;
39792
39793 - port->count++;
39794 + atomic_inc(&port->count);
39795 dlci_get(dlci);
39796 dlci_get(dlci->gsm->dlci[0]);
39797 mux_get(dlci->gsm);
39798 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39799 index 8c0b7b4..e88f052 100644
39800 --- a/drivers/tty/n_tty.c
39801 +++ b/drivers/tty/n_tty.c
39802 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39803 {
39804 *ops = tty_ldisc_N_TTY;
39805 ops->owner = NULL;
39806 - ops->refcount = ops->flags = 0;
39807 + atomic_set(&ops->refcount, 0);
39808 + ops->flags = 0;
39809 }
39810 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39811 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39812 index 8cf8d0a..4ef9ed0 100644
39813 --- a/drivers/tty/pty.c
39814 +++ b/drivers/tty/pty.c
39815 @@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39816 panic("Couldn't register Unix98 pts driver");
39817
39818 /* Now create the /dev/ptmx special device */
39819 + pax_open_kernel();
39820 tty_default_fops(&ptmx_fops);
39821 - ptmx_fops.open = ptmx_open;
39822 + *(void **)&ptmx_fops.open = ptmx_open;
39823 + pax_close_kernel();
39824
39825 cdev_init(&ptmx_cdev, &ptmx_fops);
39826 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39827 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39828 index 9700d34..df7520c 100644
39829 --- a/drivers/tty/rocket.c
39830 +++ b/drivers/tty/rocket.c
39831 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39832 tty->driver_data = info;
39833 tty_port_tty_set(port, tty);
39834
39835 - if (port->count++ == 0) {
39836 + if (atomic_inc_return(&port->count) == 1) {
39837 atomic_inc(&rp_num_ports_open);
39838
39839 #ifdef ROCKET_DEBUG_OPEN
39840 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39841 #endif
39842 }
39843 #ifdef ROCKET_DEBUG_OPEN
39844 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
39845 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
39846 #endif
39847
39848 /*
39849 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
39850 spin_unlock_irqrestore(&info->port.lock, flags);
39851 return;
39852 }
39853 - if (info->port.count)
39854 + if (atomic_read(&info->port.count))
39855 atomic_dec(&rp_num_ports_open);
39856 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
39857 spin_unlock_irqrestore(&info->port.lock, flags);
39858 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39859 index 1002054..dd644a8 100644
39860 --- a/drivers/tty/serial/kgdboc.c
39861 +++ b/drivers/tty/serial/kgdboc.c
39862 @@ -24,8 +24,9 @@
39863 #define MAX_CONFIG_LEN 40
39864
39865 static struct kgdb_io kgdboc_io_ops;
39866 +static struct kgdb_io kgdboc_io_ops_console;
39867
39868 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39869 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39870 static int configured = -1;
39871
39872 static char config[MAX_CONFIG_LEN];
39873 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
39874 kgdboc_unregister_kbd();
39875 if (configured == 1)
39876 kgdb_unregister_io_module(&kgdboc_io_ops);
39877 + else if (configured == 2)
39878 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
39879 }
39880
39881 static int configure_kgdboc(void)
39882 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
39883 int err;
39884 char *cptr = config;
39885 struct console *cons;
39886 + int is_console = 0;
39887
39888 err = kgdboc_option_setup(config);
39889 if (err || !strlen(config) || isspace(config[0]))
39890 goto noconfig;
39891
39892 err = -ENODEV;
39893 - kgdboc_io_ops.is_console = 0;
39894 kgdb_tty_driver = NULL;
39895
39896 kgdboc_use_kms = 0;
39897 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
39898 int idx;
39899 if (cons->device && cons->device(cons, &idx) == p &&
39900 idx == tty_line) {
39901 - kgdboc_io_ops.is_console = 1;
39902 + is_console = 1;
39903 break;
39904 }
39905 cons = cons->next;
39906 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
39907 kgdb_tty_line = tty_line;
39908
39909 do_register:
39910 - err = kgdb_register_io_module(&kgdboc_io_ops);
39911 + if (is_console) {
39912 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
39913 + configured = 2;
39914 + } else {
39915 + err = kgdb_register_io_module(&kgdboc_io_ops);
39916 + configured = 1;
39917 + }
39918 if (err)
39919 goto noconfig;
39920
39921 @@ -205,8 +214,6 @@ do_register:
39922 if (err)
39923 goto nmi_con_failed;
39924
39925 - configured = 1;
39926 -
39927 return 0;
39928
39929 nmi_con_failed:
39930 @@ -223,7 +230,7 @@ noconfig:
39931 static int __init init_kgdboc(void)
39932 {
39933 /* Already configured? */
39934 - if (configured == 1)
39935 + if (configured >= 1)
39936 return 0;
39937
39938 return configure_kgdboc();
39939 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39940 if (config[len - 1] == '\n')
39941 config[len - 1] = '\0';
39942
39943 - if (configured == 1)
39944 + if (configured >= 1)
39945 cleanup_kgdboc();
39946
39947 /* Go and configure with the new params. */
39948 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
39949 .post_exception = kgdboc_post_exp_handler,
39950 };
39951
39952 +static struct kgdb_io kgdboc_io_ops_console = {
39953 + .name = "kgdboc",
39954 + .read_char = kgdboc_get_char,
39955 + .write_char = kgdboc_put_char,
39956 + .pre_exception = kgdboc_pre_exp_handler,
39957 + .post_exception = kgdboc_post_exp_handler,
39958 + .is_console = 1
39959 +};
39960 +
39961 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39962 /* This is only available if kgdboc is a built in for early debugging */
39963 static int __init kgdboc_early_init(char *opt)
39964 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
39965 index 7f04717..0f3794f 100644
39966 --- a/drivers/tty/serial/samsung.c
39967 +++ b/drivers/tty/serial/samsung.c
39968 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
39969 }
39970 }
39971
39972 +static int s3c64xx_serial_startup(struct uart_port *port);
39973 static int s3c24xx_serial_startup(struct uart_port *port)
39974 {
39975 struct s3c24xx_uart_port *ourport = to_ourport(port);
39976 int ret;
39977
39978 + /* Startup sequence is different for s3c64xx and higher SoC's */
39979 + if (s3c24xx_serial_has_interrupt_mask(port))
39980 + return s3c64xx_serial_startup(port);
39981 +
39982 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
39983 port->mapbase, port->membase);
39984
39985 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
39986 /* setup info for port */
39987 port->dev = &platdev->dev;
39988
39989 - /* Startup sequence is different for s3c64xx and higher SoC's */
39990 - if (s3c24xx_serial_has_interrupt_mask(port))
39991 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
39992 -
39993 port->uartclk = 1;
39994
39995 if (cfg->uart_flags & UPF_CONS_FLOW) {
39996 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
39997 index 0fcfd98..8244fce 100644
39998 --- a/drivers/tty/serial/serial_core.c
39999 +++ b/drivers/tty/serial/serial_core.c
40000 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
40001 uart_flush_buffer(tty);
40002 uart_shutdown(tty, state);
40003 spin_lock_irqsave(&port->lock, flags);
40004 - port->count = 0;
40005 + atomic_set(&port->count, 0);
40006 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40007 spin_unlock_irqrestore(&port->lock, flags);
40008 tty_port_tty_set(port, NULL);
40009 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40010 goto end;
40011 }
40012
40013 - port->count++;
40014 + atomic_inc(&port->count);
40015 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40016 retval = -ENXIO;
40017 goto err_dec_count;
40018 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40019 /*
40020 * Make sure the device is in D0 state.
40021 */
40022 - if (port->count == 1)
40023 + if (atomic_read(&port->count) == 1)
40024 uart_change_pm(state, 0);
40025
40026 /*
40027 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40028 end:
40029 return retval;
40030 err_dec_count:
40031 - port->count--;
40032 + atomic_inc(&port->count);
40033 mutex_unlock(&port->mutex);
40034 goto end;
40035 }
40036 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40037 index 70e3a52..5742052 100644
40038 --- a/drivers/tty/synclink.c
40039 +++ b/drivers/tty/synclink.c
40040 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40041
40042 if (debug_level >= DEBUG_LEVEL_INFO)
40043 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40044 - __FILE__,__LINE__, info->device_name, info->port.count);
40045 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40046
40047 if (tty_port_close_start(&info->port, tty, filp) == 0)
40048 goto cleanup;
40049 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40050 cleanup:
40051 if (debug_level >= DEBUG_LEVEL_INFO)
40052 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40053 - tty->driver->name, info->port.count);
40054 + tty->driver->name, atomic_read(&info->port.count));
40055
40056 } /* end of mgsl_close() */
40057
40058 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40059
40060 mgsl_flush_buffer(tty);
40061 shutdown(info);
40062 -
40063 - info->port.count = 0;
40064 +
40065 + atomic_set(&info->port.count, 0);
40066 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40067 info->port.tty = NULL;
40068
40069 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40070
40071 if (debug_level >= DEBUG_LEVEL_INFO)
40072 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40073 - __FILE__,__LINE__, tty->driver->name, port->count );
40074 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40075
40076 spin_lock_irqsave(&info->irq_spinlock, flags);
40077 if (!tty_hung_up_p(filp)) {
40078 extra_count = true;
40079 - port->count--;
40080 + atomic_dec(&port->count);
40081 }
40082 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40083 port->blocked_open++;
40084 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40085
40086 if (debug_level >= DEBUG_LEVEL_INFO)
40087 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40088 - __FILE__,__LINE__, tty->driver->name, port->count );
40089 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40090
40091 tty_unlock(tty);
40092 schedule();
40093 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40094
40095 /* FIXME: Racy on hangup during close wait */
40096 if (extra_count)
40097 - port->count++;
40098 + atomic_inc(&port->count);
40099 port->blocked_open--;
40100
40101 if (debug_level >= DEBUG_LEVEL_INFO)
40102 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40103 - __FILE__,__LINE__, tty->driver->name, port->count );
40104 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40105
40106 if (!retval)
40107 port->flags |= ASYNC_NORMAL_ACTIVE;
40108 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40109
40110 if (debug_level >= DEBUG_LEVEL_INFO)
40111 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40112 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40113 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40114
40115 /* If port is closing, signal caller to try again */
40116 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40117 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40118 spin_unlock_irqrestore(&info->netlock, flags);
40119 goto cleanup;
40120 }
40121 - info->port.count++;
40122 + atomic_inc(&info->port.count);
40123 spin_unlock_irqrestore(&info->netlock, flags);
40124
40125 - if (info->port.count == 1) {
40126 + if (atomic_read(&info->port.count) == 1) {
40127 /* 1st open on this device, init hardware */
40128 retval = startup(info);
40129 if (retval < 0)
40130 @@ -3451,8 +3451,8 @@ cleanup:
40131 if (retval) {
40132 if (tty->count == 1)
40133 info->port.tty = NULL; /* tty layer will release tty struct */
40134 - if(info->port.count)
40135 - info->port.count--;
40136 + if (atomic_read(&info->port.count))
40137 + atomic_dec(&info->port.count);
40138 }
40139
40140 return retval;
40141 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40142 unsigned short new_crctype;
40143
40144 /* return error if TTY interface open */
40145 - if (info->port.count)
40146 + if (atomic_read(&info->port.count))
40147 return -EBUSY;
40148
40149 switch (encoding)
40150 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40151
40152 /* arbitrate between network and tty opens */
40153 spin_lock_irqsave(&info->netlock, flags);
40154 - if (info->port.count != 0 || info->netcount != 0) {
40155 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40156 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40157 spin_unlock_irqrestore(&info->netlock, flags);
40158 return -EBUSY;
40159 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40160 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40161
40162 /* return error if TTY interface open */
40163 - if (info->port.count)
40164 + if (atomic_read(&info->port.count))
40165 return -EBUSY;
40166
40167 if (cmd != SIOCWANDEV)
40168 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40169 index b38e954..ce45b38 100644
40170 --- a/drivers/tty/synclink_gt.c
40171 +++ b/drivers/tty/synclink_gt.c
40172 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40173 tty->driver_data = info;
40174 info->port.tty = tty;
40175
40176 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40177 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40178
40179 /* If port is closing, signal caller to try again */
40180 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40181 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40182 mutex_unlock(&info->port.mutex);
40183 goto cleanup;
40184 }
40185 - info->port.count++;
40186 + atomic_inc(&info->port.count);
40187 spin_unlock_irqrestore(&info->netlock, flags);
40188
40189 - if (info->port.count == 1) {
40190 + if (atomic_read(&info->port.count) == 1) {
40191 /* 1st open on this device, init hardware */
40192 retval = startup(info);
40193 if (retval < 0) {
40194 @@ -716,8 +716,8 @@ cleanup:
40195 if (retval) {
40196 if (tty->count == 1)
40197 info->port.tty = NULL; /* tty layer will release tty struct */
40198 - if(info->port.count)
40199 - info->port.count--;
40200 + if(atomic_read(&info->port.count))
40201 + atomic_dec(&info->port.count);
40202 }
40203
40204 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40205 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40206
40207 if (sanity_check(info, tty->name, "close"))
40208 return;
40209 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40210 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40211
40212 if (tty_port_close_start(&info->port, tty, filp) == 0)
40213 goto cleanup;
40214 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40215 tty_port_close_end(&info->port, tty);
40216 info->port.tty = NULL;
40217 cleanup:
40218 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40219 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40220 }
40221
40222 static void hangup(struct tty_struct *tty)
40223 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40224 shutdown(info);
40225
40226 spin_lock_irqsave(&info->port.lock, flags);
40227 - info->port.count = 0;
40228 + atomic_set(&info->port.count, 0);
40229 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40230 info->port.tty = NULL;
40231 spin_unlock_irqrestore(&info->port.lock, flags);
40232 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40233 unsigned short new_crctype;
40234
40235 /* return error if TTY interface open */
40236 - if (info->port.count)
40237 + if (atomic_read(&info->port.count))
40238 return -EBUSY;
40239
40240 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40241 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40242
40243 /* arbitrate between network and tty opens */
40244 spin_lock_irqsave(&info->netlock, flags);
40245 - if (info->port.count != 0 || info->netcount != 0) {
40246 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40247 DBGINFO(("%s hdlc_open busy\n", dev->name));
40248 spin_unlock_irqrestore(&info->netlock, flags);
40249 return -EBUSY;
40250 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40251 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40252
40253 /* return error if TTY interface open */
40254 - if (info->port.count)
40255 + if (atomic_read(&info->port.count))
40256 return -EBUSY;
40257
40258 if (cmd != SIOCWANDEV)
40259 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40260 if (port == NULL)
40261 continue;
40262 spin_lock(&port->lock);
40263 - if ((port->port.count || port->netcount) &&
40264 + if ((atomic_read(&port->port.count) || port->netcount) &&
40265 port->pending_bh && !port->bh_running &&
40266 !port->bh_requested) {
40267 DBGISR(("%s bh queued\n", port->device_name));
40268 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40269 spin_lock_irqsave(&info->lock, flags);
40270 if (!tty_hung_up_p(filp)) {
40271 extra_count = true;
40272 - port->count--;
40273 + atomic_dec(&port->count);
40274 }
40275 spin_unlock_irqrestore(&info->lock, flags);
40276 port->blocked_open++;
40277 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40278 remove_wait_queue(&port->open_wait, &wait);
40279
40280 if (extra_count)
40281 - port->count++;
40282 + atomic_inc(&port->count);
40283 port->blocked_open--;
40284
40285 if (!retval)
40286 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40287 index f17d9f3..27a041b 100644
40288 --- a/drivers/tty/synclinkmp.c
40289 +++ b/drivers/tty/synclinkmp.c
40290 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40291
40292 if (debug_level >= DEBUG_LEVEL_INFO)
40293 printk("%s(%d):%s open(), old ref count = %d\n",
40294 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40295 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40296
40297 /* If port is closing, signal caller to try again */
40298 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40299 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40300 spin_unlock_irqrestore(&info->netlock, flags);
40301 goto cleanup;
40302 }
40303 - info->port.count++;
40304 + atomic_inc(&info->port.count);
40305 spin_unlock_irqrestore(&info->netlock, flags);
40306
40307 - if (info->port.count == 1) {
40308 + if (atomic_read(&info->port.count) == 1) {
40309 /* 1st open on this device, init hardware */
40310 retval = startup(info);
40311 if (retval < 0)
40312 @@ -797,8 +797,8 @@ cleanup:
40313 if (retval) {
40314 if (tty->count == 1)
40315 info->port.tty = NULL; /* tty layer will release tty struct */
40316 - if(info->port.count)
40317 - info->port.count--;
40318 + if(atomic_read(&info->port.count))
40319 + atomic_dec(&info->port.count);
40320 }
40321
40322 return retval;
40323 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40324
40325 if (debug_level >= DEBUG_LEVEL_INFO)
40326 printk("%s(%d):%s close() entry, count=%d\n",
40327 - __FILE__,__LINE__, info->device_name, info->port.count);
40328 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40329
40330 if (tty_port_close_start(&info->port, tty, filp) == 0)
40331 goto cleanup;
40332 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40333 cleanup:
40334 if (debug_level >= DEBUG_LEVEL_INFO)
40335 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40336 - tty->driver->name, info->port.count);
40337 + tty->driver->name, atomic_read(&info->port.count));
40338 }
40339
40340 /* Called by tty_hangup() when a hangup is signaled.
40341 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40342 shutdown(info);
40343
40344 spin_lock_irqsave(&info->port.lock, flags);
40345 - info->port.count = 0;
40346 + atomic_set(&info->port.count, 0);
40347 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40348 info->port.tty = NULL;
40349 spin_unlock_irqrestore(&info->port.lock, flags);
40350 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40351 unsigned short new_crctype;
40352
40353 /* return error if TTY interface open */
40354 - if (info->port.count)
40355 + if (atomic_read(&info->port.count))
40356 return -EBUSY;
40357
40358 switch (encoding)
40359 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40360
40361 /* arbitrate between network and tty opens */
40362 spin_lock_irqsave(&info->netlock, flags);
40363 - if (info->port.count != 0 || info->netcount != 0) {
40364 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40365 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40366 spin_unlock_irqrestore(&info->netlock, flags);
40367 return -EBUSY;
40368 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40369 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40370
40371 /* return error if TTY interface open */
40372 - if (info->port.count)
40373 + if (atomic_read(&info->port.count))
40374 return -EBUSY;
40375
40376 if (cmd != SIOCWANDEV)
40377 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40378 * do not request bottom half processing if the
40379 * device is not open in a normal mode.
40380 */
40381 - if ( port && (port->port.count || port->netcount) &&
40382 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40383 port->pending_bh && !port->bh_running &&
40384 !port->bh_requested ) {
40385 if ( debug_level >= DEBUG_LEVEL_ISR )
40386 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40387
40388 if (debug_level >= DEBUG_LEVEL_INFO)
40389 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40390 - __FILE__,__LINE__, tty->driver->name, port->count );
40391 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40392
40393 spin_lock_irqsave(&info->lock, flags);
40394 if (!tty_hung_up_p(filp)) {
40395 extra_count = true;
40396 - port->count--;
40397 + atomic_dec(&port->count);
40398 }
40399 spin_unlock_irqrestore(&info->lock, flags);
40400 port->blocked_open++;
40401 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40402
40403 if (debug_level >= DEBUG_LEVEL_INFO)
40404 printk("%s(%d):%s block_til_ready() count=%d\n",
40405 - __FILE__,__LINE__, tty->driver->name, port->count );
40406 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40407
40408 tty_unlock(tty);
40409 schedule();
40410 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40411 remove_wait_queue(&port->open_wait, &wait);
40412
40413 if (extra_count)
40414 - port->count++;
40415 + atomic_inc(&port->count);
40416 port->blocked_open--;
40417
40418 if (debug_level >= DEBUG_LEVEL_INFO)
40419 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40420 - __FILE__,__LINE__, tty->driver->name, port->count );
40421 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40422
40423 if (!retval)
40424 port->flags |= ASYNC_NORMAL_ACTIVE;
40425 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40426 index 16ee6ce..bfcac57 100644
40427 --- a/drivers/tty/sysrq.c
40428 +++ b/drivers/tty/sysrq.c
40429 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40430 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40431 size_t count, loff_t *ppos)
40432 {
40433 - if (count) {
40434 + if (count && capable(CAP_SYS_ADMIN)) {
40435 char c;
40436
40437 if (get_user(c, buf))
40438 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40439 index 2ea176b..2877bc8 100644
40440 --- a/drivers/tty/tty_io.c
40441 +++ b/drivers/tty/tty_io.c
40442 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40443
40444 void tty_default_fops(struct file_operations *fops)
40445 {
40446 - *fops = tty_fops;
40447 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40448 }
40449
40450 /*
40451 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40452 index 0f2a2c5..471e228 100644
40453 --- a/drivers/tty/tty_ldisc.c
40454 +++ b/drivers/tty/tty_ldisc.c
40455 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40456 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40457 struct tty_ldisc_ops *ldo = ld->ops;
40458
40459 - ldo->refcount--;
40460 + atomic_dec(&ldo->refcount);
40461 module_put(ldo->owner);
40462 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40463
40464 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40465 spin_lock_irqsave(&tty_ldisc_lock, flags);
40466 tty_ldiscs[disc] = new_ldisc;
40467 new_ldisc->num = disc;
40468 - new_ldisc->refcount = 0;
40469 + atomic_set(&new_ldisc->refcount, 0);
40470 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40471
40472 return ret;
40473 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40474 return -EINVAL;
40475
40476 spin_lock_irqsave(&tty_ldisc_lock, flags);
40477 - if (tty_ldiscs[disc]->refcount)
40478 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40479 ret = -EBUSY;
40480 else
40481 tty_ldiscs[disc] = NULL;
40482 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40483 if (ldops) {
40484 ret = ERR_PTR(-EAGAIN);
40485 if (try_module_get(ldops->owner)) {
40486 - ldops->refcount++;
40487 + atomic_inc(&ldops->refcount);
40488 ret = ldops;
40489 }
40490 }
40491 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40492 unsigned long flags;
40493
40494 spin_lock_irqsave(&tty_ldisc_lock, flags);
40495 - ldops->refcount--;
40496 + atomic_dec(&ldops->refcount);
40497 module_put(ldops->owner);
40498 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40499 }
40500 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40501 index d7bdd8d..feaef30 100644
40502 --- a/drivers/tty/tty_port.c
40503 +++ b/drivers/tty/tty_port.c
40504 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40505 unsigned long flags;
40506
40507 spin_lock_irqsave(&port->lock, flags);
40508 - port->count = 0;
40509 + atomic_set(&port->count, 0);
40510 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40511 if (port->tty) {
40512 set_bit(TTY_IO_ERROR, &port->tty->flags);
40513 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40514 /* The port lock protects the port counts */
40515 spin_lock_irqsave(&port->lock, flags);
40516 if (!tty_hung_up_p(filp))
40517 - port->count--;
40518 + atomic_dec(&port->count);
40519 port->blocked_open++;
40520 spin_unlock_irqrestore(&port->lock, flags);
40521
40522 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40523 we must not mess that up further */
40524 spin_lock_irqsave(&port->lock, flags);
40525 if (!tty_hung_up_p(filp))
40526 - port->count++;
40527 + atomic_inc(&port->count);
40528 port->blocked_open--;
40529 if (retval == 0)
40530 port->flags |= ASYNC_NORMAL_ACTIVE;
40531 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40532 return 0;
40533 }
40534
40535 - if (tty->count == 1 && port->count != 1) {
40536 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40537 printk(KERN_WARNING
40538 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40539 - port->count);
40540 - port->count = 1;
40541 + atomic_read(&port->count));
40542 + atomic_set(&port->count, 1);
40543 }
40544 - if (--port->count < 0) {
40545 + if (atomic_dec_return(&port->count) < 0) {
40546 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40547 - port->count);
40548 - port->count = 0;
40549 + atomic_read(&port->count));
40550 + atomic_set(&port->count, 0);
40551 }
40552
40553 - if (port->count) {
40554 + if (atomic_read(&port->count)) {
40555 spin_unlock_irqrestore(&port->lock, flags);
40556 if (port->ops->drop)
40557 port->ops->drop(port);
40558 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40559 {
40560 spin_lock_irq(&port->lock);
40561 if (!tty_hung_up_p(filp))
40562 - ++port->count;
40563 + atomic_inc(&port->count);
40564 spin_unlock_irq(&port->lock);
40565 tty_port_tty_set(port, tty);
40566
40567 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40568 index 681765b..d3ccdf2 100644
40569 --- a/drivers/tty/vt/keyboard.c
40570 +++ b/drivers/tty/vt/keyboard.c
40571 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40572 kbd->kbdmode == VC_OFF) &&
40573 value != KVAL(K_SAK))
40574 return; /* SAK is allowed even in raw mode */
40575 +
40576 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40577 + {
40578 + void *func = fn_handler[value];
40579 + if (func == fn_show_state || func == fn_show_ptregs ||
40580 + func == fn_show_mem)
40581 + return;
40582 + }
40583 +#endif
40584 +
40585 fn_handler[value](vc);
40586 }
40587
40588 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40589 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40590 return -EFAULT;
40591
40592 - if (!capable(CAP_SYS_TTY_CONFIG))
40593 - perm = 0;
40594 -
40595 switch (cmd) {
40596 case KDGKBENT:
40597 /* Ensure another thread doesn't free it under us */
40598 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40599 spin_unlock_irqrestore(&kbd_event_lock, flags);
40600 return put_user(val, &user_kbe->kb_value);
40601 case KDSKBENT:
40602 + if (!capable(CAP_SYS_TTY_CONFIG))
40603 + perm = 0;
40604 +
40605 if (!perm)
40606 return -EPERM;
40607 if (!i && v == K_NOSUCHMAP) {
40608 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40609 int i, j, k;
40610 int ret;
40611
40612 - if (!capable(CAP_SYS_TTY_CONFIG))
40613 - perm = 0;
40614 -
40615 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40616 if (!kbs) {
40617 ret = -ENOMEM;
40618 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40619 kfree(kbs);
40620 return ((p && *p) ? -EOVERFLOW : 0);
40621 case KDSKBSENT:
40622 + if (!capable(CAP_SYS_TTY_CONFIG))
40623 + perm = 0;
40624 +
40625 if (!perm) {
40626 ret = -EPERM;
40627 goto reterr;
40628 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40629 index 5110f36..8dc0a74 100644
40630 --- a/drivers/uio/uio.c
40631 +++ b/drivers/uio/uio.c
40632 @@ -25,6 +25,7 @@
40633 #include <linux/kobject.h>
40634 #include <linux/cdev.h>
40635 #include <linux/uio_driver.h>
40636 +#include <asm/local.h>
40637
40638 #define UIO_MAX_DEVICES (1U << MINORBITS)
40639
40640 @@ -32,10 +33,10 @@ struct uio_device {
40641 struct module *owner;
40642 struct device *dev;
40643 int minor;
40644 - atomic_t event;
40645 + atomic_unchecked_t event;
40646 struct fasync_struct *async_queue;
40647 wait_queue_head_t wait;
40648 - int vma_count;
40649 + local_t vma_count;
40650 struct uio_info *info;
40651 struct kobject *map_dir;
40652 struct kobject *portio_dir;
40653 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40654 struct device_attribute *attr, char *buf)
40655 {
40656 struct uio_device *idev = dev_get_drvdata(dev);
40657 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40658 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40659 }
40660
40661 static struct device_attribute uio_class_attributes[] = {
40662 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40663 {
40664 struct uio_device *idev = info->uio_dev;
40665
40666 - atomic_inc(&idev->event);
40667 + atomic_inc_unchecked(&idev->event);
40668 wake_up_interruptible(&idev->wait);
40669 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40670 }
40671 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40672 }
40673
40674 listener->dev = idev;
40675 - listener->event_count = atomic_read(&idev->event);
40676 + listener->event_count = atomic_read_unchecked(&idev->event);
40677 filep->private_data = listener;
40678
40679 if (idev->info->open) {
40680 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40681 return -EIO;
40682
40683 poll_wait(filep, &idev->wait, wait);
40684 - if (listener->event_count != atomic_read(&idev->event))
40685 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40686 return POLLIN | POLLRDNORM;
40687 return 0;
40688 }
40689 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40690 do {
40691 set_current_state(TASK_INTERRUPTIBLE);
40692
40693 - event_count = atomic_read(&idev->event);
40694 + event_count = atomic_read_unchecked(&idev->event);
40695 if (event_count != listener->event_count) {
40696 if (copy_to_user(buf, &event_count, count))
40697 retval = -EFAULT;
40698 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40699 static void uio_vma_open(struct vm_area_struct *vma)
40700 {
40701 struct uio_device *idev = vma->vm_private_data;
40702 - idev->vma_count++;
40703 + local_inc(&idev->vma_count);
40704 }
40705
40706 static void uio_vma_close(struct vm_area_struct *vma)
40707 {
40708 struct uio_device *idev = vma->vm_private_data;
40709 - idev->vma_count--;
40710 + local_dec(&idev->vma_count);
40711 }
40712
40713 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40714 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40715 idev->owner = owner;
40716 idev->info = info;
40717 init_waitqueue_head(&idev->wait);
40718 - atomic_set(&idev->event, 0);
40719 + atomic_set_unchecked(&idev->event, 0);
40720
40721 ret = uio_get_minor(idev);
40722 if (ret)
40723 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40724 index b7eb86a..36d28af 100644
40725 --- a/drivers/usb/atm/cxacru.c
40726 +++ b/drivers/usb/atm/cxacru.c
40727 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40728 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40729 if (ret < 2)
40730 return -EINVAL;
40731 - if (index < 0 || index > 0x7f)
40732 + if (index > 0x7f)
40733 return -EINVAL;
40734 pos += tmp;
40735
40736 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40737 index 35f10bf..6a38a0b 100644
40738 --- a/drivers/usb/atm/usbatm.c
40739 +++ b/drivers/usb/atm/usbatm.c
40740 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40741 if (printk_ratelimit())
40742 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40743 __func__, vpi, vci);
40744 - atomic_inc(&vcc->stats->rx_err);
40745 + atomic_inc_unchecked(&vcc->stats->rx_err);
40746 return;
40747 }
40748
40749 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40750 if (length > ATM_MAX_AAL5_PDU) {
40751 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40752 __func__, length, vcc);
40753 - atomic_inc(&vcc->stats->rx_err);
40754 + atomic_inc_unchecked(&vcc->stats->rx_err);
40755 goto out;
40756 }
40757
40758 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40759 if (sarb->len < pdu_length) {
40760 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40761 __func__, pdu_length, sarb->len, vcc);
40762 - atomic_inc(&vcc->stats->rx_err);
40763 + atomic_inc_unchecked(&vcc->stats->rx_err);
40764 goto out;
40765 }
40766
40767 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40768 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40769 __func__, vcc);
40770 - atomic_inc(&vcc->stats->rx_err);
40771 + atomic_inc_unchecked(&vcc->stats->rx_err);
40772 goto out;
40773 }
40774
40775 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40776 if (printk_ratelimit())
40777 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40778 __func__, length);
40779 - atomic_inc(&vcc->stats->rx_drop);
40780 + atomic_inc_unchecked(&vcc->stats->rx_drop);
40781 goto out;
40782 }
40783
40784 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40785
40786 vcc->push(vcc, skb);
40787
40788 - atomic_inc(&vcc->stats->rx);
40789 + atomic_inc_unchecked(&vcc->stats->rx);
40790 out:
40791 skb_trim(sarb, 0);
40792 }
40793 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40794 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40795
40796 usbatm_pop(vcc, skb);
40797 - atomic_inc(&vcc->stats->tx);
40798 + atomic_inc_unchecked(&vcc->stats->tx);
40799
40800 skb = skb_dequeue(&instance->sndqueue);
40801 }
40802 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40803 if (!left--)
40804 return sprintf(page,
40805 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40806 - atomic_read(&atm_dev->stats.aal5.tx),
40807 - atomic_read(&atm_dev->stats.aal5.tx_err),
40808 - atomic_read(&atm_dev->stats.aal5.rx),
40809 - atomic_read(&atm_dev->stats.aal5.rx_err),
40810 - atomic_read(&atm_dev->stats.aal5.rx_drop));
40811 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40812 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40813 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40814 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40815 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40816
40817 if (!left--) {
40818 if (instance->disconnected)
40819 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40820 index f460de3..95ba1f6 100644
40821 --- a/drivers/usb/core/devices.c
40822 +++ b/drivers/usb/core/devices.c
40823 @@ -126,7 +126,7 @@ static const char format_endpt[] =
40824 * time it gets called.
40825 */
40826 static struct device_connect_event {
40827 - atomic_t count;
40828 + atomic_unchecked_t count;
40829 wait_queue_head_t wait;
40830 } device_event = {
40831 .count = ATOMIC_INIT(1),
40832 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40833
40834 void usbfs_conn_disc_event(void)
40835 {
40836 - atomic_add(2, &device_event.count);
40837 + atomic_add_unchecked(2, &device_event.count);
40838 wake_up(&device_event.wait);
40839 }
40840
40841 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
40842
40843 poll_wait(file, &device_event.wait, wait);
40844
40845 - event_count = atomic_read(&device_event.count);
40846 + event_count = atomic_read_unchecked(&device_event.count);
40847 if (file->f_version != event_count) {
40848 file->f_version = event_count;
40849 return POLLIN | POLLRDNORM;
40850 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
40851 index f034716..aed0368 100644
40852 --- a/drivers/usb/core/hcd.c
40853 +++ b/drivers/usb/core/hcd.c
40854 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40855 */
40856 usb_get_urb(urb);
40857 atomic_inc(&urb->use_count);
40858 - atomic_inc(&urb->dev->urbnum);
40859 + atomic_inc_unchecked(&urb->dev->urbnum);
40860 usbmon_urb_submit(&hcd->self, urb);
40861
40862 /* NOTE requirements on root-hub callers (usbfs and the hub
40863 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40864 urb->hcpriv = NULL;
40865 INIT_LIST_HEAD(&urb->urb_list);
40866 atomic_dec(&urb->use_count);
40867 - atomic_dec(&urb->dev->urbnum);
40868 + atomic_dec_unchecked(&urb->dev->urbnum);
40869 if (atomic_read(&urb->reject))
40870 wake_up(&usb_kill_urb_queue);
40871 usb_put_urb(urb);
40872 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
40873 index 818e4a0..0fc9589 100644
40874 --- a/drivers/usb/core/sysfs.c
40875 +++ b/drivers/usb/core/sysfs.c
40876 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
40877 struct usb_device *udev;
40878
40879 udev = to_usb_device(dev);
40880 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
40881 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
40882 }
40883 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
40884
40885 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
40886 index cd8fb44..17fbe0c 100644
40887 --- a/drivers/usb/core/usb.c
40888 +++ b/drivers/usb/core/usb.c
40889 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
40890 set_dev_node(&dev->dev, dev_to_node(bus->controller));
40891 dev->state = USB_STATE_ATTACHED;
40892 dev->lpm_disable_count = 1;
40893 - atomic_set(&dev->urbnum, 0);
40894 + atomic_set_unchecked(&dev->urbnum, 0);
40895
40896 INIT_LIST_HEAD(&dev->ep0.urb_list);
40897 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
40898 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
40899 index 4bfa78a..902bfbd 100644
40900 --- a/drivers/usb/early/ehci-dbgp.c
40901 +++ b/drivers/usb/early/ehci-dbgp.c
40902 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
40903
40904 #ifdef CONFIG_KGDB
40905 static struct kgdb_io kgdbdbgp_io_ops;
40906 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
40907 +static struct kgdb_io kgdbdbgp_io_ops_console;
40908 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
40909 #else
40910 #define dbgp_kgdb_mode (0)
40911 #endif
40912 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
40913 .write_char = kgdbdbgp_write_char,
40914 };
40915
40916 +static struct kgdb_io kgdbdbgp_io_ops_console = {
40917 + .name = "kgdbdbgp",
40918 + .read_char = kgdbdbgp_read_char,
40919 + .write_char = kgdbdbgp_write_char,
40920 + .is_console = 1
40921 +};
40922 +
40923 static int kgdbdbgp_wait_time;
40924
40925 static int __init kgdbdbgp_parse_config(char *str)
40926 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
40927 ptr++;
40928 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
40929 }
40930 - kgdb_register_io_module(&kgdbdbgp_io_ops);
40931 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
40932 + if (early_dbgp_console.index != -1)
40933 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
40934 + else
40935 + kgdb_register_io_module(&kgdbdbgp_io_ops);
40936
40937 return 0;
40938 }
40939 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
40940 index f173952..83d6ec0 100644
40941 --- a/drivers/usb/gadget/u_serial.c
40942 +++ b/drivers/usb/gadget/u_serial.c
40943 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40944 spin_lock_irq(&port->port_lock);
40945
40946 /* already open? Great. */
40947 - if (port->port.count) {
40948 + if (atomic_read(&port->port.count)) {
40949 status = 0;
40950 - port->port.count++;
40951 + atomic_inc(&port->port.count);
40952
40953 /* currently opening/closing? wait ... */
40954 } else if (port->openclose) {
40955 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40956 tty->driver_data = port;
40957 port->port.tty = tty;
40958
40959 - port->port.count = 1;
40960 + atomic_set(&port->port.count, 1);
40961 port->openclose = false;
40962
40963 /* if connected, start the I/O stream */
40964 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40965
40966 spin_lock_irq(&port->port_lock);
40967
40968 - if (port->port.count != 1) {
40969 - if (port->port.count == 0)
40970 + if (atomic_read(&port->port.count) != 1) {
40971 + if (atomic_read(&port->port.count) == 0)
40972 WARN_ON(1);
40973 else
40974 - --port->port.count;
40975 + atomic_dec(&port->port.count);
40976 goto exit;
40977 }
40978
40979 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40980 * and sleep if necessary
40981 */
40982 port->openclose = true;
40983 - port->port.count = 0;
40984 + atomic_set(&port->port.count, 0);
40985
40986 gser = port->port_usb;
40987 if (gser && gser->disconnect)
40988 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
40989 int cond;
40990
40991 spin_lock_irq(&port->port_lock);
40992 - cond = (port->port.count == 0) && !port->openclose;
40993 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
40994 spin_unlock_irq(&port->port_lock);
40995 return cond;
40996 }
40997 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
40998 /* if it's already open, start I/O ... and notify the serial
40999 * protocol about open/close status (connect/disconnect).
41000 */
41001 - if (port->port.count) {
41002 + if (atomic_read(&port->port.count)) {
41003 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41004 gs_start_io(port);
41005 if (gser->connect)
41006 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
41007
41008 port->port_usb = NULL;
41009 gser->ioport = NULL;
41010 - if (port->port.count > 0 || port->openclose) {
41011 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41012 wake_up_interruptible(&port->drain_wait);
41013 if (port->port.tty)
41014 tty_hangup(port->port.tty);
41015 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
41016
41017 /* finally, free any unused/unusable I/O buffers */
41018 spin_lock_irqsave(&port->port_lock, flags);
41019 - if (port->port.count == 0 && !port->openclose)
41020 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41021 gs_buf_free(&port->port_write_buf);
41022 gs_free_requests(gser->out, &port->read_pool, NULL);
41023 gs_free_requests(gser->out, &port->read_queue, NULL);
41024 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41025 index 5f3bcd3..bfca43f 100644
41026 --- a/drivers/usb/serial/console.c
41027 +++ b/drivers/usb/serial/console.c
41028 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41029
41030 info->port = port;
41031
41032 - ++port->port.count;
41033 + atomic_inc(&port->port.count);
41034 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41035 if (serial->type->set_termios) {
41036 /*
41037 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41038 }
41039 /* Now that any required fake tty operations are completed restore
41040 * the tty port count */
41041 - --port->port.count;
41042 + atomic_dec(&port->port.count);
41043 /* The console is special in terms of closing the device so
41044 * indicate this port is now acting as a system console. */
41045 port->port.console = 1;
41046 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41047 free_tty:
41048 kfree(tty);
41049 reset_open_count:
41050 - port->port.count = 0;
41051 + atomic_set(&port->port.count, 0);
41052 usb_autopm_put_interface(serial->interface);
41053 error_get_interface:
41054 usb_serial_put(serial);
41055 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41056 index d6bea3e..60b250e 100644
41057 --- a/drivers/usb/wusbcore/wa-hc.h
41058 +++ b/drivers/usb/wusbcore/wa-hc.h
41059 @@ -192,7 +192,7 @@ struct wahc {
41060 struct list_head xfer_delayed_list;
41061 spinlock_t xfer_list_lock;
41062 struct work_struct xfer_work;
41063 - atomic_t xfer_id_count;
41064 + atomic_unchecked_t xfer_id_count;
41065 };
41066
41067
41068 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41069 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41070 spin_lock_init(&wa->xfer_list_lock);
41071 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41072 - atomic_set(&wa->xfer_id_count, 1);
41073 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41074 }
41075
41076 /**
41077 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41078 index 57c01ab..8a05959 100644
41079 --- a/drivers/usb/wusbcore/wa-xfer.c
41080 +++ b/drivers/usb/wusbcore/wa-xfer.c
41081 @@ -296,7 +296,7 @@ out:
41082 */
41083 static void wa_xfer_id_init(struct wa_xfer *xfer)
41084 {
41085 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41086 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41087 }
41088
41089 /*
41090 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41091 index dedaf81..b0f11ab 100644
41092 --- a/drivers/vhost/vhost.c
41093 +++ b/drivers/vhost/vhost.c
41094 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41095 return 0;
41096 }
41097
41098 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41099 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41100 {
41101 struct file *eventfp, *filep = NULL;
41102 bool pollstart = false, pollstop = false;
41103 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41104 index 0fefa84..7a9d581 100644
41105 --- a/drivers/video/aty/aty128fb.c
41106 +++ b/drivers/video/aty/aty128fb.c
41107 @@ -149,7 +149,7 @@ enum {
41108 };
41109
41110 /* Must match above enum */
41111 -static char * const r128_family[] __devinitconst = {
41112 +static const char * const r128_family[] __devinitconst = {
41113 "AGP",
41114 "PCI",
41115 "PRO AGP",
41116 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41117 index 5c3960d..15cf8fc 100644
41118 --- a/drivers/video/fbcmap.c
41119 +++ b/drivers/video/fbcmap.c
41120 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41121 rc = -ENODEV;
41122 goto out;
41123 }
41124 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41125 - !info->fbops->fb_setcmap)) {
41126 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41127 rc = -EINVAL;
41128 goto out1;
41129 }
41130 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41131 index 3ff0105..7589d98 100644
41132 --- a/drivers/video/fbmem.c
41133 +++ b/drivers/video/fbmem.c
41134 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41135 image->dx += image->width + 8;
41136 }
41137 } else if (rotate == FB_ROTATE_UD) {
41138 - for (x = 0; x < num && image->dx >= 0; x++) {
41139 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41140 info->fbops->fb_imageblit(info, image);
41141 image->dx -= image->width + 8;
41142 }
41143 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41144 image->dy += image->height + 8;
41145 }
41146 } else if (rotate == FB_ROTATE_CCW) {
41147 - for (x = 0; x < num && image->dy >= 0; x++) {
41148 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41149 info->fbops->fb_imageblit(info, image);
41150 image->dy -= image->height + 8;
41151 }
41152 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41153 return -EFAULT;
41154 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41155 return -EINVAL;
41156 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41157 + if (con2fb.framebuffer >= FB_MAX)
41158 return -EINVAL;
41159 if (!registered_fb[con2fb.framebuffer])
41160 request_module("fb%d", con2fb.framebuffer);
41161 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41162 index 7672d2e..b56437f 100644
41163 --- a/drivers/video/i810/i810_accel.c
41164 +++ b/drivers/video/i810/i810_accel.c
41165 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41166 }
41167 }
41168 printk("ringbuffer lockup!!!\n");
41169 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41170 i810_report_error(mmio);
41171 par->dev_flags |= LOCKUP;
41172 info->pixmap.scan_align = 1;
41173 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41174 index 3c14e43..eafa544 100644
41175 --- a/drivers/video/logo/logo_linux_clut224.ppm
41176 +++ b/drivers/video/logo/logo_linux_clut224.ppm
41177 @@ -1,1604 +1,1123 @@
41178 P3
41179 -# Standard 224-color Linux logo
41180 80 80
41181 255
41182 - 0 0 0 0 0 0 0 0 0 0 0 0
41183 - 0 0 0 0 0 0 0 0 0 0 0 0
41184 - 0 0 0 0 0 0 0 0 0 0 0 0
41185 - 0 0 0 0 0 0 0 0 0 0 0 0
41186 - 0 0 0 0 0 0 0 0 0 0 0 0
41187 - 0 0 0 0 0 0 0 0 0 0 0 0
41188 - 0 0 0 0 0 0 0 0 0 0 0 0
41189 - 0 0 0 0 0 0 0 0 0 0 0 0
41190 - 0 0 0 0 0 0 0 0 0 0 0 0
41191 - 6 6 6 6 6 6 10 10 10 10 10 10
41192 - 10 10 10 6 6 6 6 6 6 6 6 6
41193 - 0 0 0 0 0 0 0 0 0 0 0 0
41194 - 0 0 0 0 0 0 0 0 0 0 0 0
41195 - 0 0 0 0 0 0 0 0 0 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 0 0 0
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 0 0 0 0 0 0
41201 - 0 0 0 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 0 0 0 0 0 0 0 0 0
41203 - 0 0 0 0 0 0 0 0 0 0 0 0
41204 - 0 0 0 0 0 0 0 0 0 0 0 0
41205 - 0 0 0 0 0 0 0 0 0 0 0 0
41206 - 0 0 0 0 0 0 0 0 0 0 0 0
41207 - 0 0 0 0 0 0 0 0 0 0 0 0
41208 - 0 0 0 0 0 0 0 0 0 0 0 0
41209 - 0 0 0 0 0 0 0 0 0 0 0 0
41210 - 0 0 0 6 6 6 10 10 10 14 14 14
41211 - 22 22 22 26 26 26 30 30 30 34 34 34
41212 - 30 30 30 30 30 30 26 26 26 18 18 18
41213 - 14 14 14 10 10 10 6 6 6 0 0 0
41214 - 0 0 0 0 0 0 0 0 0 0 0 0
41215 - 0 0 0 0 0 0 0 0 0 0 0 0
41216 - 0 0 0 0 0 0 0 0 0 0 0 0
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
41221 - 0 0 0 0 0 0 0 0 0 0 0 0
41222 - 0 0 0 0 0 0 0 0 0 0 0 0
41223 - 0 0 0 0 0 1 0 0 1 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 0 0 0
41226 - 0 0 0 0 0 0 0 0 0 0 0 0
41227 - 0 0 0 0 0 0 0 0 0 0 0 0
41228 - 0 0 0 0 0 0 0 0 0 0 0 0
41229 - 0 0 0 0 0 0 0 0 0 0 0 0
41230 - 6 6 6 14 14 14 26 26 26 42 42 42
41231 - 54 54 54 66 66 66 78 78 78 78 78 78
41232 - 78 78 78 74 74 74 66 66 66 54 54 54
41233 - 42 42 42 26 26 26 18 18 18 10 10 10
41234 - 6 6 6 0 0 0 0 0 0 0 0 0
41235 - 0 0 0 0 0 0 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 0 0 0 0 0 0 0 0 0 0
41243 - 0 0 1 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 0 0 0 0 0 0 0 0 0
41248 - 0 0 0 0 0 0 0 0 0 0 0 0
41249 - 0 0 0 0 0 0 0 0 0 10 10 10
41250 - 22 22 22 42 42 42 66 66 66 86 86 86
41251 - 66 66 66 38 38 38 38 38 38 22 22 22
41252 - 26 26 26 34 34 34 54 54 54 66 66 66
41253 - 86 86 86 70 70 70 46 46 46 26 26 26
41254 - 14 14 14 6 6 6 0 0 0 0 0 0
41255 - 0 0 0 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 0 0 0
41261 - 0 0 0 0 0 0 0 0 0 0 0 0
41262 - 0 0 0 0 0 0 0 0 0 0 0 0
41263 - 0 0 1 0 0 1 0 0 1 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 0 0 0
41267 - 0 0 0 0 0 0 0 0 0 0 0 0
41268 - 0 0 0 0 0 0 0 0 0 0 0 0
41269 - 0 0 0 0 0 0 10 10 10 26 26 26
41270 - 50 50 50 82 82 82 58 58 58 6 6 6
41271 - 2 2 6 2 2 6 2 2 6 2 2 6
41272 - 2 2 6 2 2 6 2 2 6 2 2 6
41273 - 6 6 6 54 54 54 86 86 86 66 66 66
41274 - 38 38 38 18 18 18 6 6 6 0 0 0
41275 - 0 0 0 0 0 0 0 0 0 0 0 0
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 0 0 0
41280 - 0 0 0 0 0 0 0 0 0 0 0 0
41281 - 0 0 0 0 0 0 0 0 0 0 0 0
41282 - 0 0 0 0 0 0 0 0 0 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 0 0 0
41284 - 0 0 0 0 0 0 0 0 0 0 0 0
41285 - 0 0 0 0 0 0 0 0 0 0 0 0
41286 - 0 0 0 0 0 0 0 0 0 0 0 0
41287 - 0 0 0 0 0 0 0 0 0 0 0 0
41288 - 0 0 0 0 0 0 0 0 0 0 0 0
41289 - 0 0 0 6 6 6 22 22 22 50 50 50
41290 - 78 78 78 34 34 34 2 2 6 2 2 6
41291 - 2 2 6 2 2 6 2 2 6 2 2 6
41292 - 2 2 6 2 2 6 2 2 6 2 2 6
41293 - 2 2 6 2 2 6 6 6 6 70 70 70
41294 - 78 78 78 46 46 46 22 22 22 6 6 6
41295 - 0 0 0 0 0 0 0 0 0 0 0 0
41296 - 0 0 0 0 0 0 0 0 0 0 0 0
41297 - 0 0 0 0 0 0 0 0 0 0 0 0
41298 - 0 0 0 0 0 0 0 0 0 0 0 0
41299 - 0 0 0 0 0 0 0 0 0 0 0 0
41300 - 0 0 0 0 0 0 0 0 0 0 0 0
41301 - 0 0 0 0 0 0 0 0 0 0 0 0
41302 - 0 0 0 0 0 0 0 0 0 0 0 0
41303 - 0 0 1 0 0 1 0 0 1 0 0 0
41304 - 0 0 0 0 0 0 0 0 0 0 0 0
41305 - 0 0 0 0 0 0 0 0 0 0 0 0
41306 - 0 0 0 0 0 0 0 0 0 0 0 0
41307 - 0 0 0 0 0 0 0 0 0 0 0 0
41308 - 0 0 0 0 0 0 0 0 0 0 0 0
41309 - 6 6 6 18 18 18 42 42 42 82 82 82
41310 - 26 26 26 2 2 6 2 2 6 2 2 6
41311 - 2 2 6 2 2 6 2 2 6 2 2 6
41312 - 2 2 6 2 2 6 2 2 6 14 14 14
41313 - 46 46 46 34 34 34 6 6 6 2 2 6
41314 - 42 42 42 78 78 78 42 42 42 18 18 18
41315 - 6 6 6 0 0 0 0 0 0 0 0 0
41316 - 0 0 0 0 0 0 0 0 0 0 0 0
41317 - 0 0 0 0 0 0 0 0 0 0 0 0
41318 - 0 0 0 0 0 0 0 0 0 0 0 0
41319 - 0 0 0 0 0 0 0 0 0 0 0 0
41320 - 0 0 0 0 0 0 0 0 0 0 0 0
41321 - 0 0 0 0 0 0 0 0 0 0 0 0
41322 - 0 0 0 0 0 0 0 0 0 0 0 0
41323 - 0 0 1 0 0 0 0 0 1 0 0 0
41324 - 0 0 0 0 0 0 0 0 0 0 0 0
41325 - 0 0 0 0 0 0 0 0 0 0 0 0
41326 - 0 0 0 0 0 0 0 0 0 0 0 0
41327 - 0 0 0 0 0 0 0 0 0 0 0 0
41328 - 0 0 0 0 0 0 0 0 0 0 0 0
41329 - 10 10 10 30 30 30 66 66 66 58 58 58
41330 - 2 2 6 2 2 6 2 2 6 2 2 6
41331 - 2 2 6 2 2 6 2 2 6 2 2 6
41332 - 2 2 6 2 2 6 2 2 6 26 26 26
41333 - 86 86 86 101 101 101 46 46 46 10 10 10
41334 - 2 2 6 58 58 58 70 70 70 34 34 34
41335 - 10 10 10 0 0 0 0 0 0 0 0 0
41336 - 0 0 0 0 0 0 0 0 0 0 0 0
41337 - 0 0 0 0 0 0 0 0 0 0 0 0
41338 - 0 0 0 0 0 0 0 0 0 0 0 0
41339 - 0 0 0 0 0 0 0 0 0 0 0 0
41340 - 0 0 0 0 0 0 0 0 0 0 0 0
41341 - 0 0 0 0 0 0 0 0 0 0 0 0
41342 - 0 0 0 0 0 0 0 0 0 0 0 0
41343 - 0 0 1 0 0 1 0 0 1 0 0 0
41344 - 0 0 0 0 0 0 0 0 0 0 0 0
41345 - 0 0 0 0 0 0 0 0 0 0 0 0
41346 - 0 0 0 0 0 0 0 0 0 0 0 0
41347 - 0 0 0 0 0 0 0 0 0 0 0 0
41348 - 0 0 0 0 0 0 0 0 0 0 0 0
41349 - 14 14 14 42 42 42 86 86 86 10 10 10
41350 - 2 2 6 2 2 6 2 2 6 2 2 6
41351 - 2 2 6 2 2 6 2 2 6 2 2 6
41352 - 2 2 6 2 2 6 2 2 6 30 30 30
41353 - 94 94 94 94 94 94 58 58 58 26 26 26
41354 - 2 2 6 6 6 6 78 78 78 54 54 54
41355 - 22 22 22 6 6 6 0 0 0 0 0 0
41356 - 0 0 0 0 0 0 0 0 0 0 0 0
41357 - 0 0 0 0 0 0 0 0 0 0 0 0
41358 - 0 0 0 0 0 0 0 0 0 0 0 0
41359 - 0 0 0 0 0 0 0 0 0 0 0 0
41360 - 0 0 0 0 0 0 0 0 0 0 0 0
41361 - 0 0 0 0 0 0 0 0 0 0 0 0
41362 - 0 0 0 0 0 0 0 0 0 0 0 0
41363 - 0 0 0 0 0 0 0 0 0 0 0 0
41364 - 0 0 0 0 0 0 0 0 0 0 0 0
41365 - 0 0 0 0 0 0 0 0 0 0 0 0
41366 - 0 0 0 0 0 0 0 0 0 0 0 0
41367 - 0 0 0 0 0 0 0 0 0 0 0 0
41368 - 0 0 0 0 0 0 0 0 0 6 6 6
41369 - 22 22 22 62 62 62 62 62 62 2 2 6
41370 - 2 2 6 2 2 6 2 2 6 2 2 6
41371 - 2 2 6 2 2 6 2 2 6 2 2 6
41372 - 2 2 6 2 2 6 2 2 6 26 26 26
41373 - 54 54 54 38 38 38 18 18 18 10 10 10
41374 - 2 2 6 2 2 6 34 34 34 82 82 82
41375 - 38 38 38 14 14 14 0 0 0 0 0 0
41376 - 0 0 0 0 0 0 0 0 0 0 0 0
41377 - 0 0 0 0 0 0 0 0 0 0 0 0
41378 - 0 0 0 0 0 0 0 0 0 0 0 0
41379 - 0 0 0 0 0 0 0 0 0 0 0 0
41380 - 0 0 0 0 0 0 0 0 0 0 0 0
41381 - 0 0 0 0 0 0 0 0 0 0 0 0
41382 - 0 0 0 0 0 0 0 0 0 0 0 0
41383 - 0 0 0 0 0 1 0 0 1 0 0 0
41384 - 0 0 0 0 0 0 0 0 0 0 0 0
41385 - 0 0 0 0 0 0 0 0 0 0 0 0
41386 - 0 0 0 0 0 0 0 0 0 0 0 0
41387 - 0 0 0 0 0 0 0 0 0 0 0 0
41388 - 0 0 0 0 0 0 0 0 0 6 6 6
41389 - 30 30 30 78 78 78 30 30 30 2 2 6
41390 - 2 2 6 2 2 6 2 2 6 2 2 6
41391 - 2 2 6 2 2 6 2 2 6 2 2 6
41392 - 2 2 6 2 2 6 2 2 6 10 10 10
41393 - 10 10 10 2 2 6 2 2 6 2 2 6
41394 - 2 2 6 2 2 6 2 2 6 78 78 78
41395 - 50 50 50 18 18 18 6 6 6 0 0 0
41396 - 0 0 0 0 0 0 0 0 0 0 0 0
41397 - 0 0 0 0 0 0 0 0 0 0 0 0
41398 - 0 0 0 0 0 0 0 0 0 0 0 0
41399 - 0 0 0 0 0 0 0 0 0 0 0 0
41400 - 0 0 0 0 0 0 0 0 0 0 0 0
41401 - 0 0 0 0 0 0 0 0 0 0 0 0
41402 - 0 0 0 0 0 0 0 0 0 0 0 0
41403 - 0 0 1 0 0 0 0 0 0 0 0 0
41404 - 0 0 0 0 0 0 0 0 0 0 0 0
41405 - 0 0 0 0 0 0 0 0 0 0 0 0
41406 - 0 0 0 0 0 0 0 0 0 0 0 0
41407 - 0 0 0 0 0 0 0 0 0 0 0 0
41408 - 0 0 0 0 0 0 0 0 0 10 10 10
41409 - 38 38 38 86 86 86 14 14 14 2 2 6
41410 - 2 2 6 2 2 6 2 2 6 2 2 6
41411 - 2 2 6 2 2 6 2 2 6 2 2 6
41412 - 2 2 6 2 2 6 2 2 6 2 2 6
41413 - 2 2 6 2 2 6 2 2 6 2 2 6
41414 - 2 2 6 2 2 6 2 2 6 54 54 54
41415 - 66 66 66 26 26 26 6 6 6 0 0 0
41416 - 0 0 0 0 0 0 0 0 0 0 0 0
41417 - 0 0 0 0 0 0 0 0 0 0 0 0
41418 - 0 0 0 0 0 0 0 0 0 0 0 0
41419 - 0 0 0 0 0 0 0 0 0 0 0 0
41420 - 0 0 0 0 0 0 0 0 0 0 0 0
41421 - 0 0 0 0 0 0 0 0 0 0 0 0
41422 - 0 0 0 0 0 0 0 0 0 0 0 0
41423 - 0 0 0 0 0 1 0 0 1 0 0 0
41424 - 0 0 0 0 0 0 0 0 0 0 0 0
41425 - 0 0 0 0 0 0 0 0 0 0 0 0
41426 - 0 0 0 0 0 0 0 0 0 0 0 0
41427 - 0 0 0 0 0 0 0 0 0 0 0 0
41428 - 0 0 0 0 0 0 0 0 0 14 14 14
41429 - 42 42 42 82 82 82 2 2 6 2 2 6
41430 - 2 2 6 6 6 6 10 10 10 2 2 6
41431 - 2 2 6 2 2 6 2 2 6 2 2 6
41432 - 2 2 6 2 2 6 2 2 6 6 6 6
41433 - 14 14 14 10 10 10 2 2 6 2 2 6
41434 - 2 2 6 2 2 6 2 2 6 18 18 18
41435 - 82 82 82 34 34 34 10 10 10 0 0 0
41436 - 0 0 0 0 0 0 0 0 0 0 0 0
41437 - 0 0 0 0 0 0 0 0 0 0 0 0
41438 - 0 0 0 0 0 0 0 0 0 0 0 0
41439 - 0 0 0 0 0 0 0 0 0 0 0 0
41440 - 0 0 0 0 0 0 0 0 0 0 0 0
41441 - 0 0 0 0 0 0 0 0 0 0 0 0
41442 - 0 0 0 0 0 0 0 0 0 0 0 0
41443 - 0 0 1 0 0 0 0 0 0 0 0 0
41444 - 0 0 0 0 0 0 0 0 0 0 0 0
41445 - 0 0 0 0 0 0 0 0 0 0 0 0
41446 - 0 0 0 0 0 0 0 0 0 0 0 0
41447 - 0 0 0 0 0 0 0 0 0 0 0 0
41448 - 0 0 0 0 0 0 0 0 0 14 14 14
41449 - 46 46 46 86 86 86 2 2 6 2 2 6
41450 - 6 6 6 6 6 6 22 22 22 34 34 34
41451 - 6 6 6 2 2 6 2 2 6 2 2 6
41452 - 2 2 6 2 2 6 18 18 18 34 34 34
41453 - 10 10 10 50 50 50 22 22 22 2 2 6
41454 - 2 2 6 2 2 6 2 2 6 10 10 10
41455 - 86 86 86 42 42 42 14 14 14 0 0 0
41456 - 0 0 0 0 0 0 0 0 0 0 0 0
41457 - 0 0 0 0 0 0 0 0 0 0 0 0
41458 - 0 0 0 0 0 0 0 0 0 0 0 0
41459 - 0 0 0 0 0 0 0 0 0 0 0 0
41460 - 0 0 0 0 0 0 0 0 0 0 0 0
41461 - 0 0 0 0 0 0 0 0 0 0 0 0
41462 - 0 0 0 0 0 0 0 0 0 0 0 0
41463 - 0 0 1 0 0 1 0 0 1 0 0 0
41464 - 0 0 0 0 0 0 0 0 0 0 0 0
41465 - 0 0 0 0 0 0 0 0 0 0 0 0
41466 - 0 0 0 0 0 0 0 0 0 0 0 0
41467 - 0 0 0 0 0 0 0 0 0 0 0 0
41468 - 0 0 0 0 0 0 0 0 0 14 14 14
41469 - 46 46 46 86 86 86 2 2 6 2 2 6
41470 - 38 38 38 116 116 116 94 94 94 22 22 22
41471 - 22 22 22 2 2 6 2 2 6 2 2 6
41472 - 14 14 14 86 86 86 138 138 138 162 162 162
41473 -154 154 154 38 38 38 26 26 26 6 6 6
41474 - 2 2 6 2 2 6 2 2 6 2 2 6
41475 - 86 86 86 46 46 46 14 14 14 0 0 0
41476 - 0 0 0 0 0 0 0 0 0 0 0 0
41477 - 0 0 0 0 0 0 0 0 0 0 0 0
41478 - 0 0 0 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 0 0 0 0 0 0 0 0 0
41481 - 0 0 0 0 0 0 0 0 0 0 0 0
41482 - 0 0 0 0 0 0 0 0 0 0 0 0
41483 - 0 0 0 0 0 0 0 0 0 0 0 0
41484 - 0 0 0 0 0 0 0 0 0 0 0 0
41485 - 0 0 0 0 0 0 0 0 0 0 0 0
41486 - 0 0 0 0 0 0 0 0 0 0 0 0
41487 - 0 0 0 0 0 0 0 0 0 0 0 0
41488 - 0 0 0 0 0 0 0 0 0 14 14 14
41489 - 46 46 46 86 86 86 2 2 6 14 14 14
41490 -134 134 134 198 198 198 195 195 195 116 116 116
41491 - 10 10 10 2 2 6 2 2 6 6 6 6
41492 -101 98 89 187 187 187 210 210 210 218 218 218
41493 -214 214 214 134 134 134 14 14 14 6 6 6
41494 - 2 2 6 2 2 6 2 2 6 2 2 6
41495 - 86 86 86 50 50 50 18 18 18 6 6 6
41496 - 0 0 0 0 0 0 0 0 0 0 0 0
41497 - 0 0 0 0 0 0 0 0 0 0 0 0
41498 - 0 0 0 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 0 0 0 0 0 0
41501 - 0 0 0 0 0 0 0 0 0 0 0 0
41502 - 0 0 0 0 0 0 0 0 1 0 0 0
41503 - 0 0 1 0 0 1 0 0 1 0 0 0
41504 - 0 0 0 0 0 0 0 0 0 0 0 0
41505 - 0 0 0 0 0 0 0 0 0 0 0 0
41506 - 0 0 0 0 0 0 0 0 0 0 0 0
41507 - 0 0 0 0 0 0 0 0 0 0 0 0
41508 - 0 0 0 0 0 0 0 0 0 14 14 14
41509 - 46 46 46 86 86 86 2 2 6 54 54 54
41510 -218 218 218 195 195 195 226 226 226 246 246 246
41511 - 58 58 58 2 2 6 2 2 6 30 30 30
41512 -210 210 210 253 253 253 174 174 174 123 123 123
41513 -221 221 221 234 234 234 74 74 74 2 2 6
41514 - 2 2 6 2 2 6 2 2 6 2 2 6
41515 - 70 70 70 58 58 58 22 22 22 6 6 6
41516 - 0 0 0 0 0 0 0 0 0 0 0 0
41517 - 0 0 0 0 0 0 0 0 0 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 0 0 0 0 0 0 0 0 0
41521 - 0 0 0 0 0 0 0 0 0 0 0 0
41522 - 0 0 0 0 0 0 0 0 0 0 0 0
41523 - 0 0 0 0 0 0 0 0 0 0 0 0
41524 - 0 0 0 0 0 0 0 0 0 0 0 0
41525 - 0 0 0 0 0 0 0 0 0 0 0 0
41526 - 0 0 0 0 0 0 0 0 0 0 0 0
41527 - 0 0 0 0 0 0 0 0 0 0 0 0
41528 - 0 0 0 0 0 0 0 0 0 14 14 14
41529 - 46 46 46 82 82 82 2 2 6 106 106 106
41530 -170 170 170 26 26 26 86 86 86 226 226 226
41531 -123 123 123 10 10 10 14 14 14 46 46 46
41532 -231 231 231 190 190 190 6 6 6 70 70 70
41533 - 90 90 90 238 238 238 158 158 158 2 2 6
41534 - 2 2 6 2 2 6 2 2 6 2 2 6
41535 - 70 70 70 58 58 58 22 22 22 6 6 6
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 0 0 0 0 0 0 0 0 0 0 0 0
41541 - 0 0 0 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 0 0 0 0 0 1 0 0 0
41543 - 0 0 1 0 0 1 0 0 1 0 0 0
41544 - 0 0 0 0 0 0 0 0 0 0 0 0
41545 - 0 0 0 0 0 0 0 0 0 0 0 0
41546 - 0 0 0 0 0 0 0 0 0 0 0 0
41547 - 0 0 0 0 0 0 0 0 0 0 0 0
41548 - 0 0 0 0 0 0 0 0 0 14 14 14
41549 - 42 42 42 86 86 86 6 6 6 116 116 116
41550 -106 106 106 6 6 6 70 70 70 149 149 149
41551 -128 128 128 18 18 18 38 38 38 54 54 54
41552 -221 221 221 106 106 106 2 2 6 14 14 14
41553 - 46 46 46 190 190 190 198 198 198 2 2 6
41554 - 2 2 6 2 2 6 2 2 6 2 2 6
41555 - 74 74 74 62 62 62 22 22 22 6 6 6
41556 - 0 0 0 0 0 0 0 0 0 0 0 0
41557 - 0 0 0 0 0 0 0 0 0 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 0 0 0 0 0 0 0 0 0 0 0 0
41561 - 0 0 0 0 0 0 0 0 0 0 0 0
41562 - 0 0 0 0 0 0 0 0 1 0 0 0
41563 - 0 0 1 0 0 0 0 0 1 0 0 0
41564 - 0 0 0 0 0 0 0 0 0 0 0 0
41565 - 0 0 0 0 0 0 0 0 0 0 0 0
41566 - 0 0 0 0 0 0 0 0 0 0 0 0
41567 - 0 0 0 0 0 0 0 0 0 0 0 0
41568 - 0 0 0 0 0 0 0 0 0 14 14 14
41569 - 42 42 42 94 94 94 14 14 14 101 101 101
41570 -128 128 128 2 2 6 18 18 18 116 116 116
41571 -118 98 46 121 92 8 121 92 8 98 78 10
41572 -162 162 162 106 106 106 2 2 6 2 2 6
41573 - 2 2 6 195 195 195 195 195 195 6 6 6
41574 - 2 2 6 2 2 6 2 2 6 2 2 6
41575 - 74 74 74 62 62 62 22 22 22 6 6 6
41576 - 0 0 0 0 0 0 0 0 0 0 0 0
41577 - 0 0 0 0 0 0 0 0 0 0 0 0
41578 - 0 0 0 0 0 0 0 0 0 0 0 0
41579 - 0 0 0 0 0 0 0 0 0 0 0 0
41580 - 0 0 0 0 0 0 0 0 0 0 0 0
41581 - 0 0 0 0 0 0 0 0 0 0 0 0
41582 - 0 0 0 0 0 0 0 0 1 0 0 1
41583 - 0 0 1 0 0 0 0 0 1 0 0 0
41584 - 0 0 0 0 0 0 0 0 0 0 0 0
41585 - 0 0 0 0 0 0 0 0 0 0 0 0
41586 - 0 0 0 0 0 0 0 0 0 0 0 0
41587 - 0 0 0 0 0 0 0 0 0 0 0 0
41588 - 0 0 0 0 0 0 0 0 0 10 10 10
41589 - 38 38 38 90 90 90 14 14 14 58 58 58
41590 -210 210 210 26 26 26 54 38 6 154 114 10
41591 -226 170 11 236 186 11 225 175 15 184 144 12
41592 -215 174 15 175 146 61 37 26 9 2 2 6
41593 - 70 70 70 246 246 246 138 138 138 2 2 6
41594 - 2 2 6 2 2 6 2 2 6 2 2 6
41595 - 70 70 70 66 66 66 26 26 26 6 6 6
41596 - 0 0 0 0 0 0 0 0 0 0 0 0
41597 - 0 0 0 0 0 0 0 0 0 0 0 0
41598 - 0 0 0 0 0 0 0 0 0 0 0 0
41599 - 0 0 0 0 0 0 0 0 0 0 0 0
41600 - 0 0 0 0 0 0 0 0 0 0 0 0
41601 - 0 0 0 0 0 0 0 0 0 0 0 0
41602 - 0 0 0 0 0 0 0 0 0 0 0 0
41603 - 0 0 0 0 0 0 0 0 0 0 0 0
41604 - 0 0 0 0 0 0 0 0 0 0 0 0
41605 - 0 0 0 0 0 0 0 0 0 0 0 0
41606 - 0 0 0 0 0 0 0 0 0 0 0 0
41607 - 0 0 0 0 0 0 0 0 0 0 0 0
41608 - 0 0 0 0 0 0 0 0 0 10 10 10
41609 - 38 38 38 86 86 86 14 14 14 10 10 10
41610 -195 195 195 188 164 115 192 133 9 225 175 15
41611 -239 182 13 234 190 10 232 195 16 232 200 30
41612 -245 207 45 241 208 19 232 195 16 184 144 12
41613 -218 194 134 211 206 186 42 42 42 2 2 6
41614 - 2 2 6 2 2 6 2 2 6 2 2 6
41615 - 50 50 50 74 74 74 30 30 30 6 6 6
41616 - 0 0 0 0 0 0 0 0 0 0 0 0
41617 - 0 0 0 0 0 0 0 0 0 0 0 0
41618 - 0 0 0 0 0 0 0 0 0 0 0 0
41619 - 0 0 0 0 0 0 0 0 0 0 0 0
41620 - 0 0 0 0 0 0 0 0 0 0 0 0
41621 - 0 0 0 0 0 0 0 0 0 0 0 0
41622 - 0 0 0 0 0 0 0 0 0 0 0 0
41623 - 0 0 0 0 0 0 0 0 0 0 0 0
41624 - 0 0 0 0 0 0 0 0 0 0 0 0
41625 - 0 0 0 0 0 0 0 0 0 0 0 0
41626 - 0 0 0 0 0 0 0 0 0 0 0 0
41627 - 0 0 0 0 0 0 0 0 0 0 0 0
41628 - 0 0 0 0 0 0 0 0 0 10 10 10
41629 - 34 34 34 86 86 86 14 14 14 2 2 6
41630 -121 87 25 192 133 9 219 162 10 239 182 13
41631 -236 186 11 232 195 16 241 208 19 244 214 54
41632 -246 218 60 246 218 38 246 215 20 241 208 19
41633 -241 208 19 226 184 13 121 87 25 2 2 6
41634 - 2 2 6 2 2 6 2 2 6 2 2 6
41635 - 50 50 50 82 82 82 34 34 34 10 10 10
41636 - 0 0 0 0 0 0 0 0 0 0 0 0
41637 - 0 0 0 0 0 0 0 0 0 0 0 0
41638 - 0 0 0 0 0 0 0 0 0 0 0 0
41639 - 0 0 0 0 0 0 0 0 0 0 0 0
41640 - 0 0 0 0 0 0 0 0 0 0 0 0
41641 - 0 0 0 0 0 0 0 0 0 0 0 0
41642 - 0 0 0 0 0 0 0 0 0 0 0 0
41643 - 0 0 0 0 0 0 0 0 0 0 0 0
41644 - 0 0 0 0 0 0 0 0 0 0 0 0
41645 - 0 0 0 0 0 0 0 0 0 0 0 0
41646 - 0 0 0 0 0 0 0 0 0 0 0 0
41647 - 0 0 0 0 0 0 0 0 0 0 0 0
41648 - 0 0 0 0 0 0 0 0 0 10 10 10
41649 - 34 34 34 82 82 82 30 30 30 61 42 6
41650 -180 123 7 206 145 10 230 174 11 239 182 13
41651 -234 190 10 238 202 15 241 208 19 246 218 74
41652 -246 218 38 246 215 20 246 215 20 246 215 20
41653 -226 184 13 215 174 15 184 144 12 6 6 6
41654 - 2 2 6 2 2 6 2 2 6 2 2 6
41655 - 26 26 26 94 94 94 42 42 42 14 14 14
41656 - 0 0 0 0 0 0 0 0 0 0 0 0
41657 - 0 0 0 0 0 0 0 0 0 0 0 0
41658 - 0 0 0 0 0 0 0 0 0 0 0 0
41659 - 0 0 0 0 0 0 0 0 0 0 0 0
41660 - 0 0 0 0 0 0 0 0 0 0 0 0
41661 - 0 0 0 0 0 0 0 0 0 0 0 0
41662 - 0 0 0 0 0 0 0 0 0 0 0 0
41663 - 0 0 0 0 0 0 0 0 0 0 0 0
41664 - 0 0 0 0 0 0 0 0 0 0 0 0
41665 - 0 0 0 0 0 0 0 0 0 0 0 0
41666 - 0 0 0 0 0 0 0 0 0 0 0 0
41667 - 0 0 0 0 0 0 0 0 0 0 0 0
41668 - 0 0 0 0 0 0 0 0 0 10 10 10
41669 - 30 30 30 78 78 78 50 50 50 104 69 6
41670 -192 133 9 216 158 10 236 178 12 236 186 11
41671 -232 195 16 241 208 19 244 214 54 245 215 43
41672 -246 215 20 246 215 20 241 208 19 198 155 10
41673 -200 144 11 216 158 10 156 118 10 2 2 6
41674 - 2 2 6 2 2 6 2 2 6 2 2 6
41675 - 6 6 6 90 90 90 54 54 54 18 18 18
41676 - 6 6 6 0 0 0 0 0 0 0 0 0
41677 - 0 0 0 0 0 0 0 0 0 0 0 0
41678 - 0 0 0 0 0 0 0 0 0 0 0 0
41679 - 0 0 0 0 0 0 0 0 0 0 0 0
41680 - 0 0 0 0 0 0 0 0 0 0 0 0
41681 - 0 0 0 0 0 0 0 0 0 0 0 0
41682 - 0 0 0 0 0 0 0 0 0 0 0 0
41683 - 0 0 0 0 0 0 0 0 0 0 0 0
41684 - 0 0 0 0 0 0 0 0 0 0 0 0
41685 - 0 0 0 0 0 0 0 0 0 0 0 0
41686 - 0 0 0 0 0 0 0 0 0 0 0 0
41687 - 0 0 0 0 0 0 0 0 0 0 0 0
41688 - 0 0 0 0 0 0 0 0 0 10 10 10
41689 - 30 30 30 78 78 78 46 46 46 22 22 22
41690 -137 92 6 210 162 10 239 182 13 238 190 10
41691 -238 202 15 241 208 19 246 215 20 246 215 20
41692 -241 208 19 203 166 17 185 133 11 210 150 10
41693 -216 158 10 210 150 10 102 78 10 2 2 6
41694 - 6 6 6 54 54 54 14 14 14 2 2 6
41695 - 2 2 6 62 62 62 74 74 74 30 30 30
41696 - 10 10 10 0 0 0 0 0 0 0 0 0
41697 - 0 0 0 0 0 0 0 0 0 0 0 0
41698 - 0 0 0 0 0 0 0 0 0 0 0 0
41699 - 0 0 0 0 0 0 0 0 0 0 0 0
41700 - 0 0 0 0 0 0 0 0 0 0 0 0
41701 - 0 0 0 0 0 0 0 0 0 0 0 0
41702 - 0 0 0 0 0 0 0 0 0 0 0 0
41703 - 0 0 0 0 0 0 0 0 0 0 0 0
41704 - 0 0 0 0 0 0 0 0 0 0 0 0
41705 - 0 0 0 0 0 0 0 0 0 0 0 0
41706 - 0 0 0 0 0 0 0 0 0 0 0 0
41707 - 0 0 0 0 0 0 0 0 0 0 0 0
41708 - 0 0 0 0 0 0 0 0 0 10 10 10
41709 - 34 34 34 78 78 78 50 50 50 6 6 6
41710 - 94 70 30 139 102 15 190 146 13 226 184 13
41711 -232 200 30 232 195 16 215 174 15 190 146 13
41712 -168 122 10 192 133 9 210 150 10 213 154 11
41713 -202 150 34 182 157 106 101 98 89 2 2 6
41714 - 2 2 6 78 78 78 116 116 116 58 58 58
41715 - 2 2 6 22 22 22 90 90 90 46 46 46
41716 - 18 18 18 6 6 6 0 0 0 0 0 0
41717 - 0 0 0 0 0 0 0 0 0 0 0 0
41718 - 0 0 0 0 0 0 0 0 0 0 0 0
41719 - 0 0 0 0 0 0 0 0 0 0 0 0
41720 - 0 0 0 0 0 0 0 0 0 0 0 0
41721 - 0 0 0 0 0 0 0 0 0 0 0 0
41722 - 0 0 0 0 0 0 0 0 0 0 0 0
41723 - 0 0 0 0 0 0 0 0 0 0 0 0
41724 - 0 0 0 0 0 0 0 0 0 0 0 0
41725 - 0 0 0 0 0 0 0 0 0 0 0 0
41726 - 0 0 0 0 0 0 0 0 0 0 0 0
41727 - 0 0 0 0 0 0 0 0 0 0 0 0
41728 - 0 0 0 0 0 0 0 0 0 10 10 10
41729 - 38 38 38 86 86 86 50 50 50 6 6 6
41730 -128 128 128 174 154 114 156 107 11 168 122 10
41731 -198 155 10 184 144 12 197 138 11 200 144 11
41732 -206 145 10 206 145 10 197 138 11 188 164 115
41733 -195 195 195 198 198 198 174 174 174 14 14 14
41734 - 2 2 6 22 22 22 116 116 116 116 116 116
41735 - 22 22 22 2 2 6 74 74 74 70 70 70
41736 - 30 30 30 10 10 10 0 0 0 0 0 0
41737 - 0 0 0 0 0 0 0 0 0 0 0 0
41738 - 0 0 0 0 0 0 0 0 0 0 0 0
41739 - 0 0 0 0 0 0 0 0 0 0 0 0
41740 - 0 0 0 0 0 0 0 0 0 0 0 0
41741 - 0 0 0 0 0 0 0 0 0 0 0 0
41742 - 0 0 0 0 0 0 0 0 0 0 0 0
41743 - 0 0 0 0 0 0 0 0 0 0 0 0
41744 - 0 0 0 0 0 0 0 0 0 0 0 0
41745 - 0 0 0 0 0 0 0 0 0 0 0 0
41746 - 0 0 0 0 0 0 0 0 0 0 0 0
41747 - 0 0 0 0 0 0 0 0 0 0 0 0
41748 - 0 0 0 0 0 0 6 6 6 18 18 18
41749 - 50 50 50 101 101 101 26 26 26 10 10 10
41750 -138 138 138 190 190 190 174 154 114 156 107 11
41751 -197 138 11 200 144 11 197 138 11 192 133 9
41752 -180 123 7 190 142 34 190 178 144 187 187 187
41753 -202 202 202 221 221 221 214 214 214 66 66 66
41754 - 2 2 6 2 2 6 50 50 50 62 62 62
41755 - 6 6 6 2 2 6 10 10 10 90 90 90
41756 - 50 50 50 18 18 18 6 6 6 0 0 0
41757 - 0 0 0 0 0 0 0 0 0 0 0 0
41758 - 0 0 0 0 0 0 0 0 0 0 0 0
41759 - 0 0 0 0 0 0 0 0 0 0 0 0
41760 - 0 0 0 0 0 0 0 0 0 0 0 0
41761 - 0 0 0 0 0 0 0 0 0 0 0 0
41762 - 0 0 0 0 0 0 0 0 0 0 0 0
41763 - 0 0 0 0 0 0 0 0 0 0 0 0
41764 - 0 0 0 0 0 0 0 0 0 0 0 0
41765 - 0 0 0 0 0 0 0 0 0 0 0 0
41766 - 0 0 0 0 0 0 0 0 0 0 0 0
41767 - 0 0 0 0 0 0 0 0 0 0 0 0
41768 - 0 0 0 0 0 0 10 10 10 34 34 34
41769 - 74 74 74 74 74 74 2 2 6 6 6 6
41770 -144 144 144 198 198 198 190 190 190 178 166 146
41771 -154 121 60 156 107 11 156 107 11 168 124 44
41772 -174 154 114 187 187 187 190 190 190 210 210 210
41773 -246 246 246 253 253 253 253 253 253 182 182 182
41774 - 6 6 6 2 2 6 2 2 6 2 2 6
41775 - 2 2 6 2 2 6 2 2 6 62 62 62
41776 - 74 74 74 34 34 34 14 14 14 0 0 0
41777 - 0 0 0 0 0 0 0 0 0 0 0 0
41778 - 0 0 0 0 0 0 0 0 0 0 0 0
41779 - 0 0 0 0 0 0 0 0 0 0 0 0
41780 - 0 0 0 0 0 0 0 0 0 0 0 0
41781 - 0 0 0 0 0 0 0 0 0 0 0 0
41782 - 0 0 0 0 0 0 0 0 0 0 0 0
41783 - 0 0 0 0 0 0 0 0 0 0 0 0
41784 - 0 0 0 0 0 0 0 0 0 0 0 0
41785 - 0 0 0 0 0 0 0 0 0 0 0 0
41786 - 0 0 0 0 0 0 0 0 0 0 0 0
41787 - 0 0 0 0 0 0 0 0 0 0 0 0
41788 - 0 0 0 10 10 10 22 22 22 54 54 54
41789 - 94 94 94 18 18 18 2 2 6 46 46 46
41790 -234 234 234 221 221 221 190 190 190 190 190 190
41791 -190 190 190 187 187 187 187 187 187 190 190 190
41792 -190 190 190 195 195 195 214 214 214 242 242 242
41793 -253 253 253 253 253 253 253 253 253 253 253 253
41794 - 82 82 82 2 2 6 2 2 6 2 2 6
41795 - 2 2 6 2 2 6 2 2 6 14 14 14
41796 - 86 86 86 54 54 54 22 22 22 6 6 6
41797 - 0 0 0 0 0 0 0 0 0 0 0 0
41798 - 0 0 0 0 0 0 0 0 0 0 0 0
41799 - 0 0 0 0 0 0 0 0 0 0 0 0
41800 - 0 0 0 0 0 0 0 0 0 0 0 0
41801 - 0 0 0 0 0 0 0 0 0 0 0 0
41802 - 0 0 0 0 0 0 0 0 0 0 0 0
41803 - 0 0 0 0 0 0 0 0 0 0 0 0
41804 - 0 0 0 0 0 0 0 0 0 0 0 0
41805 - 0 0 0 0 0 0 0 0 0 0 0 0
41806 - 0 0 0 0 0 0 0 0 0 0 0 0
41807 - 0 0 0 0 0 0 0 0 0 0 0 0
41808 - 6 6 6 18 18 18 46 46 46 90 90 90
41809 - 46 46 46 18 18 18 6 6 6 182 182 182
41810 -253 253 253 246 246 246 206 206 206 190 190 190
41811 -190 190 190 190 190 190 190 190 190 190 190 190
41812 -206 206 206 231 231 231 250 250 250 253 253 253
41813 -253 253 253 253 253 253 253 253 253 253 253 253
41814 -202 202 202 14 14 14 2 2 6 2 2 6
41815 - 2 2 6 2 2 6 2 2 6 2 2 6
41816 - 42 42 42 86 86 86 42 42 42 18 18 18
41817 - 6 6 6 0 0 0 0 0 0 0 0 0
41818 - 0 0 0 0 0 0 0 0 0 0 0 0
41819 - 0 0 0 0 0 0 0 0 0 0 0 0
41820 - 0 0 0 0 0 0 0 0 0 0 0 0
41821 - 0 0 0 0 0 0 0 0 0 0 0 0
41822 - 0 0 0 0 0 0 0 0 0 0 0 0
41823 - 0 0 0 0 0 0 0 0 0 0 0 0
41824 - 0 0 0 0 0 0 0 0 0 0 0 0
41825 - 0 0 0 0 0 0 0 0 0 0 0 0
41826 - 0 0 0 0 0 0 0 0 0 0 0 0
41827 - 0 0 0 0 0 0 0 0 0 6 6 6
41828 - 14 14 14 38 38 38 74 74 74 66 66 66
41829 - 2 2 6 6 6 6 90 90 90 250 250 250
41830 -253 253 253 253 253 253 238 238 238 198 198 198
41831 -190 190 190 190 190 190 195 195 195 221 221 221
41832 -246 246 246 253 253 253 253 253 253 253 253 253
41833 -253 253 253 253 253 253 253 253 253 253 253 253
41834 -253 253 253 82 82 82 2 2 6 2 2 6
41835 - 2 2 6 2 2 6 2 2 6 2 2 6
41836 - 2 2 6 78 78 78 70 70 70 34 34 34
41837 - 14 14 14 6 6 6 0 0 0 0 0 0
41838 - 0 0 0 0 0 0 0 0 0 0 0 0
41839 - 0 0 0 0 0 0 0 0 0 0 0 0
41840 - 0 0 0 0 0 0 0 0 0 0 0 0
41841 - 0 0 0 0 0 0 0 0 0 0 0 0
41842 - 0 0 0 0 0 0 0 0 0 0 0 0
41843 - 0 0 0 0 0 0 0 0 0 0 0 0
41844 - 0 0 0 0 0 0 0 0 0 0 0 0
41845 - 0 0 0 0 0 0 0 0 0 0 0 0
41846 - 0 0 0 0 0 0 0 0 0 0 0 0
41847 - 0 0 0 0 0 0 0 0 0 14 14 14
41848 - 34 34 34 66 66 66 78 78 78 6 6 6
41849 - 2 2 6 18 18 18 218 218 218 253 253 253
41850 -253 253 253 253 253 253 253 253 253 246 246 246
41851 -226 226 226 231 231 231 246 246 246 253 253 253
41852 -253 253 253 253 253 253 253 253 253 253 253 253
41853 -253 253 253 253 253 253 253 253 253 253 253 253
41854 -253 253 253 178 178 178 2 2 6 2 2 6
41855 - 2 2 6 2 2 6 2 2 6 2 2 6
41856 - 2 2 6 18 18 18 90 90 90 62 62 62
41857 - 30 30 30 10 10 10 0 0 0 0 0 0
41858 - 0 0 0 0 0 0 0 0 0 0 0 0
41859 - 0 0 0 0 0 0 0 0 0 0 0 0
41860 - 0 0 0 0 0 0 0 0 0 0 0 0
41861 - 0 0 0 0 0 0 0 0 0 0 0 0
41862 - 0 0 0 0 0 0 0 0 0 0 0 0
41863 - 0 0 0 0 0 0 0 0 0 0 0 0
41864 - 0 0 0 0 0 0 0 0 0 0 0 0
41865 - 0 0 0 0 0 0 0 0 0 0 0 0
41866 - 0 0 0 0 0 0 0 0 0 0 0 0
41867 - 0 0 0 0 0 0 10 10 10 26 26 26
41868 - 58 58 58 90 90 90 18 18 18 2 2 6
41869 - 2 2 6 110 110 110 253 253 253 253 253 253
41870 -253 253 253 253 253 253 253 253 253 253 253 253
41871 -250 250 250 253 253 253 253 253 253 253 253 253
41872 -253 253 253 253 253 253 253 253 253 253 253 253
41873 -253 253 253 253 253 253 253 253 253 253 253 253
41874 -253 253 253 231 231 231 18 18 18 2 2 6
41875 - 2 2 6 2 2 6 2 2 6 2 2 6
41876 - 2 2 6 2 2 6 18 18 18 94 94 94
41877 - 54 54 54 26 26 26 10 10 10 0 0 0
41878 - 0 0 0 0 0 0 0 0 0 0 0 0
41879 - 0 0 0 0 0 0 0 0 0 0 0 0
41880 - 0 0 0 0 0 0 0 0 0 0 0 0
41881 - 0 0 0 0 0 0 0 0 0 0 0 0
41882 - 0 0 0 0 0 0 0 0 0 0 0 0
41883 - 0 0 0 0 0 0 0 0 0 0 0 0
41884 - 0 0 0 0 0 0 0 0 0 0 0 0
41885 - 0 0 0 0 0 0 0 0 0 0 0 0
41886 - 0 0 0 0 0 0 0 0 0 0 0 0
41887 - 0 0 0 6 6 6 22 22 22 50 50 50
41888 - 90 90 90 26 26 26 2 2 6 2 2 6
41889 - 14 14 14 195 195 195 250 250 250 253 253 253
41890 -253 253 253 253 253 253 253 253 253 253 253 253
41891 -253 253 253 253 253 253 253 253 253 253 253 253
41892 -253 253 253 253 253 253 253 253 253 253 253 253
41893 -253 253 253 253 253 253 253 253 253 253 253 253
41894 -250 250 250 242 242 242 54 54 54 2 2 6
41895 - 2 2 6 2 2 6 2 2 6 2 2 6
41896 - 2 2 6 2 2 6 2 2 6 38 38 38
41897 - 86 86 86 50 50 50 22 22 22 6 6 6
41898 - 0 0 0 0 0 0 0 0 0 0 0 0
41899 - 0 0 0 0 0 0 0 0 0 0 0 0
41900 - 0 0 0 0 0 0 0 0 0 0 0 0
41901 - 0 0 0 0 0 0 0 0 0 0 0 0
41902 - 0 0 0 0 0 0 0 0 0 0 0 0
41903 - 0 0 0 0 0 0 0 0 0 0 0 0
41904 - 0 0 0 0 0 0 0 0 0 0 0 0
41905 - 0 0 0 0 0 0 0 0 0 0 0 0
41906 - 0 0 0 0 0 0 0 0 0 0 0 0
41907 - 6 6 6 14 14 14 38 38 38 82 82 82
41908 - 34 34 34 2 2 6 2 2 6 2 2 6
41909 - 42 42 42 195 195 195 246 246 246 253 253 253
41910 -253 253 253 253 253 253 253 253 253 250 250 250
41911 -242 242 242 242 242 242 250 250 250 253 253 253
41912 -253 253 253 253 253 253 253 253 253 253 253 253
41913 -253 253 253 250 250 250 246 246 246 238 238 238
41914 -226 226 226 231 231 231 101 101 101 6 6 6
41915 - 2 2 6 2 2 6 2 2 6 2 2 6
41916 - 2 2 6 2 2 6 2 2 6 2 2 6
41917 - 38 38 38 82 82 82 42 42 42 14 14 14
41918 - 6 6 6 0 0 0 0 0 0 0 0 0
41919 - 0 0 0 0 0 0 0 0 0 0 0 0
41920 - 0 0 0 0 0 0 0 0 0 0 0 0
41921 - 0 0 0 0 0 0 0 0 0 0 0 0
41922 - 0 0 0 0 0 0 0 0 0 0 0 0
41923 - 0 0 0 0 0 0 0 0 0 0 0 0
41924 - 0 0 0 0 0 0 0 0 0 0 0 0
41925 - 0 0 0 0 0 0 0 0 0 0 0 0
41926 - 0 0 0 0 0 0 0 0 0 0 0 0
41927 - 10 10 10 26 26 26 62 62 62 66 66 66
41928 - 2 2 6 2 2 6 2 2 6 6 6 6
41929 - 70 70 70 170 170 170 206 206 206 234 234 234
41930 -246 246 246 250 250 250 250 250 250 238 238 238
41931 -226 226 226 231 231 231 238 238 238 250 250 250
41932 -250 250 250 250 250 250 246 246 246 231 231 231
41933 -214 214 214 206 206 206 202 202 202 202 202 202
41934 -198 198 198 202 202 202 182 182 182 18 18 18
41935 - 2 2 6 2 2 6 2 2 6 2 2 6
41936 - 2 2 6 2 2 6 2 2 6 2 2 6
41937 - 2 2 6 62 62 62 66 66 66 30 30 30
41938 - 10 10 10 0 0 0 0 0 0 0 0 0
41939 - 0 0 0 0 0 0 0 0 0 0 0 0
41940 - 0 0 0 0 0 0 0 0 0 0 0 0
41941 - 0 0 0 0 0 0 0 0 0 0 0 0
41942 - 0 0 0 0 0 0 0 0 0 0 0 0
41943 - 0 0 0 0 0 0 0 0 0 0 0 0
41944 - 0 0 0 0 0 0 0 0 0 0 0 0
41945 - 0 0 0 0 0 0 0 0 0 0 0 0
41946 - 0 0 0 0 0 0 0 0 0 0 0 0
41947 - 14 14 14 42 42 42 82 82 82 18 18 18
41948 - 2 2 6 2 2 6 2 2 6 10 10 10
41949 - 94 94 94 182 182 182 218 218 218 242 242 242
41950 -250 250 250 253 253 253 253 253 253 250 250 250
41951 -234 234 234 253 253 253 253 253 253 253 253 253
41952 -253 253 253 253 253 253 253 253 253 246 246 246
41953 -238 238 238 226 226 226 210 210 210 202 202 202
41954 -195 195 195 195 195 195 210 210 210 158 158 158
41955 - 6 6 6 14 14 14 50 50 50 14 14 14
41956 - 2 2 6 2 2 6 2 2 6 2 2 6
41957 - 2 2 6 6 6 6 86 86 86 46 46 46
41958 - 18 18 18 6 6 6 0 0 0 0 0 0
41959 - 0 0 0 0 0 0 0 0 0 0 0 0
41960 - 0 0 0 0 0 0 0 0 0 0 0 0
41961 - 0 0 0 0 0 0 0 0 0 0 0 0
41962 - 0 0 0 0 0 0 0 0 0 0 0 0
41963 - 0 0 0 0 0 0 0 0 0 0 0 0
41964 - 0 0 0 0 0 0 0 0 0 0 0 0
41965 - 0 0 0 0 0 0 0 0 0 0 0 0
41966 - 0 0 0 0 0 0 0 0 0 6 6 6
41967 - 22 22 22 54 54 54 70 70 70 2 2 6
41968 - 2 2 6 10 10 10 2 2 6 22 22 22
41969 -166 166 166 231 231 231 250 250 250 253 253 253
41970 -253 253 253 253 253 253 253 253 253 250 250 250
41971 -242 242 242 253 253 253 253 253 253 253 253 253
41972 -253 253 253 253 253 253 253 253 253 253 253 253
41973 -253 253 253 253 253 253 253 253 253 246 246 246
41974 -231 231 231 206 206 206 198 198 198 226 226 226
41975 - 94 94 94 2 2 6 6 6 6 38 38 38
41976 - 30 30 30 2 2 6 2 2 6 2 2 6
41977 - 2 2 6 2 2 6 62 62 62 66 66 66
41978 - 26 26 26 10 10 10 0 0 0 0 0 0
41979 - 0 0 0 0 0 0 0 0 0 0 0 0
41980 - 0 0 0 0 0 0 0 0 0 0 0 0
41981 - 0 0 0 0 0 0 0 0 0 0 0 0
41982 - 0 0 0 0 0 0 0 0 0 0 0 0
41983 - 0 0 0 0 0 0 0 0 0 0 0 0
41984 - 0 0 0 0 0 0 0 0 0 0 0 0
41985 - 0 0 0 0 0 0 0 0 0 0 0 0
41986 - 0 0 0 0 0 0 0 0 0 10 10 10
41987 - 30 30 30 74 74 74 50 50 50 2 2 6
41988 - 26 26 26 26 26 26 2 2 6 106 106 106
41989 -238 238 238 253 253 253 253 253 253 253 253 253
41990 -253 253 253 253 253 253 253 253 253 253 253 253
41991 -253 253 253 253 253 253 253 253 253 253 253 253
41992 -253 253 253 253 253 253 253 253 253 253 253 253
41993 -253 253 253 253 253 253 253 253 253 253 253 253
41994 -253 253 253 246 246 246 218 218 218 202 202 202
41995 -210 210 210 14 14 14 2 2 6 2 2 6
41996 - 30 30 30 22 22 22 2 2 6 2 2 6
41997 - 2 2 6 2 2 6 18 18 18 86 86 86
41998 - 42 42 42 14 14 14 0 0 0 0 0 0
41999 - 0 0 0 0 0 0 0 0 0 0 0 0
42000 - 0 0 0 0 0 0 0 0 0 0 0 0
42001 - 0 0 0 0 0 0 0 0 0 0 0 0
42002 - 0 0 0 0 0 0 0 0 0 0 0 0
42003 - 0 0 0 0 0 0 0 0 0 0 0 0
42004 - 0 0 0 0 0 0 0 0 0 0 0 0
42005 - 0 0 0 0 0 0 0 0 0 0 0 0
42006 - 0 0 0 0 0 0 0 0 0 14 14 14
42007 - 42 42 42 90 90 90 22 22 22 2 2 6
42008 - 42 42 42 2 2 6 18 18 18 218 218 218
42009 -253 253 253 253 253 253 253 253 253 253 253 253
42010 -253 253 253 253 253 253 253 253 253 253 253 253
42011 -253 253 253 253 253 253 253 253 253 253 253 253
42012 -253 253 253 253 253 253 253 253 253 253 253 253
42013 -253 253 253 253 253 253 253 253 253 253 253 253
42014 -253 253 253 253 253 253 250 250 250 221 221 221
42015 -218 218 218 101 101 101 2 2 6 14 14 14
42016 - 18 18 18 38 38 38 10 10 10 2 2 6
42017 - 2 2 6 2 2 6 2 2 6 78 78 78
42018 - 58 58 58 22 22 22 6 6 6 0 0 0
42019 - 0 0 0 0 0 0 0 0 0 0 0 0
42020 - 0 0 0 0 0 0 0 0 0 0 0 0
42021 - 0 0 0 0 0 0 0 0 0 0 0 0
42022 - 0 0 0 0 0 0 0 0 0 0 0 0
42023 - 0 0 0 0 0 0 0 0 0 0 0 0
42024 - 0 0 0 0 0 0 0 0 0 0 0 0
42025 - 0 0 0 0 0 0 0 0 0 0 0 0
42026 - 0 0 0 0 0 0 6 6 6 18 18 18
42027 - 54 54 54 82 82 82 2 2 6 26 26 26
42028 - 22 22 22 2 2 6 123 123 123 253 253 253
42029 -253 253 253 253 253 253 253 253 253 253 253 253
42030 -253 253 253 253 253 253 253 253 253 253 253 253
42031 -253 253 253 253 253 253 253 253 253 253 253 253
42032 -253 253 253 253 253 253 253 253 253 253 253 253
42033 -253 253 253 253 253 253 253 253 253 253 253 253
42034 -253 253 253 253 253 253 253 253 253 250 250 250
42035 -238 238 238 198 198 198 6 6 6 38 38 38
42036 - 58 58 58 26 26 26 38 38 38 2 2 6
42037 - 2 2 6 2 2 6 2 2 6 46 46 46
42038 - 78 78 78 30 30 30 10 10 10 0 0 0
42039 - 0 0 0 0 0 0 0 0 0 0 0 0
42040 - 0 0 0 0 0 0 0 0 0 0 0 0
42041 - 0 0 0 0 0 0 0 0 0 0 0 0
42042 - 0 0 0 0 0 0 0 0 0 0 0 0
42043 - 0 0 0 0 0 0 0 0 0 0 0 0
42044 - 0 0 0 0 0 0 0 0 0 0 0 0
42045 - 0 0 0 0 0 0 0 0 0 0 0 0
42046 - 0 0 0 0 0 0 10 10 10 30 30 30
42047 - 74 74 74 58 58 58 2 2 6 42 42 42
42048 - 2 2 6 22 22 22 231 231 231 253 253 253
42049 -253 253 253 253 253 253 253 253 253 253 253 253
42050 -253 253 253 253 253 253 253 253 253 250 250 250
42051 -253 253 253 253 253 253 253 253 253 253 253 253
42052 -253 253 253 253 253 253 253 253 253 253 253 253
42053 -253 253 253 253 253 253 253 253 253 253 253 253
42054 -253 253 253 253 253 253 253 253 253 253 253 253
42055 -253 253 253 246 246 246 46 46 46 38 38 38
42056 - 42 42 42 14 14 14 38 38 38 14 14 14
42057 - 2 2 6 2 2 6 2 2 6 6 6 6
42058 - 86 86 86 46 46 46 14 14 14 0 0 0
42059 - 0 0 0 0 0 0 0 0 0 0 0 0
42060 - 0 0 0 0 0 0 0 0 0 0 0 0
42061 - 0 0 0 0 0 0 0 0 0 0 0 0
42062 - 0 0 0 0 0 0 0 0 0 0 0 0
42063 - 0 0 0 0 0 0 0 0 0 0 0 0
42064 - 0 0 0 0 0 0 0 0 0 0 0 0
42065 - 0 0 0 0 0 0 0 0 0 0 0 0
42066 - 0 0 0 6 6 6 14 14 14 42 42 42
42067 - 90 90 90 18 18 18 18 18 18 26 26 26
42068 - 2 2 6 116 116 116 253 253 253 253 253 253
42069 -253 253 253 253 253 253 253 253 253 253 253 253
42070 -253 253 253 253 253 253 250 250 250 238 238 238
42071 -253 253 253 253 253 253 253 253 253 253 253 253
42072 -253 253 253 253 253 253 253 253 253 253 253 253
42073 -253 253 253 253 253 253 253 253 253 253 253 253
42074 -253 253 253 253 253 253 253 253 253 253 253 253
42075 -253 253 253 253 253 253 94 94 94 6 6 6
42076 - 2 2 6 2 2 6 10 10 10 34 34 34
42077 - 2 2 6 2 2 6 2 2 6 2 2 6
42078 - 74 74 74 58 58 58 22 22 22 6 6 6
42079 - 0 0 0 0 0 0 0 0 0 0 0 0
42080 - 0 0 0 0 0 0 0 0 0 0 0 0
42081 - 0 0 0 0 0 0 0 0 0 0 0 0
42082 - 0 0 0 0 0 0 0 0 0 0 0 0
42083 - 0 0 0 0 0 0 0 0 0 0 0 0
42084 - 0 0 0 0 0 0 0 0 0 0 0 0
42085 - 0 0 0 0 0 0 0 0 0 0 0 0
42086 - 0 0 0 10 10 10 26 26 26 66 66 66
42087 - 82 82 82 2 2 6 38 38 38 6 6 6
42088 - 14 14 14 210 210 210 253 253 253 253 253 253
42089 -253 253 253 253 253 253 253 253 253 253 253 253
42090 -253 253 253 253 253 253 246 246 246 242 242 242
42091 -253 253 253 253 253 253 253 253 253 253 253 253
42092 -253 253 253 253 253 253 253 253 253 253 253 253
42093 -253 253 253 253 253 253 253 253 253 253 253 253
42094 -253 253 253 253 253 253 253 253 253 253 253 253
42095 -253 253 253 253 253 253 144 144 144 2 2 6
42096 - 2 2 6 2 2 6 2 2 6 46 46 46
42097 - 2 2 6 2 2 6 2 2 6 2 2 6
42098 - 42 42 42 74 74 74 30 30 30 10 10 10
42099 - 0 0 0 0 0 0 0 0 0 0 0 0
42100 - 0 0 0 0 0 0 0 0 0 0 0 0
42101 - 0 0 0 0 0 0 0 0 0 0 0 0
42102 - 0 0 0 0 0 0 0 0 0 0 0 0
42103 - 0 0 0 0 0 0 0 0 0 0 0 0
42104 - 0 0 0 0 0 0 0 0 0 0 0 0
42105 - 0 0 0 0 0 0 0 0 0 0 0 0
42106 - 6 6 6 14 14 14 42 42 42 90 90 90
42107 - 26 26 26 6 6 6 42 42 42 2 2 6
42108 - 74 74 74 250 250 250 253 253 253 253 253 253
42109 -253 253 253 253 253 253 253 253 253 253 253 253
42110 -253 253 253 253 253 253 242 242 242 242 242 242
42111 -253 253 253 253 253 253 253 253 253 253 253 253
42112 -253 253 253 253 253 253 253 253 253 253 253 253
42113 -253 253 253 253 253 253 253 253 253 253 253 253
42114 -253 253 253 253 253 253 253 253 253 253 253 253
42115 -253 253 253 253 253 253 182 182 182 2 2 6
42116 - 2 2 6 2 2 6 2 2 6 46 46 46
42117 - 2 2 6 2 2 6 2 2 6 2 2 6
42118 - 10 10 10 86 86 86 38 38 38 10 10 10
42119 - 0 0 0 0 0 0 0 0 0 0 0 0
42120 - 0 0 0 0 0 0 0 0 0 0 0 0
42121 - 0 0 0 0 0 0 0 0 0 0 0 0
42122 - 0 0 0 0 0 0 0 0 0 0 0 0
42123 - 0 0 0 0 0 0 0 0 0 0 0 0
42124 - 0 0 0 0 0 0 0 0 0 0 0 0
42125 - 0 0 0 0 0 0 0 0 0 0 0 0
42126 - 10 10 10 26 26 26 66 66 66 82 82 82
42127 - 2 2 6 22 22 22 18 18 18 2 2 6
42128 -149 149 149 253 253 253 253 253 253 253 253 253
42129 -253 253 253 253 253 253 253 253 253 253 253 253
42130 -253 253 253 253 253 253 234 234 234 242 242 242
42131 -253 253 253 253 253 253 253 253 253 253 253 253
42132 -253 253 253 253 253 253 253 253 253 253 253 253
42133 -253 253 253 253 253 253 253 253 253 253 253 253
42134 -253 253 253 253 253 253 253 253 253 253 253 253
42135 -253 253 253 253 253 253 206 206 206 2 2 6
42136 - 2 2 6 2 2 6 2 2 6 38 38 38
42137 - 2 2 6 2 2 6 2 2 6 2 2 6
42138 - 6 6 6 86 86 86 46 46 46 14 14 14
42139 - 0 0 0 0 0 0 0 0 0 0 0 0
42140 - 0 0 0 0 0 0 0 0 0 0 0 0
42141 - 0 0 0 0 0 0 0 0 0 0 0 0
42142 - 0 0 0 0 0 0 0 0 0 0 0 0
42143 - 0 0 0 0 0 0 0 0 0 0 0 0
42144 - 0 0 0 0 0 0 0 0 0 0 0 0
42145 - 0 0 0 0 0 0 0 0 0 6 6 6
42146 - 18 18 18 46 46 46 86 86 86 18 18 18
42147 - 2 2 6 34 34 34 10 10 10 6 6 6
42148 -210 210 210 253 253 253 253 253 253 253 253 253
42149 -253 253 253 253 253 253 253 253 253 253 253 253
42150 -253 253 253 253 253 253 234 234 234 242 242 242
42151 -253 253 253 253 253 253 253 253 253 253 253 253
42152 -253 253 253 253 253 253 253 253 253 253 253 253
42153 -253 253 253 253 253 253 253 253 253 253 253 253
42154 -253 253 253 253 253 253 253 253 253 253 253 253
42155 -253 253 253 253 253 253 221 221 221 6 6 6
42156 - 2 2 6 2 2 6 6 6 6 30 30 30
42157 - 2 2 6 2 2 6 2 2 6 2 2 6
42158 - 2 2 6 82 82 82 54 54 54 18 18 18
42159 - 6 6 6 0 0 0 0 0 0 0 0 0
42160 - 0 0 0 0 0 0 0 0 0 0 0 0
42161 - 0 0 0 0 0 0 0 0 0 0 0 0
42162 - 0 0 0 0 0 0 0 0 0 0 0 0
42163 - 0 0 0 0 0 0 0 0 0 0 0 0
42164 - 0 0 0 0 0 0 0 0 0 0 0 0
42165 - 0 0 0 0 0 0 0 0 0 10 10 10
42166 - 26 26 26 66 66 66 62 62 62 2 2 6
42167 - 2 2 6 38 38 38 10 10 10 26 26 26
42168 -238 238 238 253 253 253 253 253 253 253 253 253
42169 -253 253 253 253 253 253 253 253 253 253 253 253
42170 -253 253 253 253 253 253 231 231 231 238 238 238
42171 -253 253 253 253 253 253 253 253 253 253 253 253
42172 -253 253 253 253 253 253 253 253 253 253 253 253
42173 -253 253 253 253 253 253 253 253 253 253 253 253
42174 -253 253 253 253 253 253 253 253 253 253 253 253
42175 -253 253 253 253 253 253 231 231 231 6 6 6
42176 - 2 2 6 2 2 6 10 10 10 30 30 30
42177 - 2 2 6 2 2 6 2 2 6 2 2 6
42178 - 2 2 6 66 66 66 58 58 58 22 22 22
42179 - 6 6 6 0 0 0 0 0 0 0 0 0
42180 - 0 0 0 0 0 0 0 0 0 0 0 0
42181 - 0 0 0 0 0 0 0 0 0 0 0 0
42182 - 0 0 0 0 0 0 0 0 0 0 0 0
42183 - 0 0 0 0 0 0 0 0 0 0 0 0
42184 - 0 0 0 0 0 0 0 0 0 0 0 0
42185 - 0 0 0 0 0 0 0 0 0 10 10 10
42186 - 38 38 38 78 78 78 6 6 6 2 2 6
42187 - 2 2 6 46 46 46 14 14 14 42 42 42
42188 -246 246 246 253 253 253 253 253 253 253 253 253
42189 -253 253 253 253 253 253 253 253 253 253 253 253
42190 -253 253 253 253 253 253 231 231 231 242 242 242
42191 -253 253 253 253 253 253 253 253 253 253 253 253
42192 -253 253 253 253 253 253 253 253 253 253 253 253
42193 -253 253 253 253 253 253 253 253 253 253 253 253
42194 -253 253 253 253 253 253 253 253 253 253 253 253
42195 -253 253 253 253 253 253 234 234 234 10 10 10
42196 - 2 2 6 2 2 6 22 22 22 14 14 14
42197 - 2 2 6 2 2 6 2 2 6 2 2 6
42198 - 2 2 6 66 66 66 62 62 62 22 22 22
42199 - 6 6 6 0 0 0 0 0 0 0 0 0
42200 - 0 0 0 0 0 0 0 0 0 0 0 0
42201 - 0 0 0 0 0 0 0 0 0 0 0 0
42202 - 0 0 0 0 0 0 0 0 0 0 0 0
42203 - 0 0 0 0 0 0 0 0 0 0 0 0
42204 - 0 0 0 0 0 0 0 0 0 0 0 0
42205 - 0 0 0 0 0 0 6 6 6 18 18 18
42206 - 50 50 50 74 74 74 2 2 6 2 2 6
42207 - 14 14 14 70 70 70 34 34 34 62 62 62
42208 -250 250 250 253 253 253 253 253 253 253 253 253
42209 -253 253 253 253 253 253 253 253 253 253 253 253
42210 -253 253 253 253 253 253 231 231 231 246 246 246
42211 -253 253 253 253 253 253 253 253 253 253 253 253
42212 -253 253 253 253 253 253 253 253 253 253 253 253
42213 -253 253 253 253 253 253 253 253 253 253 253 253
42214 -253 253 253 253 253 253 253 253 253 253 253 253
42215 -253 253 253 253 253 253 234 234 234 14 14 14
42216 - 2 2 6 2 2 6 30 30 30 2 2 6
42217 - 2 2 6 2 2 6 2 2 6 2 2 6
42218 - 2 2 6 66 66 66 62 62 62 22 22 22
42219 - 6 6 6 0 0 0 0 0 0 0 0 0
42220 - 0 0 0 0 0 0 0 0 0 0 0 0
42221 - 0 0 0 0 0 0 0 0 0 0 0 0
42222 - 0 0 0 0 0 0 0 0 0 0 0 0
42223 - 0 0 0 0 0 0 0 0 0 0 0 0
42224 - 0 0 0 0 0 0 0 0 0 0 0 0
42225 - 0 0 0 0 0 0 6 6 6 18 18 18
42226 - 54 54 54 62 62 62 2 2 6 2 2 6
42227 - 2 2 6 30 30 30 46 46 46 70 70 70
42228 -250 250 250 253 253 253 253 253 253 253 253 253
42229 -253 253 253 253 253 253 253 253 253 253 253 253
42230 -253 253 253 253 253 253 231 231 231 246 246 246
42231 -253 253 253 253 253 253 253 253 253 253 253 253
42232 -253 253 253 253 253 253 253 253 253 253 253 253
42233 -253 253 253 253 253 253 253 253 253 253 253 253
42234 -253 253 253 253 253 253 253 253 253 253 253 253
42235 -253 253 253 253 253 253 226 226 226 10 10 10
42236 - 2 2 6 6 6 6 30 30 30 2 2 6
42237 - 2 2 6 2 2 6 2 2 6 2 2 6
42238 - 2 2 6 66 66 66 58 58 58 22 22 22
42239 - 6 6 6 0 0 0 0 0 0 0 0 0
42240 - 0 0 0 0 0 0 0 0 0 0 0 0
42241 - 0 0 0 0 0 0 0 0 0 0 0 0
42242 - 0 0 0 0 0 0 0 0 0 0 0 0
42243 - 0 0 0 0 0 0 0 0 0 0 0 0
42244 - 0 0 0 0 0 0 0 0 0 0 0 0
42245 - 0 0 0 0 0 0 6 6 6 22 22 22
42246 - 58 58 58 62 62 62 2 2 6 2 2 6
42247 - 2 2 6 2 2 6 30 30 30 78 78 78
42248 -250 250 250 253 253 253 253 253 253 253 253 253
42249 -253 253 253 253 253 253 253 253 253 253 253 253
42250 -253 253 253 253 253 253 231 231 231 246 246 246
42251 -253 253 253 253 253 253 253 253 253 253 253 253
42252 -253 253 253 253 253 253 253 253 253 253 253 253
42253 -253 253 253 253 253 253 253 253 253 253 253 253
42254 -253 253 253 253 253 253 253 253 253 253 253 253
42255 -253 253 253 253 253 253 206 206 206 2 2 6
42256 - 22 22 22 34 34 34 18 14 6 22 22 22
42257 - 26 26 26 18 18 18 6 6 6 2 2 6
42258 - 2 2 6 82 82 82 54 54 54 18 18 18
42259 - 6 6 6 0 0 0 0 0 0 0 0 0
42260 - 0 0 0 0 0 0 0 0 0 0 0 0
42261 - 0 0 0 0 0 0 0 0 0 0 0 0
42262 - 0 0 0 0 0 0 0 0 0 0 0 0
42263 - 0 0 0 0 0 0 0 0 0 0 0 0
42264 - 0 0 0 0 0 0 0 0 0 0 0 0
42265 - 0 0 0 0 0 0 6 6 6 26 26 26
42266 - 62 62 62 106 106 106 74 54 14 185 133 11
42267 -210 162 10 121 92 8 6 6 6 62 62 62
42268 -238 238 238 253 253 253 253 253 253 253 253 253
42269 -253 253 253 253 253 253 253 253 253 253 253 253
42270 -253 253 253 253 253 253 231 231 231 246 246 246
42271 -253 253 253 253 253 253 253 253 253 253 253 253
42272 -253 253 253 253 253 253 253 253 253 253 253 253
42273 -253 253 253 253 253 253 253 253 253 253 253 253
42274 -253 253 253 253 253 253 253 253 253 253 253 253
42275 -253 253 253 253 253 253 158 158 158 18 18 18
42276 - 14 14 14 2 2 6 2 2 6 2 2 6
42277 - 6 6 6 18 18 18 66 66 66 38 38 38
42278 - 6 6 6 94 94 94 50 50 50 18 18 18
42279 - 6 6 6 0 0 0 0 0 0 0 0 0
42280 - 0 0 0 0 0 0 0 0 0 0 0 0
42281 - 0 0 0 0 0 0 0 0 0 0 0 0
42282 - 0 0 0 0 0 0 0 0 0 0 0 0
42283 - 0 0 0 0 0 0 0 0 0 0 0 0
42284 - 0 0 0 0 0 0 0 0 0 6 6 6
42285 - 10 10 10 10 10 10 18 18 18 38 38 38
42286 - 78 78 78 142 134 106 216 158 10 242 186 14
42287 -246 190 14 246 190 14 156 118 10 10 10 10
42288 - 90 90 90 238 238 238 253 253 253 253 253 253
42289 -253 253 253 253 253 253 253 253 253 253 253 253
42290 -253 253 253 253 253 253 231 231 231 250 250 250
42291 -253 253 253 253 253 253 253 253 253 253 253 253
42292 -253 253 253 253 253 253 253 253 253 253 253 253
42293 -253 253 253 253 253 253 253 253 253 253 253 253
42294 -253 253 253 253 253 253 253 253 253 246 230 190
42295 -238 204 91 238 204 91 181 142 44 37 26 9
42296 - 2 2 6 2 2 6 2 2 6 2 2 6
42297 - 2 2 6 2 2 6 38 38 38 46 46 46
42298 - 26 26 26 106 106 106 54 54 54 18 18 18
42299 - 6 6 6 0 0 0 0 0 0 0 0 0
42300 - 0 0 0 0 0 0 0 0 0 0 0 0
42301 - 0 0 0 0 0 0 0 0 0 0 0 0
42302 - 0 0 0 0 0 0 0 0 0 0 0 0
42303 - 0 0 0 0 0 0 0 0 0 0 0 0
42304 - 0 0 0 6 6 6 14 14 14 22 22 22
42305 - 30 30 30 38 38 38 50 50 50 70 70 70
42306 -106 106 106 190 142 34 226 170 11 242 186 14
42307 -246 190 14 246 190 14 246 190 14 154 114 10
42308 - 6 6 6 74 74 74 226 226 226 253 253 253
42309 -253 253 253 253 253 253 253 253 253 253 253 253
42310 -253 253 253 253 253 253 231 231 231 250 250 250
42311 -253 253 253 253 253 253 253 253 253 253 253 253
42312 -253 253 253 253 253 253 253 253 253 253 253 253
42313 -253 253 253 253 253 253 253 253 253 253 253 253
42314 -253 253 253 253 253 253 253 253 253 228 184 62
42315 -241 196 14 241 208 19 232 195 16 38 30 10
42316 - 2 2 6 2 2 6 2 2 6 2 2 6
42317 - 2 2 6 6 6 6 30 30 30 26 26 26
42318 -203 166 17 154 142 90 66 66 66 26 26 26
42319 - 6 6 6 0 0 0 0 0 0 0 0 0
42320 - 0 0 0 0 0 0 0 0 0 0 0 0
42321 - 0 0 0 0 0 0 0 0 0 0 0 0
42322 - 0 0 0 0 0 0 0 0 0 0 0 0
42323 - 0 0 0 0 0 0 0 0 0 0 0 0
42324 - 6 6 6 18 18 18 38 38 38 58 58 58
42325 - 78 78 78 86 86 86 101 101 101 123 123 123
42326 -175 146 61 210 150 10 234 174 13 246 186 14
42327 -246 190 14 246 190 14 246 190 14 238 190 10
42328 -102 78 10 2 2 6 46 46 46 198 198 198
42329 -253 253 253 253 253 253 253 253 253 253 253 253
42330 -253 253 253 253 253 253 234 234 234 242 242 242
42331 -253 253 253 253 253 253 253 253 253 253 253 253
42332 -253 253 253 253 253 253 253 253 253 253 253 253
42333 -253 253 253 253 253 253 253 253 253 253 253 253
42334 -253 253 253 253 253 253 253 253 253 224 178 62
42335 -242 186 14 241 196 14 210 166 10 22 18 6
42336 - 2 2 6 2 2 6 2 2 6 2 2 6
42337 - 2 2 6 2 2 6 6 6 6 121 92 8
42338 -238 202 15 232 195 16 82 82 82 34 34 34
42339 - 10 10 10 0 0 0 0 0 0 0 0 0
42340 - 0 0 0 0 0 0 0 0 0 0 0 0
42341 - 0 0 0 0 0 0 0 0 0 0 0 0
42342 - 0 0 0 0 0 0 0 0 0 0 0 0
42343 - 0 0 0 0 0 0 0 0 0 0 0 0
42344 - 14 14 14 38 38 38 70 70 70 154 122 46
42345 -190 142 34 200 144 11 197 138 11 197 138 11
42346 -213 154 11 226 170 11 242 186 14 246 190 14
42347 -246 190 14 246 190 14 246 190 14 246 190 14
42348 -225 175 15 46 32 6 2 2 6 22 22 22
42349 -158 158 158 250 250 250 253 253 253 253 253 253
42350 -253 253 253 253 253 253 253 253 253 253 253 253
42351 -253 253 253 253 253 253 253 253 253 253 253 253
42352 -253 253 253 253 253 253 253 253 253 253 253 253
42353 -253 253 253 253 253 253 253 253 253 253 253 253
42354 -253 253 253 250 250 250 242 242 242 224 178 62
42355 -239 182 13 236 186 11 213 154 11 46 32 6
42356 - 2 2 6 2 2 6 2 2 6 2 2 6
42357 - 2 2 6 2 2 6 61 42 6 225 175 15
42358 -238 190 10 236 186 11 112 100 78 42 42 42
42359 - 14 14 14 0 0 0 0 0 0 0 0 0
42360 - 0 0 0 0 0 0 0 0 0 0 0 0
42361 - 0 0 0 0 0 0 0 0 0 0 0 0
42362 - 0 0 0 0 0 0 0 0 0 0 0 0
42363 - 0 0 0 0 0 0 0 0 0 6 6 6
42364 - 22 22 22 54 54 54 154 122 46 213 154 11
42365 -226 170 11 230 174 11 226 170 11 226 170 11
42366 -236 178 12 242 186 14 246 190 14 246 190 14
42367 -246 190 14 246 190 14 246 190 14 246 190 14
42368 -241 196 14 184 144 12 10 10 10 2 2 6
42369 - 6 6 6 116 116 116 242 242 242 253 253 253
42370 -253 253 253 253 253 253 253 253 253 253 253 253
42371 -253 253 253 253 253 253 253 253 253 253 253 253
42372 -253 253 253 253 253 253 253 253 253 253 253 253
42373 -253 253 253 253 253 253 253 253 253 253 253 253
42374 -253 253 253 231 231 231 198 198 198 214 170 54
42375 -236 178 12 236 178 12 210 150 10 137 92 6
42376 - 18 14 6 2 2 6 2 2 6 2 2 6
42377 - 6 6 6 70 47 6 200 144 11 236 178 12
42378 -239 182 13 239 182 13 124 112 88 58 58 58
42379 - 22 22 22 6 6 6 0 0 0 0 0 0
42380 - 0 0 0 0 0 0 0 0 0 0 0 0
42381 - 0 0 0 0 0 0 0 0 0 0 0 0
42382 - 0 0 0 0 0 0 0 0 0 0 0 0
42383 - 0 0 0 0 0 0 0 0 0 10 10 10
42384 - 30 30 30 70 70 70 180 133 36 226 170 11
42385 -239 182 13 242 186 14 242 186 14 246 186 14
42386 -246 190 14 246 190 14 246 190 14 246 190 14
42387 -246 190 14 246 190 14 246 190 14 246 190 14
42388 -246 190 14 232 195 16 98 70 6 2 2 6
42389 - 2 2 6 2 2 6 66 66 66 221 221 221
42390 -253 253 253 253 253 253 253 253 253 253 253 253
42391 -253 253 253 253 253 253 253 253 253 253 253 253
42392 -253 253 253 253 253 253 253 253 253 253 253 253
42393 -253 253 253 253 253 253 253 253 253 253 253 253
42394 -253 253 253 206 206 206 198 198 198 214 166 58
42395 -230 174 11 230 174 11 216 158 10 192 133 9
42396 -163 110 8 116 81 8 102 78 10 116 81 8
42397 -167 114 7 197 138 11 226 170 11 239 182 13
42398 -242 186 14 242 186 14 162 146 94 78 78 78
42399 - 34 34 34 14 14 14 6 6 6 0 0 0
42400 - 0 0 0 0 0 0 0 0 0 0 0 0
42401 - 0 0 0 0 0 0 0 0 0 0 0 0
42402 - 0 0 0 0 0 0 0 0 0 0 0 0
42403 - 0 0 0 0 0 0 0 0 0 6 6 6
42404 - 30 30 30 78 78 78 190 142 34 226 170 11
42405 -239 182 13 246 190 14 246 190 14 246 190 14
42406 -246 190 14 246 190 14 246 190 14 246 190 14
42407 -246 190 14 246 190 14 246 190 14 246 190 14
42408 -246 190 14 241 196 14 203 166 17 22 18 6
42409 - 2 2 6 2 2 6 2 2 6 38 38 38
42410 -218 218 218 253 253 253 253 253 253 253 253 253
42411 -253 253 253 253 253 253 253 253 253 253 253 253
42412 -253 253 253 253 253 253 253 253 253 253 253 253
42413 -253 253 253 253 253 253 253 253 253 253 253 253
42414 -250 250 250 206 206 206 198 198 198 202 162 69
42415 -226 170 11 236 178 12 224 166 10 210 150 10
42416 -200 144 11 197 138 11 192 133 9 197 138 11
42417 -210 150 10 226 170 11 242 186 14 246 190 14
42418 -246 190 14 246 186 14 225 175 15 124 112 88
42419 - 62 62 62 30 30 30 14 14 14 6 6 6
42420 - 0 0 0 0 0 0 0 0 0 0 0 0
42421 - 0 0 0 0 0 0 0 0 0 0 0 0
42422 - 0 0 0 0 0 0 0 0 0 0 0 0
42423 - 0 0 0 0 0 0 0 0 0 10 10 10
42424 - 30 30 30 78 78 78 174 135 50 224 166 10
42425 -239 182 13 246 190 14 246 190 14 246 190 14
42426 -246 190 14 246 190 14 246 190 14 246 190 14
42427 -246 190 14 246 190 14 246 190 14 246 190 14
42428 -246 190 14 246 190 14 241 196 14 139 102 15
42429 - 2 2 6 2 2 6 2 2 6 2 2 6
42430 - 78 78 78 250 250 250 253 253 253 253 253 253
42431 -253 253 253 253 253 253 253 253 253 253 253 253
42432 -253 253 253 253 253 253 253 253 253 253 253 253
42433 -253 253 253 253 253 253 253 253 253 253 253 253
42434 -250 250 250 214 214 214 198 198 198 190 150 46
42435 -219 162 10 236 178 12 234 174 13 224 166 10
42436 -216 158 10 213 154 11 213 154 11 216 158 10
42437 -226 170 11 239 182 13 246 190 14 246 190 14
42438 -246 190 14 246 190 14 242 186 14 206 162 42
42439 -101 101 101 58 58 58 30 30 30 14 14 14
42440 - 6 6 6 0 0 0 0 0 0 0 0 0
42441 - 0 0 0 0 0 0 0 0 0 0 0 0
42442 - 0 0 0 0 0 0 0 0 0 0 0 0
42443 - 0 0 0 0 0 0 0 0 0 10 10 10
42444 - 30 30 30 74 74 74 174 135 50 216 158 10
42445 -236 178 12 246 190 14 246 190 14 246 190 14
42446 -246 190 14 246 190 14 246 190 14 246 190 14
42447 -246 190 14 246 190 14 246 190 14 246 190 14
42448 -246 190 14 246 190 14 241 196 14 226 184 13
42449 - 61 42 6 2 2 6 2 2 6 2 2 6
42450 - 22 22 22 238 238 238 253 253 253 253 253 253
42451 -253 253 253 253 253 253 253 253 253 253 253 253
42452 -253 253 253 253 253 253 253 253 253 253 253 253
42453 -253 253 253 253 253 253 253 253 253 253 253 253
42454 -253 253 253 226 226 226 187 187 187 180 133 36
42455 -216 158 10 236 178 12 239 182 13 236 178 12
42456 -230 174 11 226 170 11 226 170 11 230 174 11
42457 -236 178 12 242 186 14 246 190 14 246 190 14
42458 -246 190 14 246 190 14 246 186 14 239 182 13
42459 -206 162 42 106 106 106 66 66 66 34 34 34
42460 - 14 14 14 6 6 6 0 0 0 0 0 0
42461 - 0 0 0 0 0 0 0 0 0 0 0 0
42462 - 0 0 0 0 0 0 0 0 0 0 0 0
42463 - 0 0 0 0 0 0 0 0 0 6 6 6
42464 - 26 26 26 70 70 70 163 133 67 213 154 11
42465 -236 178 12 246 190 14 246 190 14 246 190 14
42466 -246 190 14 246 190 14 246 190 14 246 190 14
42467 -246 190 14 246 190 14 246 190 14 246 190 14
42468 -246 190 14 246 190 14 246 190 14 241 196 14
42469 -190 146 13 18 14 6 2 2 6 2 2 6
42470 - 46 46 46 246 246 246 253 253 253 253 253 253
42471 -253 253 253 253 253 253 253 253 253 253 253 253
42472 -253 253 253 253 253 253 253 253 253 253 253 253
42473 -253 253 253 253 253 253 253 253 253 253 253 253
42474 -253 253 253 221 221 221 86 86 86 156 107 11
42475 -216 158 10 236 178 12 242 186 14 246 186 14
42476 -242 186 14 239 182 13 239 182 13 242 186 14
42477 -242 186 14 246 186 14 246 190 14 246 190 14
42478 -246 190 14 246 190 14 246 190 14 246 190 14
42479 -242 186 14 225 175 15 142 122 72 66 66 66
42480 - 30 30 30 10 10 10 0 0 0 0 0 0
42481 - 0 0 0 0 0 0 0 0 0 0 0 0
42482 - 0 0 0 0 0 0 0 0 0 0 0 0
42483 - 0 0 0 0 0 0 0 0 0 6 6 6
42484 - 26 26 26 70 70 70 163 133 67 210 150 10
42485 -236 178 12 246 190 14 246 190 14 246 190 14
42486 -246 190 14 246 190 14 246 190 14 246 190 14
42487 -246 190 14 246 190 14 246 190 14 246 190 14
42488 -246 190 14 246 190 14 246 190 14 246 190 14
42489 -232 195 16 121 92 8 34 34 34 106 106 106
42490 -221 221 221 253 253 253 253 253 253 253 253 253
42491 -253 253 253 253 253 253 253 253 253 253 253 253
42492 -253 253 253 253 253 253 253 253 253 253 253 253
42493 -253 253 253 253 253 253 253 253 253 253 253 253
42494 -242 242 242 82 82 82 18 14 6 163 110 8
42495 -216 158 10 236 178 12 242 186 14 246 190 14
42496 -246 190 14 246 190 14 246 190 14 246 190 14
42497 -246 190 14 246 190 14 246 190 14 246 190 14
42498 -246 190 14 246 190 14 246 190 14 246 190 14
42499 -246 190 14 246 190 14 242 186 14 163 133 67
42500 - 46 46 46 18 18 18 6 6 6 0 0 0
42501 - 0 0 0 0 0 0 0 0 0 0 0 0
42502 - 0 0 0 0 0 0 0 0 0 0 0 0
42503 - 0 0 0 0 0 0 0 0 0 10 10 10
42504 - 30 30 30 78 78 78 163 133 67 210 150 10
42505 -236 178 12 246 186 14 246 190 14 246 190 14
42506 -246 190 14 246 190 14 246 190 14 246 190 14
42507 -246 190 14 246 190 14 246 190 14 246 190 14
42508 -246 190 14 246 190 14 246 190 14 246 190 14
42509 -241 196 14 215 174 15 190 178 144 253 253 253
42510 -253 253 253 253 253 253 253 253 253 253 253 253
42511 -253 253 253 253 253 253 253 253 253 253 253 253
42512 -253 253 253 253 253 253 253 253 253 253 253 253
42513 -253 253 253 253 253 253 253 253 253 218 218 218
42514 - 58 58 58 2 2 6 22 18 6 167 114 7
42515 -216 158 10 236 178 12 246 186 14 246 190 14
42516 -246 190 14 246 190 14 246 190 14 246 190 14
42517 -246 190 14 246 190 14 246 190 14 246 190 14
42518 -246 190 14 246 190 14 246 190 14 246 190 14
42519 -246 190 14 246 186 14 242 186 14 190 150 46
42520 - 54 54 54 22 22 22 6 6 6 0 0 0
42521 - 0 0 0 0 0 0 0 0 0 0 0 0
42522 - 0 0 0 0 0 0 0 0 0 0 0 0
42523 - 0 0 0 0 0 0 0 0 0 14 14 14
42524 - 38 38 38 86 86 86 180 133 36 213 154 11
42525 -236 178 12 246 186 14 246 190 14 246 190 14
42526 -246 190 14 246 190 14 246 190 14 246 190 14
42527 -246 190 14 246 190 14 246 190 14 246 190 14
42528 -246 190 14 246 190 14 246 190 14 246 190 14
42529 -246 190 14 232 195 16 190 146 13 214 214 214
42530 -253 253 253 253 253 253 253 253 253 253 253 253
42531 -253 253 253 253 253 253 253 253 253 253 253 253
42532 -253 253 253 253 253 253 253 253 253 253 253 253
42533 -253 253 253 250 250 250 170 170 170 26 26 26
42534 - 2 2 6 2 2 6 37 26 9 163 110 8
42535 -219 162 10 239 182 13 246 186 14 246 190 14
42536 -246 190 14 246 190 14 246 190 14 246 190 14
42537 -246 190 14 246 190 14 246 190 14 246 190 14
42538 -246 190 14 246 190 14 246 190 14 246 190 14
42539 -246 186 14 236 178 12 224 166 10 142 122 72
42540 - 46 46 46 18 18 18 6 6 6 0 0 0
42541 - 0 0 0 0 0 0 0 0 0 0 0 0
42542 - 0 0 0 0 0 0 0 0 0 0 0 0
42543 - 0 0 0 0 0 0 6 6 6 18 18 18
42544 - 50 50 50 109 106 95 192 133 9 224 166 10
42545 -242 186 14 246 190 14 246 190 14 246 190 14
42546 -246 190 14 246 190 14 246 190 14 246 190 14
42547 -246 190 14 246 190 14 246 190 14 246 190 14
42548 -246 190 14 246 190 14 246 190 14 246 190 14
42549 -242 186 14 226 184 13 210 162 10 142 110 46
42550 -226 226 226 253 253 253 253 253 253 253 253 253
42551 -253 253 253 253 253 253 253 253 253 253 253 253
42552 -253 253 253 253 253 253 253 253 253 253 253 253
42553 -198 198 198 66 66 66 2 2 6 2 2 6
42554 - 2 2 6 2 2 6 50 34 6 156 107 11
42555 -219 162 10 239 182 13 246 186 14 246 190 14
42556 -246 190 14 246 190 14 246 190 14 246 190 14
42557 -246 190 14 246 190 14 246 190 14 246 190 14
42558 -246 190 14 246 190 14 246 190 14 242 186 14
42559 -234 174 13 213 154 11 154 122 46 66 66 66
42560 - 30 30 30 10 10 10 0 0 0 0 0 0
42561 - 0 0 0 0 0 0 0 0 0 0 0 0
42562 - 0 0 0 0 0 0 0 0 0 0 0 0
42563 - 0 0 0 0 0 0 6 6 6 22 22 22
42564 - 58 58 58 154 121 60 206 145 10 234 174 13
42565 -242 186 14 246 186 14 246 190 14 246 190 14
42566 -246 190 14 246 190 14 246 190 14 246 190 14
42567 -246 190 14 246 190 14 246 190 14 246 190 14
42568 -246 190 14 246 190 14 246 190 14 246 190 14
42569 -246 186 14 236 178 12 210 162 10 163 110 8
42570 - 61 42 6 138 138 138 218 218 218 250 250 250
42571 -253 253 253 253 253 253 253 253 253 250 250 250
42572 -242 242 242 210 210 210 144 144 144 66 66 66
42573 - 6 6 6 2 2 6 2 2 6 2 2 6
42574 - 2 2 6 2 2 6 61 42 6 163 110 8
42575 -216 158 10 236 178 12 246 190 14 246 190 14
42576 -246 190 14 246 190 14 246 190 14 246 190 14
42577 -246 190 14 246 190 14 246 190 14 246 190 14
42578 -246 190 14 239 182 13 230 174 11 216 158 10
42579 -190 142 34 124 112 88 70 70 70 38 38 38
42580 - 18 18 18 6 6 6 0 0 0 0 0 0
42581 - 0 0 0 0 0 0 0 0 0 0 0 0
42582 - 0 0 0 0 0 0 0 0 0 0 0 0
42583 - 0 0 0 0 0 0 6 6 6 22 22 22
42584 - 62 62 62 168 124 44 206 145 10 224 166 10
42585 -236 178 12 239 182 13 242 186 14 242 186 14
42586 -246 186 14 246 190 14 246 190 14 246 190 14
42587 -246 190 14 246 190 14 246 190 14 246 190 14
42588 -246 190 14 246 190 14 246 190 14 246 190 14
42589 -246 190 14 236 178 12 216 158 10 175 118 6
42590 - 80 54 7 2 2 6 6 6 6 30 30 30
42591 - 54 54 54 62 62 62 50 50 50 38 38 38
42592 - 14 14 14 2 2 6 2 2 6 2 2 6
42593 - 2 2 6 2 2 6 2 2 6 2 2 6
42594 - 2 2 6 6 6 6 80 54 7 167 114 7
42595 -213 154 11 236 178 12 246 190 14 246 190 14
42596 -246 190 14 246 190 14 246 190 14 246 190 14
42597 -246 190 14 242 186 14 239 182 13 239 182 13
42598 -230 174 11 210 150 10 174 135 50 124 112 88
42599 - 82 82 82 54 54 54 34 34 34 18 18 18
42600 - 6 6 6 0 0 0 0 0 0 0 0 0
42601 - 0 0 0 0 0 0 0 0 0 0 0 0
42602 - 0 0 0 0 0 0 0 0 0 0 0 0
42603 - 0 0 0 0 0 0 6 6 6 18 18 18
42604 - 50 50 50 158 118 36 192 133 9 200 144 11
42605 -216 158 10 219 162 10 224 166 10 226 170 11
42606 -230 174 11 236 178 12 239 182 13 239 182 13
42607 -242 186 14 246 186 14 246 190 14 246 190 14
42608 -246 190 14 246 190 14 246 190 14 246 190 14
42609 -246 186 14 230 174 11 210 150 10 163 110 8
42610 -104 69 6 10 10 10 2 2 6 2 2 6
42611 - 2 2 6 2 2 6 2 2 6 2 2 6
42612 - 2 2 6 2 2 6 2 2 6 2 2 6
42613 - 2 2 6 2 2 6 2 2 6 2 2 6
42614 - 2 2 6 6 6 6 91 60 6 167 114 7
42615 -206 145 10 230 174 11 242 186 14 246 190 14
42616 -246 190 14 246 190 14 246 186 14 242 186 14
42617 -239 182 13 230 174 11 224 166 10 213 154 11
42618 -180 133 36 124 112 88 86 86 86 58 58 58
42619 - 38 38 38 22 22 22 10 10 10 6 6 6
42620 - 0 0 0 0 0 0 0 0 0 0 0 0
42621 - 0 0 0 0 0 0 0 0 0 0 0 0
42622 - 0 0 0 0 0 0 0 0 0 0 0 0
42623 - 0 0 0 0 0 0 0 0 0 14 14 14
42624 - 34 34 34 70 70 70 138 110 50 158 118 36
42625 -167 114 7 180 123 7 192 133 9 197 138 11
42626 -200 144 11 206 145 10 213 154 11 219 162 10
42627 -224 166 10 230 174 11 239 182 13 242 186 14
42628 -246 186 14 246 186 14 246 186 14 246 186 14
42629 -239 182 13 216 158 10 185 133 11 152 99 6
42630 -104 69 6 18 14 6 2 2 6 2 2 6
42631 - 2 2 6 2 2 6 2 2 6 2 2 6
42632 - 2 2 6 2 2 6 2 2 6 2 2 6
42633 - 2 2 6 2 2 6 2 2 6 2 2 6
42634 - 2 2 6 6 6 6 80 54 7 152 99 6
42635 -192 133 9 219 162 10 236 178 12 239 182 13
42636 -246 186 14 242 186 14 239 182 13 236 178 12
42637 -224 166 10 206 145 10 192 133 9 154 121 60
42638 - 94 94 94 62 62 62 42 42 42 22 22 22
42639 - 14 14 14 6 6 6 0 0 0 0 0 0
42640 - 0 0 0 0 0 0 0 0 0 0 0 0
42641 - 0 0 0 0 0 0 0 0 0 0 0 0
42642 - 0 0 0 0 0 0 0 0 0 0 0 0
42643 - 0 0 0 0 0 0 0 0 0 6 6 6
42644 - 18 18 18 34 34 34 58 58 58 78 78 78
42645 -101 98 89 124 112 88 142 110 46 156 107 11
42646 -163 110 8 167 114 7 175 118 6 180 123 7
42647 -185 133 11 197 138 11 210 150 10 219 162 10
42648 -226 170 11 236 178 12 236 178 12 234 174 13
42649 -219 162 10 197 138 11 163 110 8 130 83 6
42650 - 91 60 6 10 10 10 2 2 6 2 2 6
42651 - 18 18 18 38 38 38 38 38 38 38 38 38
42652 - 38 38 38 38 38 38 38 38 38 38 38 38
42653 - 38 38 38 38 38 38 26 26 26 2 2 6
42654 - 2 2 6 6 6 6 70 47 6 137 92 6
42655 -175 118 6 200 144 11 219 162 10 230 174 11
42656 -234 174 13 230 174 11 219 162 10 210 150 10
42657 -192 133 9 163 110 8 124 112 88 82 82 82
42658 - 50 50 50 30 30 30 14 14 14 6 6 6
42659 - 0 0 0 0 0 0 0 0 0 0 0 0
42660 - 0 0 0 0 0 0 0 0 0 0 0 0
42661 - 0 0 0 0 0 0 0 0 0 0 0 0
42662 - 0 0 0 0 0 0 0 0 0 0 0 0
42663 - 0 0 0 0 0 0 0 0 0 0 0 0
42664 - 6 6 6 14 14 14 22 22 22 34 34 34
42665 - 42 42 42 58 58 58 74 74 74 86 86 86
42666 -101 98 89 122 102 70 130 98 46 121 87 25
42667 -137 92 6 152 99 6 163 110 8 180 123 7
42668 -185 133 11 197 138 11 206 145 10 200 144 11
42669 -180 123 7 156 107 11 130 83 6 104 69 6
42670 - 50 34 6 54 54 54 110 110 110 101 98 89
42671 - 86 86 86 82 82 82 78 78 78 78 78 78
42672 - 78 78 78 78 78 78 78 78 78 78 78 78
42673 - 78 78 78 82 82 82 86 86 86 94 94 94
42674 -106 106 106 101 101 101 86 66 34 124 80 6
42675 -156 107 11 180 123 7 192 133 9 200 144 11
42676 -206 145 10 200 144 11 192 133 9 175 118 6
42677 -139 102 15 109 106 95 70 70 70 42 42 42
42678 - 22 22 22 10 10 10 0 0 0 0 0 0
42679 - 0 0 0 0 0 0 0 0 0 0 0 0
42680 - 0 0 0 0 0 0 0 0 0 0 0 0
42681 - 0 0 0 0 0 0 0 0 0 0 0 0
42682 - 0 0 0 0 0 0 0 0 0 0 0 0
42683 - 0 0 0 0 0 0 0 0 0 0 0 0
42684 - 0 0 0 0 0 0 6 6 6 10 10 10
42685 - 14 14 14 22 22 22 30 30 30 38 38 38
42686 - 50 50 50 62 62 62 74 74 74 90 90 90
42687 -101 98 89 112 100 78 121 87 25 124 80 6
42688 -137 92 6 152 99 6 152 99 6 152 99 6
42689 -138 86 6 124 80 6 98 70 6 86 66 30
42690 -101 98 89 82 82 82 58 58 58 46 46 46
42691 - 38 38 38 34 34 34 34 34 34 34 34 34
42692 - 34 34 34 34 34 34 34 34 34 34 34 34
42693 - 34 34 34 34 34 34 38 38 38 42 42 42
42694 - 54 54 54 82 82 82 94 86 76 91 60 6
42695 -134 86 6 156 107 11 167 114 7 175 118 6
42696 -175 118 6 167 114 7 152 99 6 121 87 25
42697 -101 98 89 62 62 62 34 34 34 18 18 18
42698 - 6 6 6 0 0 0 0 0 0 0 0 0
42699 - 0 0 0 0 0 0 0 0 0 0 0 0
42700 - 0 0 0 0 0 0 0 0 0 0 0 0
42701 - 0 0 0 0 0 0 0 0 0 0 0 0
42702 - 0 0 0 0 0 0 0 0 0 0 0 0
42703 - 0 0 0 0 0 0 0 0 0 0 0 0
42704 - 0 0 0 0 0 0 0 0 0 0 0 0
42705 - 0 0 0 6 6 6 6 6 6 10 10 10
42706 - 18 18 18 22 22 22 30 30 30 42 42 42
42707 - 50 50 50 66 66 66 86 86 86 101 98 89
42708 -106 86 58 98 70 6 104 69 6 104 69 6
42709 -104 69 6 91 60 6 82 62 34 90 90 90
42710 - 62 62 62 38 38 38 22 22 22 14 14 14
42711 - 10 10 10 10 10 10 10 10 10 10 10 10
42712 - 10 10 10 10 10 10 6 6 6 10 10 10
42713 - 10 10 10 10 10 10 10 10 10 14 14 14
42714 - 22 22 22 42 42 42 70 70 70 89 81 66
42715 - 80 54 7 104 69 6 124 80 6 137 92 6
42716 -134 86 6 116 81 8 100 82 52 86 86 86
42717 - 58 58 58 30 30 30 14 14 14 6 6 6
42718 - 0 0 0 0 0 0 0 0 0 0 0 0
42719 - 0 0 0 0 0 0 0 0 0 0 0 0
42720 - 0 0 0 0 0 0 0 0 0 0 0 0
42721 - 0 0 0 0 0 0 0 0 0 0 0 0
42722 - 0 0 0 0 0 0 0 0 0 0 0 0
42723 - 0 0 0 0 0 0 0 0 0 0 0 0
42724 - 0 0 0 0 0 0 0 0 0 0 0 0
42725 - 0 0 0 0 0 0 0 0 0 0 0 0
42726 - 0 0 0 6 6 6 10 10 10 14 14 14
42727 - 18 18 18 26 26 26 38 38 38 54 54 54
42728 - 70 70 70 86 86 86 94 86 76 89 81 66
42729 - 89 81 66 86 86 86 74 74 74 50 50 50
42730 - 30 30 30 14 14 14 6 6 6 0 0 0
42731 - 0 0 0 0 0 0 0 0 0 0 0 0
42732 - 0 0 0 0 0 0 0 0 0 0 0 0
42733 - 0 0 0 0 0 0 0 0 0 0 0 0
42734 - 6 6 6 18 18 18 34 34 34 58 58 58
42735 - 82 82 82 89 81 66 89 81 66 89 81 66
42736 - 94 86 66 94 86 76 74 74 74 50 50 50
42737 - 26 26 26 14 14 14 6 6 6 0 0 0
42738 - 0 0 0 0 0 0 0 0 0 0 0 0
42739 - 0 0 0 0 0 0 0 0 0 0 0 0
42740 - 0 0 0 0 0 0 0 0 0 0 0 0
42741 - 0 0 0 0 0 0 0 0 0 0 0 0
42742 - 0 0 0 0 0 0 0 0 0 0 0 0
42743 - 0 0 0 0 0 0 0 0 0 0 0 0
42744 - 0 0 0 0 0 0 0 0 0 0 0 0
42745 - 0 0 0 0 0 0 0 0 0 0 0 0
42746 - 0 0 0 0 0 0 0 0 0 0 0 0
42747 - 6 6 6 6 6 6 14 14 14 18 18 18
42748 - 30 30 30 38 38 38 46 46 46 54 54 54
42749 - 50 50 50 42 42 42 30 30 30 18 18 18
42750 - 10 10 10 0 0 0 0 0 0 0 0 0
42751 - 0 0 0 0 0 0 0 0 0 0 0 0
42752 - 0 0 0 0 0 0 0 0 0 0 0 0
42753 - 0 0 0 0 0 0 0 0 0 0 0 0
42754 - 0 0 0 6 6 6 14 14 14 26 26 26
42755 - 38 38 38 50 50 50 58 58 58 58 58 58
42756 - 54 54 54 42 42 42 30 30 30 18 18 18
42757 - 10 10 10 0 0 0 0 0 0 0 0 0
42758 - 0 0 0 0 0 0 0 0 0 0 0 0
42759 - 0 0 0 0 0 0 0 0 0 0 0 0
42760 - 0 0 0 0 0 0 0 0 0 0 0 0
42761 - 0 0 0 0 0 0 0 0 0 0 0 0
42762 - 0 0 0 0 0 0 0 0 0 0 0 0
42763 - 0 0 0 0 0 0 0 0 0 0 0 0
42764 - 0 0 0 0 0 0 0 0 0 0 0 0
42765 - 0 0 0 0 0 0 0 0 0 0 0 0
42766 - 0 0 0 0 0 0 0 0 0 0 0 0
42767 - 0 0 0 0 0 0 0 0 0 6 6 6
42768 - 6 6 6 10 10 10 14 14 14 18 18 18
42769 - 18 18 18 14 14 14 10 10 10 6 6 6
42770 - 0 0 0 0 0 0 0 0 0 0 0 0
42771 - 0 0 0 0 0 0 0 0 0 0 0 0
42772 - 0 0 0 0 0 0 0 0 0 0 0 0
42773 - 0 0 0 0 0 0 0 0 0 0 0 0
42774 - 0 0 0 0 0 0 0 0 0 6 6 6
42775 - 14 14 14 18 18 18 22 22 22 22 22 22
42776 - 18 18 18 14 14 14 10 10 10 6 6 6
42777 - 0 0 0 0 0 0 0 0 0 0 0 0
42778 - 0 0 0 0 0 0 0 0 0 0 0 0
42779 - 0 0 0 0 0 0 0 0 0 0 0 0
42780 - 0 0 0 0 0 0 0 0 0 0 0 0
42781 - 0 0 0 0 0 0 0 0 0 0 0 0
42782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42795 +4 4 4 4 4 4
42796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42809 +4 4 4 4 4 4
42810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42823 +4 4 4 4 4 4
42824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42837 +4 4 4 4 4 4
42838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42851 +4 4 4 4 4 4
42852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42865 +4 4 4 4 4 4
42866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42870 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
42871 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
42872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42875 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
42876 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42877 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
42878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42879 +4 4 4 4 4 4
42880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42884 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
42885 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
42886 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42889 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
42890 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
42891 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
42892 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42893 +4 4 4 4 4 4
42894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42898 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
42899 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
42900 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42903 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
42904 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
42905 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
42906 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
42907 +4 4 4 4 4 4
42908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42911 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
42912 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
42913 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
42914 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
42915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42916 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42917 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
42918 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
42919 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
42920 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
42921 +4 4 4 4 4 4
42922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42925 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
42926 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
42927 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
42928 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
42929 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42930 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
42931 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
42932 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
42933 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
42934 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
42935 +4 4 4 4 4 4
42936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42939 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
42940 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
42941 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
42942 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
42943 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42944 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
42945 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
42946 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
42947 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
42948 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
42949 +4 4 4 4 4 4
42950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42952 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
42953 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
42954 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
42955 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
42956 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
42957 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
42958 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
42959 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
42960 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
42961 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
42962 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
42963 +4 4 4 4 4 4
42964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42966 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
42967 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
42968 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
42969 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
42970 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
42971 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
42972 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
42973 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
42974 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
42975 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
42976 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
42977 +4 4 4 4 4 4
42978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42980 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
42981 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
42982 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
42983 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
42984 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
42985 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
42986 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
42987 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
42988 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
42989 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
42990 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42991 +4 4 4 4 4 4
42992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42994 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
42995 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
42996 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
42997 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
42998 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
42999 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43000 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43001 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43002 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43003 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43004 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43005 +4 4 4 4 4 4
43006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43007 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43008 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43009 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43010 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43011 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43012 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43013 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43014 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43015 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43016 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43017 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43018 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43019 +4 4 4 4 4 4
43020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43021 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43022 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43023 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43024 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43025 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43026 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43027 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43028 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43029 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43030 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43031 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43032 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43033 +0 0 0 4 4 4
43034 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43035 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43036 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43037 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43038 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43039 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43040 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43041 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43042 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43043 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43044 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43045 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43046 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43047 +2 0 0 0 0 0
43048 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43049 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43050 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43051 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43052 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43053 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43054 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43055 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43056 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43057 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43058 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43059 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43060 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43061 +37 38 37 0 0 0
43062 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43063 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43064 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43065 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43066 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43067 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43068 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43069 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43070 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43071 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43072 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43073 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43074 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43075 +85 115 134 4 0 0
43076 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43077 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43078 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43079 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43080 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43081 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43082 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43083 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43084 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43085 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43086 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43087 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43088 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43089 +60 73 81 4 0 0
43090 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43091 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43092 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43093 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43094 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43095 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43096 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43097 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43098 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43099 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43100 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43101 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43102 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43103 +16 19 21 4 0 0
43104 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43105 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43106 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43107 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43108 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43109 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43110 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43111 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43112 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43113 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43114 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43115 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43116 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43117 +4 0 0 4 3 3
43118 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43119 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43120 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43122 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43123 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43124 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43125 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43126 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43127 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43128 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43129 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43130 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43131 +3 2 2 4 4 4
43132 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43133 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43134 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43135 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43136 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43137 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43138 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43139 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43140 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43141 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43142 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43143 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43144 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43145 +4 4 4 4 4 4
43146 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43147 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43148 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43149 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43150 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43151 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43152 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43153 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43154 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43155 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43156 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43157 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43158 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43159 +4 4 4 4 4 4
43160 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43161 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43162 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43163 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43164 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43165 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43166 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43167 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43168 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43169 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43170 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43171 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43172 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43173 +5 5 5 5 5 5
43174 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43175 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43176 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43177 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43178 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43179 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43180 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43181 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43182 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43183 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43184 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43185 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43186 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43187 +5 5 5 4 4 4
43188 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43189 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43190 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43191 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43192 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43193 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43194 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43195 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43196 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43197 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43198 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43199 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43201 +4 4 4 4 4 4
43202 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43203 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43204 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43205 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43206 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43207 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43208 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43209 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43210 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43211 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43212 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43213 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43215 +4 4 4 4 4 4
43216 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43217 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43218 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43219 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43220 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43221 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43222 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43223 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43224 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43225 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43226 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43229 +4 4 4 4 4 4
43230 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43231 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43232 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43233 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43234 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43235 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43236 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43237 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43238 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43239 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43240 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43243 +4 4 4 4 4 4
43244 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43245 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43246 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43247 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43248 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43249 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43250 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43251 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43252 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43253 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43254 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43257 +4 4 4 4 4 4
43258 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43259 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43260 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43261 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43262 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43263 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43264 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43265 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43266 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43267 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43268 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43271 +4 4 4 4 4 4
43272 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43273 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43274 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43275 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43276 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43277 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43278 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43279 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43280 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43281 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43282 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43285 +4 4 4 4 4 4
43286 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43287 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43288 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43289 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43290 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43291 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43292 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43293 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43294 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43295 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43296 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43299 +4 4 4 4 4 4
43300 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43301 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43302 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43303 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43304 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43305 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43306 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43307 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43308 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43309 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43310 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43313 +4 4 4 4 4 4
43314 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43315 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43316 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43317 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43318 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43319 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43320 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43321 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43322 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43323 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43324 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43327 +4 4 4 4 4 4
43328 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43329 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43330 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43331 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43332 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43333 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43334 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43335 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43336 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43337 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43338 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43341 +4 4 4 4 4 4
43342 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43343 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43344 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43345 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43346 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43347 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43348 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43349 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43350 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43351 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43352 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43355 +4 4 4 4 4 4
43356 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43357 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43358 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43359 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43360 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43361 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43362 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43363 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43364 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43365 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43366 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43369 +4 4 4 4 4 4
43370 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43371 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43372 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43373 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43374 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43375 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43376 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43377 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43378 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43379 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43380 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43383 +4 4 4 4 4 4
43384 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43385 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43386 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43387 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43388 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43389 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43390 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43391 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43392 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43393 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43394 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43397 +4 4 4 4 4 4
43398 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43399 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43400 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43401 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43402 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43403 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43404 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43405 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43406 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43407 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43408 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43411 +4 4 4 4 4 4
43412 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43413 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43414 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43415 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43416 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43417 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43418 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43419 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43420 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43421 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43422 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43425 +4 4 4 4 4 4
43426 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43427 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43428 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43429 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43430 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43431 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43432 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43433 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43434 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43435 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43436 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43439 +4 4 4 4 4 4
43440 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43441 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43442 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43443 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43444 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43445 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43446 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43447 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43448 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43449 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43450 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43453 +4 4 4 4 4 4
43454 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43455 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43456 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43457 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43458 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43459 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43460 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43461 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43462 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43463 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43464 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43467 +4 4 4 4 4 4
43468 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43469 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43470 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43471 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43472 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43473 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43474 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43475 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43476 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43477 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43478 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43481 +4 4 4 4 4 4
43482 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43483 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43484 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43485 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43486 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43487 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43488 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43489 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43490 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43491 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43492 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43495 +4 4 4 4 4 4
43496 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43497 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43498 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43499 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43500 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43501 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43502 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43503 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43504 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43505 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43506 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43509 +4 4 4 4 4 4
43510 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43511 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43512 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43513 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43514 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43515 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43516 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43517 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43518 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43519 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43520 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43523 +4 4 4 4 4 4
43524 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43525 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43526 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43527 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43528 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43529 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43530 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43531 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43532 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43533 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43534 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43537 +4 4 4 4 4 4
43538 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43539 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43540 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43541 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43542 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43543 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43544 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43545 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43546 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43547 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43548 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43551 +4 4 4 4 4 4
43552 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43553 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43554 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43555 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43556 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43557 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43558 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43559 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43560 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43561 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43562 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43565 +4 4 4 4 4 4
43566 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43567 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43568 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43569 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43570 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43571 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43572 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43573 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43574 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43575 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43576 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43579 +4 4 4 4 4 4
43580 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43581 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43582 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43583 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43584 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43585 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43586 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43587 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43588 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43589 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43590 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43593 +4 4 4 4 4 4
43594 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43595 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43596 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43597 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43598 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43599 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43600 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43601 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43602 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43603 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43607 +4 4 4 4 4 4
43608 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43609 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43610 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43611 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43612 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43613 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43614 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43615 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43616 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43617 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43621 +4 4 4 4 4 4
43622 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43623 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43624 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43625 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43626 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43627 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43628 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43629 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43630 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43631 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43635 +4 4 4 4 4 4
43636 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43637 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43638 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43639 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43640 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43641 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43642 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43643 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43644 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43645 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43649 +4 4 4 4 4 4
43650 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43651 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43652 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43653 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43654 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43655 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43656 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43657 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43658 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43663 +4 4 4 4 4 4
43664 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43665 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43666 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43667 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43668 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43669 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43670 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43671 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43672 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43677 +4 4 4 4 4 4
43678 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43679 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43680 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43681 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43682 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43683 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43684 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43685 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43686 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691 +4 4 4 4 4 4
43692 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43693 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43694 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43695 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43696 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43697 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43698 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43699 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43705 +4 4 4 4 4 4
43706 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43707 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43708 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43709 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43710 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43711 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43712 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43713 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43719 +4 4 4 4 4 4
43720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43721 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43722 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43723 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43724 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43725 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43726 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43727 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43733 +4 4 4 4 4 4
43734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43735 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43736 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43737 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43738 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43739 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43740 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43741 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747 +4 4 4 4 4 4
43748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43749 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43750 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43751 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43752 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43753 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43754 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43755 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43761 +4 4 4 4 4 4
43762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43765 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43766 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43767 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43768 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43769 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775 +4 4 4 4 4 4
43776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43779 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43780 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43781 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43782 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43789 +4 4 4 4 4 4
43790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43793 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43794 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43795 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43796 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43803 +4 4 4 4 4 4
43804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43807 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43808 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43809 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43810 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43817 +4 4 4 4 4 4
43818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43821 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43822 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43823 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43824 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43831 +4 4 4 4 4 4
43832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43836 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
43837 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43838 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43845 +4 4 4 4 4 4
43846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43850 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
43851 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
43852 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43859 +4 4 4 4 4 4
43860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43864 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
43865 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
43866 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43873 +4 4 4 4 4 4
43874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43878 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
43879 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
43880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43887 +4 4 4 4 4 4
43888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43892 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43893 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
43894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43901 +4 4 4 4 4 4
43902 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
43903 index 86d449e..af6a7f7 100644
43904 --- a/drivers/video/udlfb.c
43905 +++ b/drivers/video/udlfb.c
43906 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
43907 dlfb_urb_completion(urb);
43908
43909 error:
43910 - atomic_add(bytes_sent, &dev->bytes_sent);
43911 - atomic_add(bytes_identical, &dev->bytes_identical);
43912 - atomic_add(width*height*2, &dev->bytes_rendered);
43913 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43914 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43915 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
43916 end_cycles = get_cycles();
43917 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43918 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43919 >> 10)), /* Kcycles */
43920 &dev->cpu_kcycles_used);
43921
43922 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
43923 dlfb_urb_completion(urb);
43924
43925 error:
43926 - atomic_add(bytes_sent, &dev->bytes_sent);
43927 - atomic_add(bytes_identical, &dev->bytes_identical);
43928 - atomic_add(bytes_rendered, &dev->bytes_rendered);
43929 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43930 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43931 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43932 end_cycles = get_cycles();
43933 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43934 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43935 >> 10)), /* Kcycles */
43936 &dev->cpu_kcycles_used);
43937 }
43938 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
43939 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43940 struct dlfb_data *dev = fb_info->par;
43941 return snprintf(buf, PAGE_SIZE, "%u\n",
43942 - atomic_read(&dev->bytes_rendered));
43943 + atomic_read_unchecked(&dev->bytes_rendered));
43944 }
43945
43946 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43947 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43948 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43949 struct dlfb_data *dev = fb_info->par;
43950 return snprintf(buf, PAGE_SIZE, "%u\n",
43951 - atomic_read(&dev->bytes_identical));
43952 + atomic_read_unchecked(&dev->bytes_identical));
43953 }
43954
43955 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43956 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43957 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43958 struct dlfb_data *dev = fb_info->par;
43959 return snprintf(buf, PAGE_SIZE, "%u\n",
43960 - atomic_read(&dev->bytes_sent));
43961 + atomic_read_unchecked(&dev->bytes_sent));
43962 }
43963
43964 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43965 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43966 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43967 struct dlfb_data *dev = fb_info->par;
43968 return snprintf(buf, PAGE_SIZE, "%u\n",
43969 - atomic_read(&dev->cpu_kcycles_used));
43970 + atomic_read_unchecked(&dev->cpu_kcycles_used));
43971 }
43972
43973 static ssize_t edid_show(
43974 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
43975 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43976 struct dlfb_data *dev = fb_info->par;
43977
43978 - atomic_set(&dev->bytes_rendered, 0);
43979 - atomic_set(&dev->bytes_identical, 0);
43980 - atomic_set(&dev->bytes_sent, 0);
43981 - atomic_set(&dev->cpu_kcycles_used, 0);
43982 + atomic_set_unchecked(&dev->bytes_rendered, 0);
43983 + atomic_set_unchecked(&dev->bytes_identical, 0);
43984 + atomic_set_unchecked(&dev->bytes_sent, 0);
43985 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43986
43987 return count;
43988 }
43989 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
43990 index 2f8f82d..191de37 100644
43991 --- a/drivers/video/uvesafb.c
43992 +++ b/drivers/video/uvesafb.c
43993 @@ -19,6 +19,7 @@
43994 #include <linux/io.h>
43995 #include <linux/mutex.h>
43996 #include <linux/slab.h>
43997 +#include <linux/moduleloader.h>
43998 #include <video/edid.h>
43999 #include <video/uvesafb.h>
44000 #ifdef CONFIG_X86
44001 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44002 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44003 par->pmi_setpal = par->ypan = 0;
44004 } else {
44005 +
44006 +#ifdef CONFIG_PAX_KERNEXEC
44007 +#ifdef CONFIG_MODULES
44008 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44009 +#endif
44010 + if (!par->pmi_code) {
44011 + par->pmi_setpal = par->ypan = 0;
44012 + return 0;
44013 + }
44014 +#endif
44015 +
44016 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44017 + task->t.regs.edi);
44018 +
44019 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44020 + pax_open_kernel();
44021 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44022 + pax_close_kernel();
44023 +
44024 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44025 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44026 +#else
44027 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44028 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44029 +#endif
44030 +
44031 printk(KERN_INFO "uvesafb: protected mode interface info at "
44032 "%04x:%04x\n",
44033 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44034 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
44035 par->ypan = ypan;
44036
44037 if (par->pmi_setpal || par->ypan) {
44038 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44039 if (__supported_pte_mask & _PAGE_NX) {
44040 par->pmi_setpal = par->ypan = 0;
44041 printk(KERN_WARNING "uvesafb: NX protection is actively."
44042 "We have better not to use the PMI.\n");
44043 - } else {
44044 + } else
44045 +#endif
44046 uvesafb_vbe_getpmi(task, par);
44047 - }
44048 }
44049 #else
44050 /* The protected mode interface is not available on non-x86. */
44051 @@ -1838,6 +1862,11 @@ out:
44052 if (par->vbe_modes)
44053 kfree(par->vbe_modes);
44054
44055 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44056 + if (par->pmi_code)
44057 + module_free_exec(NULL, par->pmi_code);
44058 +#endif
44059 +
44060 framebuffer_release(info);
44061 return err;
44062 }
44063 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
44064 kfree(par->vbe_state_orig);
44065 if (par->vbe_state_saved)
44066 kfree(par->vbe_state_saved);
44067 +
44068 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44069 + if (par->pmi_code)
44070 + module_free_exec(NULL, par->pmi_code);
44071 +#endif
44072 +
44073 }
44074
44075 framebuffer_release(info);
44076 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44077 index 501b340..86bd4cf 100644
44078 --- a/drivers/video/vesafb.c
44079 +++ b/drivers/video/vesafb.c
44080 @@ -9,6 +9,7 @@
44081 */
44082
44083 #include <linux/module.h>
44084 +#include <linux/moduleloader.h>
44085 #include <linux/kernel.h>
44086 #include <linux/errno.h>
44087 #include <linux/string.h>
44088 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44089 static int vram_total __initdata; /* Set total amount of memory */
44090 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44091 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44092 -static void (*pmi_start)(void) __read_mostly;
44093 -static void (*pmi_pal) (void) __read_mostly;
44094 +static void (*pmi_start)(void) __read_only;
44095 +static void (*pmi_pal) (void) __read_only;
44096 static int depth __read_mostly;
44097 static int vga_compat __read_mostly;
44098 /* --------------------------------------------------------------------- */
44099 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44100 unsigned int size_vmode;
44101 unsigned int size_remap;
44102 unsigned int size_total;
44103 + void *pmi_code = NULL;
44104
44105 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44106 return -ENODEV;
44107 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44108 size_remap = size_total;
44109 vesafb_fix.smem_len = size_remap;
44110
44111 -#ifndef __i386__
44112 - screen_info.vesapm_seg = 0;
44113 -#endif
44114 -
44115 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44116 printk(KERN_WARNING
44117 "vesafb: cannot reserve video memory at 0x%lx\n",
44118 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44119 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44120 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44121
44122 +#ifdef __i386__
44123 +
44124 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44125 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
44126 + if (!pmi_code)
44127 +#elif !defined(CONFIG_PAX_KERNEXEC)
44128 + if (0)
44129 +#endif
44130 +
44131 +#endif
44132 + screen_info.vesapm_seg = 0;
44133 +
44134 if (screen_info.vesapm_seg) {
44135 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44136 - screen_info.vesapm_seg,screen_info.vesapm_off);
44137 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44138 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44139 }
44140
44141 if (screen_info.vesapm_seg < 0xc000)
44142 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44143
44144 if (ypan || pmi_setpal) {
44145 unsigned short *pmi_base;
44146 +
44147 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44148 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44149 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44150 +
44151 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44152 + pax_open_kernel();
44153 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44154 +#else
44155 + pmi_code = pmi_base;
44156 +#endif
44157 +
44158 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44159 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44160 +
44161 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44162 + pmi_start = ktva_ktla(pmi_start);
44163 + pmi_pal = ktva_ktla(pmi_pal);
44164 + pax_close_kernel();
44165 +#endif
44166 +
44167 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44168 if (pmi_base[3]) {
44169 printk(KERN_INFO "vesafb: pmi: ports = ");
44170 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44171 info->node, info->fix.id);
44172 return 0;
44173 err:
44174 +
44175 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44176 + module_free_exec(NULL, pmi_code);
44177 +#endif
44178 +
44179 if (info->screen_base)
44180 iounmap(info->screen_base);
44181 framebuffer_release(info);
44182 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44183 index 88714ae..16c2e11 100644
44184 --- a/drivers/video/via/via_clock.h
44185 +++ b/drivers/video/via/via_clock.h
44186 @@ -56,7 +56,7 @@ struct via_clock {
44187
44188 void (*set_engine_pll_state)(u8 state);
44189 void (*set_engine_pll)(struct via_pll_config config);
44190 -};
44191 +} __no_const;
44192
44193
44194 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44195 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44196 index 6b1b7e1..b2fa4d5 100644
44197 --- a/drivers/virtio/virtio_mmio.c
44198 +++ b/drivers/virtio/virtio_mmio.c
44199 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44200
44201 resources[0].end = memparse(device, &str) - 1;
44202
44203 - processed = sscanf(str, "@%lli:%u%n:%d%n",
44204 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
44205 &base, &resources[1].start, &consumed,
44206 &vm_cmdline_id, &consumed);
44207
44208 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44209 index fef20db..d28b1ab 100644
44210 --- a/drivers/xen/xenfs/xenstored.c
44211 +++ b/drivers/xen/xenfs/xenstored.c
44212 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44213 static int xsd_kva_open(struct inode *inode, struct file *file)
44214 {
44215 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44216 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44217 + NULL);
44218 +#else
44219 xen_store_interface);
44220 +#endif
44221 +
44222 if (!file->private_data)
44223 return -ENOMEM;
44224 return 0;
44225 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44226 index 890bed5..17ae73e 100644
44227 --- a/fs/9p/vfs_inode.c
44228 +++ b/fs/9p/vfs_inode.c
44229 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44230 void
44231 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44232 {
44233 - char *s = nd_get_link(nd);
44234 + const char *s = nd_get_link(nd);
44235
44236 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44237 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44238 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44239 index 0efd152..b5802ad 100644
44240 --- a/fs/Kconfig.binfmt
44241 +++ b/fs/Kconfig.binfmt
44242 @@ -89,7 +89,7 @@ config HAVE_AOUT
44243
44244 config BINFMT_AOUT
44245 tristate "Kernel support for a.out and ECOFF binaries"
44246 - depends on HAVE_AOUT
44247 + depends on HAVE_AOUT && BROKEN
44248 ---help---
44249 A.out (Assembler.OUTput) is a set of formats for libraries and
44250 executables used in the earliest versions of UNIX. Linux used
44251 diff --git a/fs/aio.c b/fs/aio.c
44252 index 71f613c..9d01f1f 100644
44253 --- a/fs/aio.c
44254 +++ b/fs/aio.c
44255 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44256 size += sizeof(struct io_event) * nr_events;
44257 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44258
44259 - if (nr_pages < 0)
44260 + if (nr_pages <= 0)
44261 return -EINVAL;
44262
44263 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44264 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44265 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44266 {
44267 ssize_t ret;
44268 + struct iovec iovstack;
44269
44270 #ifdef CONFIG_COMPAT
44271 if (compat)
44272 ret = compat_rw_copy_check_uvector(type,
44273 (struct compat_iovec __user *)kiocb->ki_buf,
44274 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44275 + kiocb->ki_nbytes, 1, &iovstack,
44276 &kiocb->ki_iovec);
44277 else
44278 #endif
44279 ret = rw_copy_check_uvector(type,
44280 (struct iovec __user *)kiocb->ki_buf,
44281 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44282 + kiocb->ki_nbytes, 1, &iovstack,
44283 &kiocb->ki_iovec);
44284 if (ret < 0)
44285 goto out;
44286 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44287 if (ret < 0)
44288 goto out;
44289
44290 + if (kiocb->ki_iovec == &iovstack) {
44291 + kiocb->ki_inline_vec = iovstack;
44292 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
44293 + }
44294 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44295 kiocb->ki_cur_seg = 0;
44296 /* ki_nbytes/left now reflect bytes instead of segs */
44297 diff --git a/fs/attr.c b/fs/attr.c
44298 index cce7df5..eaa2731 100644
44299 --- a/fs/attr.c
44300 +++ b/fs/attr.c
44301 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44302 unsigned long limit;
44303
44304 limit = rlimit(RLIMIT_FSIZE);
44305 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44306 if (limit != RLIM_INFINITY && offset > limit)
44307 goto out_sig;
44308 if (offset > inode->i_sb->s_maxbytes)
44309 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44310 index dce436e..55e670d 100644
44311 --- a/fs/autofs4/waitq.c
44312 +++ b/fs/autofs4/waitq.c
44313 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44314 {
44315 unsigned long sigpipe, flags;
44316 mm_segment_t fs;
44317 - const char *data = (const char *)addr;
44318 + const char __user *data = (const char __force_user *)addr;
44319 ssize_t wr = 0;
44320
44321 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44322 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44323 return 1;
44324 }
44325
44326 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44327 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44328 +#endif
44329 +
44330 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44331 enum autofs_notify notify)
44332 {
44333 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44334
44335 /* If this is a direct mount request create a dummy name */
44336 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44337 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44338 + /* this name does get written to userland via autofs4_write() */
44339 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44340 +#else
44341 qstr.len = sprintf(name, "%p", dentry);
44342 +#endif
44343 else {
44344 qstr.len = autofs4_getpath(sbi, dentry, &name);
44345 if (!qstr.len) {
44346 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44347 index 2b3bda8..6a2d4be 100644
44348 --- a/fs/befs/linuxvfs.c
44349 +++ b/fs/befs/linuxvfs.c
44350 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44351 {
44352 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44353 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44354 - char *link = nd_get_link(nd);
44355 + const char *link = nd_get_link(nd);
44356 if (!IS_ERR(link))
44357 kfree(link);
44358 }
44359 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44360 index 0e7a6f8..332b1ca 100644
44361 --- a/fs/binfmt_aout.c
44362 +++ b/fs/binfmt_aout.c
44363 @@ -16,6 +16,7 @@
44364 #include <linux/string.h>
44365 #include <linux/fs.h>
44366 #include <linux/file.h>
44367 +#include <linux/security.h>
44368 #include <linux/stat.h>
44369 #include <linux/fcntl.h>
44370 #include <linux/ptrace.h>
44371 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44372 #endif
44373 # define START_STACK(u) ((void __user *)u.start_stack)
44374
44375 + memset(&dump, 0, sizeof(dump));
44376 +
44377 fs = get_fs();
44378 set_fs(KERNEL_DS);
44379 has_dumped = 1;
44380 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44381
44382 /* If the size of the dump file exceeds the rlimit, then see what would happen
44383 if we wrote the stack, but not the data area. */
44384 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44385 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44386 dump.u_dsize = 0;
44387
44388 /* Make sure we have enough room to write the stack and data areas. */
44389 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44390 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44391 dump.u_ssize = 0;
44392
44393 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44394 rlim = rlimit(RLIMIT_DATA);
44395 if (rlim >= RLIM_INFINITY)
44396 rlim = ~0;
44397 +
44398 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44399 if (ex.a_data + ex.a_bss > rlim)
44400 return -ENOMEM;
44401
44402 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44403
44404 install_exec_creds(bprm);
44405
44406 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44407 + current->mm->pax_flags = 0UL;
44408 +#endif
44409 +
44410 +#ifdef CONFIG_PAX_PAGEEXEC
44411 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44412 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44413 +
44414 +#ifdef CONFIG_PAX_EMUTRAMP
44415 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44416 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44417 +#endif
44418 +
44419 +#ifdef CONFIG_PAX_MPROTECT
44420 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44421 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44422 +#endif
44423 +
44424 + }
44425 +#endif
44426 +
44427 if (N_MAGIC(ex) == OMAGIC) {
44428 unsigned long text_addr, map_size;
44429 loff_t pos;
44430 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44431 }
44432
44433 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44434 - PROT_READ | PROT_WRITE | PROT_EXEC,
44435 + PROT_READ | PROT_WRITE,
44436 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44437 fd_offset + ex.a_text);
44438 if (error != N_DATADDR(ex)) {
44439 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44440 index fbd9f60..0b845dd 100644
44441 --- a/fs/binfmt_elf.c
44442 +++ b/fs/binfmt_elf.c
44443 @@ -33,6 +33,7 @@
44444 #include <linux/elf.h>
44445 #include <linux/utsname.h>
44446 #include <linux/coredump.h>
44447 +#include <linux/xattr.h>
44448 #include <asm/uaccess.h>
44449 #include <asm/param.h>
44450 #include <asm/page.h>
44451 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44452 #define elf_core_dump NULL
44453 #endif
44454
44455 +#ifdef CONFIG_PAX_MPROTECT
44456 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44457 +#endif
44458 +
44459 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44460 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44461 #else
44462 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44463 .load_binary = load_elf_binary,
44464 .load_shlib = load_elf_library,
44465 .core_dump = elf_core_dump,
44466 +
44467 +#ifdef CONFIG_PAX_MPROTECT
44468 + .handle_mprotect= elf_handle_mprotect,
44469 +#endif
44470 +
44471 .min_coredump = ELF_EXEC_PAGESIZE,
44472 };
44473
44474 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44475
44476 static int set_brk(unsigned long start, unsigned long end)
44477 {
44478 + unsigned long e = end;
44479 +
44480 start = ELF_PAGEALIGN(start);
44481 end = ELF_PAGEALIGN(end);
44482 if (end > start) {
44483 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44484 if (BAD_ADDR(addr))
44485 return addr;
44486 }
44487 - current->mm->start_brk = current->mm->brk = end;
44488 + current->mm->start_brk = current->mm->brk = e;
44489 return 0;
44490 }
44491
44492 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44493 elf_addr_t __user *u_rand_bytes;
44494 const char *k_platform = ELF_PLATFORM;
44495 const char *k_base_platform = ELF_BASE_PLATFORM;
44496 - unsigned char k_rand_bytes[16];
44497 + u32 k_rand_bytes[4];
44498 int items;
44499 elf_addr_t *elf_info;
44500 int ei_index = 0;
44501 const struct cred *cred = current_cred();
44502 struct vm_area_struct *vma;
44503 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44504
44505 /*
44506 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44507 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44508 * Generate 16 random bytes for userspace PRNG seeding.
44509 */
44510 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44511 - u_rand_bytes = (elf_addr_t __user *)
44512 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44513 + srandom32(k_rand_bytes[0] ^ random32());
44514 + srandom32(k_rand_bytes[1] ^ random32());
44515 + srandom32(k_rand_bytes[2] ^ random32());
44516 + srandom32(k_rand_bytes[3] ^ random32());
44517 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44518 + u_rand_bytes = (elf_addr_t __user *) p;
44519 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44520 return -EFAULT;
44521
44522 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44523 return -EFAULT;
44524 current->mm->env_end = p;
44525
44526 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44527 +
44528 /* Put the elf_info on the stack in the right place. */
44529 sp = (elf_addr_t __user *)envp + 1;
44530 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44531 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44532 return -EFAULT;
44533 return 0;
44534 }
44535 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44536 an ELF header */
44537
44538 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44539 - struct file *interpreter, unsigned long *interp_map_addr,
44540 - unsigned long no_base)
44541 + struct file *interpreter, unsigned long no_base)
44542 {
44543 struct elf_phdr *elf_phdata;
44544 struct elf_phdr *eppnt;
44545 - unsigned long load_addr = 0;
44546 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44547 int load_addr_set = 0;
44548 unsigned long last_bss = 0, elf_bss = 0;
44549 - unsigned long error = ~0UL;
44550 + unsigned long error = -EINVAL;
44551 unsigned long total_size;
44552 int retval, i, size;
44553
44554 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44555 goto out_close;
44556 }
44557
44558 +#ifdef CONFIG_PAX_SEGMEXEC
44559 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44560 + pax_task_size = SEGMEXEC_TASK_SIZE;
44561 +#endif
44562 +
44563 eppnt = elf_phdata;
44564 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44565 if (eppnt->p_type == PT_LOAD) {
44566 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44567 map_addr = elf_map(interpreter, load_addr + vaddr,
44568 eppnt, elf_prot, elf_type, total_size);
44569 total_size = 0;
44570 - if (!*interp_map_addr)
44571 - *interp_map_addr = map_addr;
44572 error = map_addr;
44573 if (BAD_ADDR(map_addr))
44574 goto out_close;
44575 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44576 k = load_addr + eppnt->p_vaddr;
44577 if (BAD_ADDR(k) ||
44578 eppnt->p_filesz > eppnt->p_memsz ||
44579 - eppnt->p_memsz > TASK_SIZE ||
44580 - TASK_SIZE - eppnt->p_memsz < k) {
44581 + eppnt->p_memsz > pax_task_size ||
44582 + pax_task_size - eppnt->p_memsz < k) {
44583 error = -ENOMEM;
44584 goto out_close;
44585 }
44586 @@ -530,6 +551,315 @@ out:
44587 return error;
44588 }
44589
44590 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44591 +#ifdef CONFIG_PAX_SOFTMODE
44592 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44593 +{
44594 + unsigned long pax_flags = 0UL;
44595 +
44596 +#ifdef CONFIG_PAX_PAGEEXEC
44597 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44598 + pax_flags |= MF_PAX_PAGEEXEC;
44599 +#endif
44600 +
44601 +#ifdef CONFIG_PAX_SEGMEXEC
44602 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44603 + pax_flags |= MF_PAX_SEGMEXEC;
44604 +#endif
44605 +
44606 +#ifdef CONFIG_PAX_EMUTRAMP
44607 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44608 + pax_flags |= MF_PAX_EMUTRAMP;
44609 +#endif
44610 +
44611 +#ifdef CONFIG_PAX_MPROTECT
44612 + if (elf_phdata->p_flags & PF_MPROTECT)
44613 + pax_flags |= MF_PAX_MPROTECT;
44614 +#endif
44615 +
44616 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44617 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44618 + pax_flags |= MF_PAX_RANDMMAP;
44619 +#endif
44620 +
44621 + return pax_flags;
44622 +}
44623 +#endif
44624 +
44625 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44626 +{
44627 + unsigned long pax_flags = 0UL;
44628 +
44629 +#ifdef CONFIG_PAX_PAGEEXEC
44630 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44631 + pax_flags |= MF_PAX_PAGEEXEC;
44632 +#endif
44633 +
44634 +#ifdef CONFIG_PAX_SEGMEXEC
44635 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44636 + pax_flags |= MF_PAX_SEGMEXEC;
44637 +#endif
44638 +
44639 +#ifdef CONFIG_PAX_EMUTRAMP
44640 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44641 + pax_flags |= MF_PAX_EMUTRAMP;
44642 +#endif
44643 +
44644 +#ifdef CONFIG_PAX_MPROTECT
44645 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44646 + pax_flags |= MF_PAX_MPROTECT;
44647 +#endif
44648 +
44649 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44650 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44651 + pax_flags |= MF_PAX_RANDMMAP;
44652 +#endif
44653 +
44654 + return pax_flags;
44655 +}
44656 +#endif
44657 +
44658 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44659 +#ifdef CONFIG_PAX_SOFTMODE
44660 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44661 +{
44662 + unsigned long pax_flags = 0UL;
44663 +
44664 +#ifdef CONFIG_PAX_PAGEEXEC
44665 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44666 + pax_flags |= MF_PAX_PAGEEXEC;
44667 +#endif
44668 +
44669 +#ifdef CONFIG_PAX_SEGMEXEC
44670 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44671 + pax_flags |= MF_PAX_SEGMEXEC;
44672 +#endif
44673 +
44674 +#ifdef CONFIG_PAX_EMUTRAMP
44675 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44676 + pax_flags |= MF_PAX_EMUTRAMP;
44677 +#endif
44678 +
44679 +#ifdef CONFIG_PAX_MPROTECT
44680 + if (pax_flags_softmode & MF_PAX_MPROTECT)
44681 + pax_flags |= MF_PAX_MPROTECT;
44682 +#endif
44683 +
44684 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44685 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44686 + pax_flags |= MF_PAX_RANDMMAP;
44687 +#endif
44688 +
44689 + return pax_flags;
44690 +}
44691 +#endif
44692 +
44693 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44694 +{
44695 + unsigned long pax_flags = 0UL;
44696 +
44697 +#ifdef CONFIG_PAX_PAGEEXEC
44698 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44699 + pax_flags |= MF_PAX_PAGEEXEC;
44700 +#endif
44701 +
44702 +#ifdef CONFIG_PAX_SEGMEXEC
44703 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44704 + pax_flags |= MF_PAX_SEGMEXEC;
44705 +#endif
44706 +
44707 +#ifdef CONFIG_PAX_EMUTRAMP
44708 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44709 + pax_flags |= MF_PAX_EMUTRAMP;
44710 +#endif
44711 +
44712 +#ifdef CONFIG_PAX_MPROTECT
44713 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44714 + pax_flags |= MF_PAX_MPROTECT;
44715 +#endif
44716 +
44717 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44718 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44719 + pax_flags |= MF_PAX_RANDMMAP;
44720 +#endif
44721 +
44722 + return pax_flags;
44723 +}
44724 +#endif
44725 +
44726 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44727 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44728 +{
44729 + unsigned long pax_flags = 0UL;
44730 +
44731 +#ifdef CONFIG_PAX_EI_PAX
44732 +
44733 +#ifdef CONFIG_PAX_PAGEEXEC
44734 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44735 + pax_flags |= MF_PAX_PAGEEXEC;
44736 +#endif
44737 +
44738 +#ifdef CONFIG_PAX_SEGMEXEC
44739 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44740 + pax_flags |= MF_PAX_SEGMEXEC;
44741 +#endif
44742 +
44743 +#ifdef CONFIG_PAX_EMUTRAMP
44744 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44745 + pax_flags |= MF_PAX_EMUTRAMP;
44746 +#endif
44747 +
44748 +#ifdef CONFIG_PAX_MPROTECT
44749 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44750 + pax_flags |= MF_PAX_MPROTECT;
44751 +#endif
44752 +
44753 +#ifdef CONFIG_PAX_ASLR
44754 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44755 + pax_flags |= MF_PAX_RANDMMAP;
44756 +#endif
44757 +
44758 +#else
44759 +
44760 +#ifdef CONFIG_PAX_PAGEEXEC
44761 + pax_flags |= MF_PAX_PAGEEXEC;
44762 +#endif
44763 +
44764 +#ifdef CONFIG_PAX_SEGMEXEC
44765 + pax_flags |= MF_PAX_SEGMEXEC;
44766 +#endif
44767 +
44768 +#ifdef CONFIG_PAX_MPROTECT
44769 + pax_flags |= MF_PAX_MPROTECT;
44770 +#endif
44771 +
44772 +#ifdef CONFIG_PAX_RANDMMAP
44773 + if (randomize_va_space)
44774 + pax_flags |= MF_PAX_RANDMMAP;
44775 +#endif
44776 +
44777 +#endif
44778 +
44779 + return pax_flags;
44780 +}
44781 +
44782 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44783 +{
44784 +
44785 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44786 + unsigned long i;
44787 +
44788 + for (i = 0UL; i < elf_ex->e_phnum; i++)
44789 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44790 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44791 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44792 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44793 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44794 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44795 + return ~0UL;
44796 +
44797 +#ifdef CONFIG_PAX_SOFTMODE
44798 + if (pax_softmode)
44799 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44800 + else
44801 +#endif
44802 +
44803 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44804 + break;
44805 + }
44806 +#endif
44807 +
44808 + return ~0UL;
44809 +}
44810 +
44811 +static unsigned long pax_parse_xattr_pax(struct file * const file)
44812 +{
44813 +
44814 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44815 + ssize_t xattr_size, i;
44816 + unsigned char xattr_value[5];
44817 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44818 +
44819 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44820 + if (xattr_size <= 0 || xattr_size > 5)
44821 + return ~0UL;
44822 +
44823 + for (i = 0; i < xattr_size; i++)
44824 + switch (xattr_value[i]) {
44825 + default:
44826 + return ~0UL;
44827 +
44828 +#define parse_flag(option1, option2, flag) \
44829 + case option1: \
44830 + if (pax_flags_hardmode & MF_PAX_##flag) \
44831 + return ~0UL; \
44832 + pax_flags_hardmode |= MF_PAX_##flag; \
44833 + break; \
44834 + case option2: \
44835 + if (pax_flags_softmode & MF_PAX_##flag) \
44836 + return ~0UL; \
44837 + pax_flags_softmode |= MF_PAX_##flag; \
44838 + break;
44839 +
44840 + parse_flag('p', 'P', PAGEEXEC);
44841 + parse_flag('e', 'E', EMUTRAMP);
44842 + parse_flag('m', 'M', MPROTECT);
44843 + parse_flag('r', 'R', RANDMMAP);
44844 + parse_flag('s', 'S', SEGMEXEC);
44845 +
44846 +#undef parse_flag
44847 + }
44848 +
44849 + if (pax_flags_hardmode & pax_flags_softmode)
44850 + return ~0UL;
44851 +
44852 +#ifdef CONFIG_PAX_SOFTMODE
44853 + if (pax_softmode)
44854 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
44855 + else
44856 +#endif
44857 +
44858 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
44859 +#else
44860 + return ~0UL;
44861 +#endif
44862 +
44863 +}
44864 +
44865 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
44866 +{
44867 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
44868 +
44869 + pax_flags = pax_parse_ei_pax(elf_ex);
44870 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
44871 + xattr_pax_flags = pax_parse_xattr_pax(file);
44872 +
44873 + if (pt_pax_flags == ~0UL)
44874 + pt_pax_flags = xattr_pax_flags;
44875 + else if (xattr_pax_flags == ~0UL)
44876 + xattr_pax_flags = pt_pax_flags;
44877 + if (pt_pax_flags != xattr_pax_flags)
44878 + return -EINVAL;
44879 + if (pt_pax_flags != ~0UL)
44880 + pax_flags = pt_pax_flags;
44881 +
44882 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
44883 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44884 + if ((__supported_pte_mask & _PAGE_NX))
44885 + pax_flags &= ~MF_PAX_SEGMEXEC;
44886 + else
44887 + pax_flags &= ~MF_PAX_PAGEEXEC;
44888 + }
44889 +#endif
44890 +
44891 + if (0 > pax_check_flags(&pax_flags))
44892 + return -EINVAL;
44893 +
44894 + current->mm->pax_flags = pax_flags;
44895 + return 0;
44896 +}
44897 +#endif
44898 +
44899 /*
44900 * These are the functions used to load ELF style executables and shared
44901 * libraries. There is no binary dependent code anywhere else.
44902 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
44903 {
44904 unsigned int random_variable = 0;
44905
44906 +#ifdef CONFIG_PAX_RANDUSTACK
44907 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
44908 + return stack_top - current->mm->delta_stack;
44909 +#endif
44910 +
44911 if ((current->flags & PF_RANDOMIZE) &&
44912 !(current->personality & ADDR_NO_RANDOMIZE)) {
44913 random_variable = get_random_int() & STACK_RND_MASK;
44914 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44915 unsigned long load_addr = 0, load_bias = 0;
44916 int load_addr_set = 0;
44917 char * elf_interpreter = NULL;
44918 - unsigned long error;
44919 + unsigned long error = 0;
44920 struct elf_phdr *elf_ppnt, *elf_phdata;
44921 unsigned long elf_bss, elf_brk;
44922 int retval, i;
44923 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44924 unsigned long start_code, end_code, start_data, end_data;
44925 unsigned long reloc_func_desc __maybe_unused = 0;
44926 int executable_stack = EXSTACK_DEFAULT;
44927 - unsigned long def_flags = 0;
44928 struct {
44929 struct elfhdr elf_ex;
44930 struct elfhdr interp_elf_ex;
44931 } *loc;
44932 + unsigned long pax_task_size = TASK_SIZE;
44933
44934 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
44935 if (!loc) {
44936 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44937 goto out_free_dentry;
44938
44939 /* OK, This is the point of no return */
44940 - current->mm->def_flags = def_flags;
44941 +
44942 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44943 + current->mm->pax_flags = 0UL;
44944 +#endif
44945 +
44946 +#ifdef CONFIG_PAX_DLRESOLVE
44947 + current->mm->call_dl_resolve = 0UL;
44948 +#endif
44949 +
44950 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
44951 + current->mm->call_syscall = 0UL;
44952 +#endif
44953 +
44954 +#ifdef CONFIG_PAX_ASLR
44955 + current->mm->delta_mmap = 0UL;
44956 + current->mm->delta_stack = 0UL;
44957 +#endif
44958 +
44959 + current->mm->def_flags = 0;
44960 +
44961 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44962 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
44963 + send_sig(SIGKILL, current, 0);
44964 + goto out_free_dentry;
44965 + }
44966 +#endif
44967 +
44968 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44969 + pax_set_initial_flags(bprm);
44970 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
44971 + if (pax_set_initial_flags_func)
44972 + (pax_set_initial_flags_func)(bprm);
44973 +#endif
44974 +
44975 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
44976 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
44977 + current->mm->context.user_cs_limit = PAGE_SIZE;
44978 + current->mm->def_flags |= VM_PAGEEXEC;
44979 + }
44980 +#endif
44981 +
44982 +#ifdef CONFIG_PAX_SEGMEXEC
44983 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
44984 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
44985 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
44986 + pax_task_size = SEGMEXEC_TASK_SIZE;
44987 + current->mm->def_flags |= VM_NOHUGEPAGE;
44988 + }
44989 +#endif
44990 +
44991 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
44992 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44993 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
44994 + put_cpu();
44995 + }
44996 +#endif
44997
44998 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
44999 may depend on the personality. */
45000 SET_PERSONALITY(loc->elf_ex);
45001 +
45002 +#ifdef CONFIG_PAX_ASLR
45003 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45004 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45005 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45006 + }
45007 +#endif
45008 +
45009 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45010 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45011 + executable_stack = EXSTACK_DISABLE_X;
45012 + current->personality &= ~READ_IMPLIES_EXEC;
45013 + } else
45014 +#endif
45015 +
45016 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45017 current->personality |= READ_IMPLIES_EXEC;
45018
45019 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45020 #else
45021 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45022 #endif
45023 +
45024 +#ifdef CONFIG_PAX_RANDMMAP
45025 + /* PaX: randomize base address at the default exe base if requested */
45026 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45027 +#ifdef CONFIG_SPARC64
45028 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45029 +#else
45030 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45031 +#endif
45032 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45033 + elf_flags |= MAP_FIXED;
45034 + }
45035 +#endif
45036 +
45037 }
45038
45039 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45040 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45041 * allowed task size. Note that p_filesz must always be
45042 * <= p_memsz so it is only necessary to check p_memsz.
45043 */
45044 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45045 - elf_ppnt->p_memsz > TASK_SIZE ||
45046 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45047 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45048 + elf_ppnt->p_memsz > pax_task_size ||
45049 + pax_task_size - elf_ppnt->p_memsz < k) {
45050 /* set_brk can never work. Avoid overflows. */
45051 send_sig(SIGKILL, current, 0);
45052 retval = -EINVAL;
45053 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45054 goto out_free_dentry;
45055 }
45056 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45057 - send_sig(SIGSEGV, current, 0);
45058 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45059 - goto out_free_dentry;
45060 + /*
45061 + * This bss-zeroing can fail if the ELF
45062 + * file specifies odd protections. So
45063 + * we don't check the return value
45064 + */
45065 }
45066
45067 +#ifdef CONFIG_PAX_RANDMMAP
45068 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45069 + unsigned long start, size;
45070 +
45071 + start = ELF_PAGEALIGN(elf_brk);
45072 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45073 + down_read(&current->mm->mmap_sem);
45074 + retval = -ENOMEM;
45075 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45076 + unsigned long prot = PROT_NONE;
45077 +
45078 + up_read(&current->mm->mmap_sem);
45079 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45080 +// if (current->personality & ADDR_NO_RANDOMIZE)
45081 +// prot = PROT_READ;
45082 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45083 + retval = IS_ERR_VALUE(start) ? start : 0;
45084 + } else
45085 + up_read(&current->mm->mmap_sem);
45086 + if (retval == 0)
45087 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45088 + if (retval < 0) {
45089 + send_sig(SIGKILL, current, 0);
45090 + goto out_free_dentry;
45091 + }
45092 + }
45093 +#endif
45094 +
45095 if (elf_interpreter) {
45096 - unsigned long interp_map_addr = 0;
45097 -
45098 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45099 interpreter,
45100 - &interp_map_addr,
45101 load_bias);
45102 if (!IS_ERR((void *)elf_entry)) {
45103 /*
45104 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45105 * Decide what to dump of a segment, part, all or none.
45106 */
45107 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45108 - unsigned long mm_flags)
45109 + unsigned long mm_flags, long signr)
45110 {
45111 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45112
45113 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45114 if (vma->vm_file == NULL)
45115 return 0;
45116
45117 - if (FILTER(MAPPED_PRIVATE))
45118 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45119 goto whole;
45120
45121 /*
45122 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45123 {
45124 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45125 int i = 0;
45126 - do
45127 + do {
45128 i += 2;
45129 - while (auxv[i - 2] != AT_NULL);
45130 + } while (auxv[i - 2] != AT_NULL);
45131 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45132 }
45133
45134 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45135 }
45136
45137 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45138 - unsigned long mm_flags)
45139 + struct coredump_params *cprm)
45140 {
45141 struct vm_area_struct *vma;
45142 size_t size = 0;
45143
45144 for (vma = first_vma(current, gate_vma); vma != NULL;
45145 vma = next_vma(vma, gate_vma))
45146 - size += vma_dump_size(vma, mm_flags);
45147 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45148 return size;
45149 }
45150
45151 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45152
45153 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45154
45155 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45156 + offset += elf_core_vma_data_size(gate_vma, cprm);
45157 offset += elf_core_extra_data_size();
45158 e_shoff = offset;
45159
45160 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45161 offset = dataoff;
45162
45163 size += sizeof(*elf);
45164 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45165 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45166 goto end_coredump;
45167
45168 size += sizeof(*phdr4note);
45169 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45170 if (size > cprm->limit
45171 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45172 goto end_coredump;
45173 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45174 phdr.p_offset = offset;
45175 phdr.p_vaddr = vma->vm_start;
45176 phdr.p_paddr = 0;
45177 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45178 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45179 phdr.p_memsz = vma->vm_end - vma->vm_start;
45180 offset += phdr.p_filesz;
45181 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45182 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45183 phdr.p_align = ELF_EXEC_PAGESIZE;
45184
45185 size += sizeof(phdr);
45186 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45187 if (size > cprm->limit
45188 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45189 goto end_coredump;
45190 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45191 unsigned long addr;
45192 unsigned long end;
45193
45194 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45195 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45196
45197 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45198 struct page *page;
45199 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45200 page = get_dump_page(addr);
45201 if (page) {
45202 void *kaddr = kmap(page);
45203 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45204 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45205 !dump_write(cprm->file, kaddr,
45206 PAGE_SIZE);
45207 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45208
45209 if (e_phnum == PN_XNUM) {
45210 size += sizeof(*shdr4extnum);
45211 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45212 if (size > cprm->limit
45213 || !dump_write(cprm->file, shdr4extnum,
45214 sizeof(*shdr4extnum)))
45215 @@ -2216,6 +2667,97 @@ out:
45216
45217 #endif /* CONFIG_ELF_CORE */
45218
45219 +#ifdef CONFIG_PAX_MPROTECT
45220 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
45221 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45222 + * we'll remove VM_MAYWRITE for good on RELRO segments.
45223 + *
45224 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45225 + * basis because we want to allow the common case and not the special ones.
45226 + */
45227 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45228 +{
45229 + struct elfhdr elf_h;
45230 + struct elf_phdr elf_p;
45231 + unsigned long i;
45232 + unsigned long oldflags;
45233 + bool is_textrel_rw, is_textrel_rx, is_relro;
45234 +
45235 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45236 + return;
45237 +
45238 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45239 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45240 +
45241 +#ifdef CONFIG_PAX_ELFRELOCS
45242 + /* possible TEXTREL */
45243 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45244 + 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);
45245 +#else
45246 + is_textrel_rw = false;
45247 + is_textrel_rx = false;
45248 +#endif
45249 +
45250 + /* possible RELRO */
45251 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45252 +
45253 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45254 + return;
45255 +
45256 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45257 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45258 +
45259 +#ifdef CONFIG_PAX_ETEXECRELOCS
45260 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45261 +#else
45262 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45263 +#endif
45264 +
45265 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45266 + !elf_check_arch(&elf_h) ||
45267 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45268 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45269 + return;
45270 +
45271 + for (i = 0UL; i < elf_h.e_phnum; i++) {
45272 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45273 + return;
45274 + switch (elf_p.p_type) {
45275 + case PT_DYNAMIC:
45276 + if (!is_textrel_rw && !is_textrel_rx)
45277 + continue;
45278 + i = 0UL;
45279 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45280 + elf_dyn dyn;
45281 +
45282 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45283 + return;
45284 + if (dyn.d_tag == DT_NULL)
45285 + return;
45286 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45287 + gr_log_textrel(vma);
45288 + if (is_textrel_rw)
45289 + vma->vm_flags |= VM_MAYWRITE;
45290 + else
45291 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45292 + vma->vm_flags &= ~VM_MAYWRITE;
45293 + return;
45294 + }
45295 + i++;
45296 + }
45297 + return;
45298 +
45299 + case PT_GNU_RELRO:
45300 + if (!is_relro)
45301 + continue;
45302 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45303 + vma->vm_flags &= ~VM_MAYWRITE;
45304 + return;
45305 + }
45306 + }
45307 +}
45308 +#endif
45309 +
45310 static int __init init_elf_binfmt(void)
45311 {
45312 register_binfmt(&elf_format);
45313 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45314 index e280352..7b2f231 100644
45315 --- a/fs/binfmt_flat.c
45316 +++ b/fs/binfmt_flat.c
45317 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45318 realdatastart = (unsigned long) -ENOMEM;
45319 printk("Unable to allocate RAM for process data, errno %d\n",
45320 (int)-realdatastart);
45321 + down_write(&current->mm->mmap_sem);
45322 vm_munmap(textpos, text_len);
45323 + up_write(&current->mm->mmap_sem);
45324 ret = realdatastart;
45325 goto err;
45326 }
45327 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45328 }
45329 if (IS_ERR_VALUE(result)) {
45330 printk("Unable to read data+bss, errno %d\n", (int)-result);
45331 + down_write(&current->mm->mmap_sem);
45332 vm_munmap(textpos, text_len);
45333 vm_munmap(realdatastart, len);
45334 + up_write(&current->mm->mmap_sem);
45335 ret = result;
45336 goto err;
45337 }
45338 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45339 }
45340 if (IS_ERR_VALUE(result)) {
45341 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45342 + down_write(&current->mm->mmap_sem);
45343 vm_munmap(textpos, text_len + data_len + extra +
45344 MAX_SHARED_LIBS * sizeof(unsigned long));
45345 + up_write(&current->mm->mmap_sem);
45346 ret = result;
45347 goto err;
45348 }
45349 diff --git a/fs/bio.c b/fs/bio.c
45350 index b96fc6c..431d628 100644
45351 --- a/fs/bio.c
45352 +++ b/fs/bio.c
45353 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45354 /*
45355 * Overflow, abort
45356 */
45357 - if (end < start)
45358 + if (end < start || end - start > INT_MAX - nr_pages)
45359 return ERR_PTR(-EINVAL);
45360
45361 nr_pages += end - start;
45362 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45363 /*
45364 * Overflow, abort
45365 */
45366 - if (end < start)
45367 + if (end < start || end - start > INT_MAX - nr_pages)
45368 return ERR_PTR(-EINVAL);
45369
45370 nr_pages += end - start;
45371 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45372 const int read = bio_data_dir(bio) == READ;
45373 struct bio_map_data *bmd = bio->bi_private;
45374 int i;
45375 - char *p = bmd->sgvecs[0].iov_base;
45376 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45377
45378 __bio_for_each_segment(bvec, bio, i, 0) {
45379 char *addr = page_address(bvec->bv_page);
45380 diff --git a/fs/block_dev.c b/fs/block_dev.c
45381 index ab3a456..7da538b 100644
45382 --- a/fs/block_dev.c
45383 +++ b/fs/block_dev.c
45384 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45385 else if (bdev->bd_contains == bdev)
45386 return true; /* is a whole device which isn't held */
45387
45388 - else if (whole->bd_holder == bd_may_claim)
45389 + else if (whole->bd_holder == (void *)bd_may_claim)
45390 return true; /* is a partition of a device that is being partitioned */
45391 else if (whole->bd_holder != NULL)
45392 return false; /* is a partition of a held device */
45393 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45394 index cdfb4c4..da736d4 100644
45395 --- a/fs/btrfs/ctree.c
45396 +++ b/fs/btrfs/ctree.c
45397 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45398 free_extent_buffer(buf);
45399 add_root_to_dirty_list(root);
45400 } else {
45401 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45402 - parent_start = parent->start;
45403 - else
45404 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45405 + if (parent)
45406 + parent_start = parent->start;
45407 + else
45408 + parent_start = 0;
45409 + } else
45410 parent_start = 0;
45411
45412 WARN_ON(trans->transid != btrfs_header_generation(parent));
45413 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45414 index 95542a1..95a8727 100644
45415 --- a/fs/btrfs/inode.c
45416 +++ b/fs/btrfs/inode.c
45417 @@ -7243,7 +7243,7 @@ fail:
45418 return -ENOMEM;
45419 }
45420
45421 -static int btrfs_getattr(struct vfsmount *mnt,
45422 +int btrfs_getattr(struct vfsmount *mnt,
45423 struct dentry *dentry, struct kstat *stat)
45424 {
45425 struct inode *inode = dentry->d_inode;
45426 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45427 return 0;
45428 }
45429
45430 +EXPORT_SYMBOL(btrfs_getattr);
45431 +
45432 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45433 +{
45434 + return BTRFS_I(inode)->root->anon_dev;
45435 +}
45436 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45437 +
45438 /*
45439 * If a file is moved, it will inherit the cow and compression flags of the new
45440 * directory.
45441 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45442 index 8fcf9a5..a200000 100644
45443 --- a/fs/btrfs/ioctl.c
45444 +++ b/fs/btrfs/ioctl.c
45445 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45446 for (i = 0; i < num_types; i++) {
45447 struct btrfs_space_info *tmp;
45448
45449 + /* Don't copy in more than we allocated */
45450 if (!slot_count)
45451 break;
45452
45453 + slot_count--;
45454 +
45455 info = NULL;
45456 rcu_read_lock();
45457 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45458 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45459 memcpy(dest, &space, sizeof(space));
45460 dest++;
45461 space_args.total_spaces++;
45462 - slot_count--;
45463 }
45464 - if (!slot_count)
45465 - break;
45466 }
45467 up_read(&info->groups_sem);
45468 }
45469 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45470 index 776f0aa..3aad281 100644
45471 --- a/fs/btrfs/relocation.c
45472 +++ b/fs/btrfs/relocation.c
45473 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45474 }
45475 spin_unlock(&rc->reloc_root_tree.lock);
45476
45477 - BUG_ON((struct btrfs_root *)node->data != root);
45478 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45479
45480 if (!del) {
45481 spin_lock(&rc->reloc_root_tree.lock);
45482 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45483 index 622f469..e8d2d55 100644
45484 --- a/fs/cachefiles/bind.c
45485 +++ b/fs/cachefiles/bind.c
45486 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45487 args);
45488
45489 /* start by checking things over */
45490 - ASSERT(cache->fstop_percent >= 0 &&
45491 - cache->fstop_percent < cache->fcull_percent &&
45492 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45493 cache->fcull_percent < cache->frun_percent &&
45494 cache->frun_percent < 100);
45495
45496 - ASSERT(cache->bstop_percent >= 0 &&
45497 - cache->bstop_percent < cache->bcull_percent &&
45498 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45499 cache->bcull_percent < cache->brun_percent &&
45500 cache->brun_percent < 100);
45501
45502 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45503 index 0a1467b..6a53245 100644
45504 --- a/fs/cachefiles/daemon.c
45505 +++ b/fs/cachefiles/daemon.c
45506 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45507 if (n > buflen)
45508 return -EMSGSIZE;
45509
45510 - if (copy_to_user(_buffer, buffer, n) != 0)
45511 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45512 return -EFAULT;
45513
45514 return n;
45515 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45516 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45517 return -EIO;
45518
45519 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45520 + if (datalen > PAGE_SIZE - 1)
45521 return -EOPNOTSUPP;
45522
45523 /* drag the command string into the kernel so we can parse it */
45524 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45525 if (args[0] != '%' || args[1] != '\0')
45526 return -EINVAL;
45527
45528 - if (fstop < 0 || fstop >= cache->fcull_percent)
45529 + if (fstop >= cache->fcull_percent)
45530 return cachefiles_daemon_range_error(cache, args);
45531
45532 cache->fstop_percent = fstop;
45533 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45534 if (args[0] != '%' || args[1] != '\0')
45535 return -EINVAL;
45536
45537 - if (bstop < 0 || bstop >= cache->bcull_percent)
45538 + if (bstop >= cache->bcull_percent)
45539 return cachefiles_daemon_range_error(cache, args);
45540
45541 cache->bstop_percent = bstop;
45542 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45543 index bd6bc1b..b627b53 100644
45544 --- a/fs/cachefiles/internal.h
45545 +++ b/fs/cachefiles/internal.h
45546 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45547 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45548 struct rb_root active_nodes; /* active nodes (can't be culled) */
45549 rwlock_t active_lock; /* lock for active_nodes */
45550 - atomic_t gravecounter; /* graveyard uniquifier */
45551 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45552 unsigned frun_percent; /* when to stop culling (% files) */
45553 unsigned fcull_percent; /* when to start culling (% files) */
45554 unsigned fstop_percent; /* when to stop allocating (% files) */
45555 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45556 * proc.c
45557 */
45558 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45559 -extern atomic_t cachefiles_lookup_histogram[HZ];
45560 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45561 -extern atomic_t cachefiles_create_histogram[HZ];
45562 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45563 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45564 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45565
45566 extern int __init cachefiles_proc_init(void);
45567 extern void cachefiles_proc_cleanup(void);
45568 static inline
45569 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45570 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45571 {
45572 unsigned long jif = jiffies - start_jif;
45573 if (jif >= HZ)
45574 jif = HZ - 1;
45575 - atomic_inc(&histogram[jif]);
45576 + atomic_inc_unchecked(&histogram[jif]);
45577 }
45578
45579 #else
45580 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45581 index b0b5f7c..039bb26 100644
45582 --- a/fs/cachefiles/namei.c
45583 +++ b/fs/cachefiles/namei.c
45584 @@ -318,7 +318,7 @@ try_again:
45585 /* first step is to make up a grave dentry in the graveyard */
45586 sprintf(nbuffer, "%08x%08x",
45587 (uint32_t) get_seconds(),
45588 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45589 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45590
45591 /* do the multiway lock magic */
45592 trap = lock_rename(cache->graveyard, dir);
45593 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45594 index eccd339..4c1d995 100644
45595 --- a/fs/cachefiles/proc.c
45596 +++ b/fs/cachefiles/proc.c
45597 @@ -14,9 +14,9 @@
45598 #include <linux/seq_file.h>
45599 #include "internal.h"
45600
45601 -atomic_t cachefiles_lookup_histogram[HZ];
45602 -atomic_t cachefiles_mkdir_histogram[HZ];
45603 -atomic_t cachefiles_create_histogram[HZ];
45604 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45605 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45606 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45607
45608 /*
45609 * display the latency histogram
45610 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45611 return 0;
45612 default:
45613 index = (unsigned long) v - 3;
45614 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45615 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45616 - z = atomic_read(&cachefiles_create_histogram[index]);
45617 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45618 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45619 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45620 if (x == 0 && y == 0 && z == 0)
45621 return 0;
45622
45623 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45624 index c994691..2a1537f 100644
45625 --- a/fs/cachefiles/rdwr.c
45626 +++ b/fs/cachefiles/rdwr.c
45627 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45628 old_fs = get_fs();
45629 set_fs(KERNEL_DS);
45630 ret = file->f_op->write(
45631 - file, (const void __user *) data, len, &pos);
45632 + file, (const void __force_user *) data, len, &pos);
45633 set_fs(old_fs);
45634 kunmap(page);
45635 if (ret != len)
45636 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45637 index e5b7731..b9c59fb 100644
45638 --- a/fs/ceph/dir.c
45639 +++ b/fs/ceph/dir.c
45640 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45641 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45642 struct ceph_mds_client *mdsc = fsc->mdsc;
45643 unsigned frag = fpos_frag(filp->f_pos);
45644 - int off = fpos_off(filp->f_pos);
45645 + unsigned int off = fpos_off(filp->f_pos);
45646 int err;
45647 u32 ftype;
45648 struct ceph_mds_reply_info_parsed *rinfo;
45649 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45650 index d9ea6ed..1e6c8ac 100644
45651 --- a/fs/cifs/cifs_debug.c
45652 +++ b/fs/cifs/cifs_debug.c
45653 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45654
45655 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45656 #ifdef CONFIG_CIFS_STATS2
45657 - atomic_set(&totBufAllocCount, 0);
45658 - atomic_set(&totSmBufAllocCount, 0);
45659 + atomic_set_unchecked(&totBufAllocCount, 0);
45660 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45661 #endif /* CONFIG_CIFS_STATS2 */
45662 spin_lock(&cifs_tcp_ses_lock);
45663 list_for_each(tmp1, &cifs_tcp_ses_list) {
45664 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45665 tcon = list_entry(tmp3,
45666 struct cifs_tcon,
45667 tcon_list);
45668 - atomic_set(&tcon->num_smbs_sent, 0);
45669 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45670 if (server->ops->clear_stats)
45671 server->ops->clear_stats(tcon);
45672 }
45673 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45674 smBufAllocCount.counter, cifs_min_small);
45675 #ifdef CONFIG_CIFS_STATS2
45676 seq_printf(m, "Total Large %d Small %d Allocations\n",
45677 - atomic_read(&totBufAllocCount),
45678 - atomic_read(&totSmBufAllocCount));
45679 + atomic_read_unchecked(&totBufAllocCount),
45680 + atomic_read_unchecked(&totSmBufAllocCount));
45681 #endif /* CONFIG_CIFS_STATS2 */
45682
45683 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45684 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45685 if (tcon->need_reconnect)
45686 seq_puts(m, "\tDISCONNECTED ");
45687 seq_printf(m, "\nSMBs: %d",
45688 - atomic_read(&tcon->num_smbs_sent));
45689 + atomic_read_unchecked(&tcon->num_smbs_sent));
45690 if (server->ops->print_stats)
45691 server->ops->print_stats(m, tcon);
45692 }
45693 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45694 index e7931cc..76a1ab9 100644
45695 --- a/fs/cifs/cifsfs.c
45696 +++ b/fs/cifs/cifsfs.c
45697 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45698 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45699 cifs_req_cachep = kmem_cache_create("cifs_request",
45700 CIFSMaxBufSize + max_hdr_size, 0,
45701 - SLAB_HWCACHE_ALIGN, NULL);
45702 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45703 if (cifs_req_cachep == NULL)
45704 return -ENOMEM;
45705
45706 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45707 efficient to alloc 1 per page off the slab compared to 17K (5page)
45708 alloc of large cifs buffers even when page debugging is on */
45709 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45710 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45711 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45712 NULL);
45713 if (cifs_sm_req_cachep == NULL) {
45714 mempool_destroy(cifs_req_poolp);
45715 @@ -1111,8 +1111,8 @@ init_cifs(void)
45716 atomic_set(&bufAllocCount, 0);
45717 atomic_set(&smBufAllocCount, 0);
45718 #ifdef CONFIG_CIFS_STATS2
45719 - atomic_set(&totBufAllocCount, 0);
45720 - atomic_set(&totSmBufAllocCount, 0);
45721 + atomic_set_unchecked(&totBufAllocCount, 0);
45722 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45723 #endif /* CONFIG_CIFS_STATS2 */
45724
45725 atomic_set(&midCount, 0);
45726 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45727 index f5af252..489b5f2 100644
45728 --- a/fs/cifs/cifsglob.h
45729 +++ b/fs/cifs/cifsglob.h
45730 @@ -751,35 +751,35 @@ struct cifs_tcon {
45731 __u16 Flags; /* optional support bits */
45732 enum statusEnum tidStatus;
45733 #ifdef CONFIG_CIFS_STATS
45734 - atomic_t num_smbs_sent;
45735 + atomic_unchecked_t num_smbs_sent;
45736 union {
45737 struct {
45738 - atomic_t num_writes;
45739 - atomic_t num_reads;
45740 - atomic_t num_flushes;
45741 - atomic_t num_oplock_brks;
45742 - atomic_t num_opens;
45743 - atomic_t num_closes;
45744 - atomic_t num_deletes;
45745 - atomic_t num_mkdirs;
45746 - atomic_t num_posixopens;
45747 - atomic_t num_posixmkdirs;
45748 - atomic_t num_rmdirs;
45749 - atomic_t num_renames;
45750 - atomic_t num_t2renames;
45751 - atomic_t num_ffirst;
45752 - atomic_t num_fnext;
45753 - atomic_t num_fclose;
45754 - atomic_t num_hardlinks;
45755 - atomic_t num_symlinks;
45756 - atomic_t num_locks;
45757 - atomic_t num_acl_get;
45758 - atomic_t num_acl_set;
45759 + atomic_unchecked_t num_writes;
45760 + atomic_unchecked_t num_reads;
45761 + atomic_unchecked_t num_flushes;
45762 + atomic_unchecked_t num_oplock_brks;
45763 + atomic_unchecked_t num_opens;
45764 + atomic_unchecked_t num_closes;
45765 + atomic_unchecked_t num_deletes;
45766 + atomic_unchecked_t num_mkdirs;
45767 + atomic_unchecked_t num_posixopens;
45768 + atomic_unchecked_t num_posixmkdirs;
45769 + atomic_unchecked_t num_rmdirs;
45770 + atomic_unchecked_t num_renames;
45771 + atomic_unchecked_t num_t2renames;
45772 + atomic_unchecked_t num_ffirst;
45773 + atomic_unchecked_t num_fnext;
45774 + atomic_unchecked_t num_fclose;
45775 + atomic_unchecked_t num_hardlinks;
45776 + atomic_unchecked_t num_symlinks;
45777 + atomic_unchecked_t num_locks;
45778 + atomic_unchecked_t num_acl_get;
45779 + atomic_unchecked_t num_acl_set;
45780 } cifs_stats;
45781 #ifdef CONFIG_CIFS_SMB2
45782 struct {
45783 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45784 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45785 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45786 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45787 } smb2_stats;
45788 #endif /* CONFIG_CIFS_SMB2 */
45789 } stats;
45790 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45791 }
45792
45793 #ifdef CONFIG_CIFS_STATS
45794 -#define cifs_stats_inc atomic_inc
45795 +#define cifs_stats_inc atomic_inc_unchecked
45796
45797 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45798 unsigned int bytes)
45799 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45800 /* Various Debug counters */
45801 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45802 #ifdef CONFIG_CIFS_STATS2
45803 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45804 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45805 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45806 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45807 #endif
45808 GLOBAL_EXTERN atomic_t smBufAllocCount;
45809 GLOBAL_EXTERN atomic_t midCount;
45810 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45811 index 51dc2fb..1e12a33 100644
45812 --- a/fs/cifs/link.c
45813 +++ b/fs/cifs/link.c
45814 @@ -616,7 +616,7 @@ symlink_exit:
45815
45816 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45817 {
45818 - char *p = nd_get_link(nd);
45819 + const char *p = nd_get_link(nd);
45820 if (!IS_ERR(p))
45821 kfree(p);
45822 }
45823 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45824 index 3a00c0d..42d901c 100644
45825 --- a/fs/cifs/misc.c
45826 +++ b/fs/cifs/misc.c
45827 @@ -169,7 +169,7 @@ cifs_buf_get(void)
45828 memset(ret_buf, 0, buf_size + 3);
45829 atomic_inc(&bufAllocCount);
45830 #ifdef CONFIG_CIFS_STATS2
45831 - atomic_inc(&totBufAllocCount);
45832 + atomic_inc_unchecked(&totBufAllocCount);
45833 #endif /* CONFIG_CIFS_STATS2 */
45834 }
45835
45836 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
45837 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
45838 atomic_inc(&smBufAllocCount);
45839 #ifdef CONFIG_CIFS_STATS2
45840 - atomic_inc(&totSmBufAllocCount);
45841 + atomic_inc_unchecked(&totSmBufAllocCount);
45842 #endif /* CONFIG_CIFS_STATS2 */
45843
45844 }
45845 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
45846 index 591bf19..690d600 100644
45847 --- a/fs/cifs/smb1ops.c
45848 +++ b/fs/cifs/smb1ops.c
45849 @@ -617,27 +617,27 @@ static void
45850 cifs_clear_stats(struct cifs_tcon *tcon)
45851 {
45852 #ifdef CONFIG_CIFS_STATS
45853 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
45854 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
45855 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
45856 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45857 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
45858 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
45859 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45860 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
45861 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
45862 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
45863 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
45864 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
45865 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
45866 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
45867 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
45868 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
45869 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
45870 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
45871 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
45872 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
45873 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
45874 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
45875 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
45876 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
45877 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45878 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
45879 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
45880 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45881 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
45882 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
45883 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
45884 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
45885 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
45886 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
45887 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
45888 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
45889 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
45890 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
45891 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
45892 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
45893 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
45894 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
45895 #endif
45896 }
45897
45898 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45899 {
45900 #ifdef CONFIG_CIFS_STATS
45901 seq_printf(m, " Oplocks breaks: %d",
45902 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
45903 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
45904 seq_printf(m, "\nReads: %d Bytes: %llu",
45905 - atomic_read(&tcon->stats.cifs_stats.num_reads),
45906 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
45907 (long long)(tcon->bytes_read));
45908 seq_printf(m, "\nWrites: %d Bytes: %llu",
45909 - atomic_read(&tcon->stats.cifs_stats.num_writes),
45910 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
45911 (long long)(tcon->bytes_written));
45912 seq_printf(m, "\nFlushes: %d",
45913 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
45914 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
45915 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
45916 - atomic_read(&tcon->stats.cifs_stats.num_locks),
45917 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
45918 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
45919 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
45920 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
45921 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
45922 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
45923 - atomic_read(&tcon->stats.cifs_stats.num_opens),
45924 - atomic_read(&tcon->stats.cifs_stats.num_closes),
45925 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
45926 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
45927 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
45928 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
45929 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
45930 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
45931 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
45932 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
45933 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
45934 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
45935 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
45936 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
45937 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
45938 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
45939 seq_printf(m, "\nRenames: %d T2 Renames %d",
45940 - atomic_read(&tcon->stats.cifs_stats.num_renames),
45941 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
45942 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
45943 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
45944 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
45945 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
45946 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
45947 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
45948 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
45949 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
45950 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
45951 #endif
45952 }
45953
45954 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
45955 index 4d9dbe0..0af4601 100644
45956 --- a/fs/cifs/smb2ops.c
45957 +++ b/fs/cifs/smb2ops.c
45958 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
45959 #ifdef CONFIG_CIFS_STATS
45960 int i;
45961 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
45962 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45963 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45964 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45965 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45966 }
45967 #endif
45968 }
45969 @@ -301,66 +301,66 @@ static void
45970 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45971 {
45972 #ifdef CONFIG_CIFS_STATS
45973 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45974 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45975 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45976 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45977 seq_printf(m, "\nNegotiates: %d sent %d failed",
45978 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
45979 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
45980 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
45981 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
45982 seq_printf(m, "\nSessionSetups: %d sent %d failed",
45983 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
45984 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
45985 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
45986 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
45987 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
45988 seq_printf(m, "\nLogoffs: %d sent %d failed",
45989 - atomic_read(&sent[SMB2_LOGOFF_HE]),
45990 - atomic_read(&failed[SMB2_LOGOFF_HE]));
45991 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
45992 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
45993 seq_printf(m, "\nTreeConnects: %d sent %d failed",
45994 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
45995 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
45996 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
45997 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
45998 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
45999 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46000 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46001 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46002 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46003 seq_printf(m, "\nCreates: %d sent %d failed",
46004 - atomic_read(&sent[SMB2_CREATE_HE]),
46005 - atomic_read(&failed[SMB2_CREATE_HE]));
46006 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46007 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46008 seq_printf(m, "\nCloses: %d sent %d failed",
46009 - atomic_read(&sent[SMB2_CLOSE_HE]),
46010 - atomic_read(&failed[SMB2_CLOSE_HE]));
46011 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46012 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46013 seq_printf(m, "\nFlushes: %d sent %d failed",
46014 - atomic_read(&sent[SMB2_FLUSH_HE]),
46015 - atomic_read(&failed[SMB2_FLUSH_HE]));
46016 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46017 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46018 seq_printf(m, "\nReads: %d sent %d failed",
46019 - atomic_read(&sent[SMB2_READ_HE]),
46020 - atomic_read(&failed[SMB2_READ_HE]));
46021 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46022 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46023 seq_printf(m, "\nWrites: %d sent %d failed",
46024 - atomic_read(&sent[SMB2_WRITE_HE]),
46025 - atomic_read(&failed[SMB2_WRITE_HE]));
46026 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46027 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46028 seq_printf(m, "\nLocks: %d sent %d failed",
46029 - atomic_read(&sent[SMB2_LOCK_HE]),
46030 - atomic_read(&failed[SMB2_LOCK_HE]));
46031 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46032 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46033 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46034 - atomic_read(&sent[SMB2_IOCTL_HE]),
46035 - atomic_read(&failed[SMB2_IOCTL_HE]));
46036 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46037 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46038 seq_printf(m, "\nCancels: %d sent %d failed",
46039 - atomic_read(&sent[SMB2_CANCEL_HE]),
46040 - atomic_read(&failed[SMB2_CANCEL_HE]));
46041 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46042 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46043 seq_printf(m, "\nEchos: %d sent %d failed",
46044 - atomic_read(&sent[SMB2_ECHO_HE]),
46045 - atomic_read(&failed[SMB2_ECHO_HE]));
46046 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46047 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46048 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46049 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46050 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46051 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46052 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46053 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46054 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46055 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46056 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46057 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46058 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46059 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46060 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46061 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46062 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46063 seq_printf(m, "\nSetInfos: %d sent %d failed",
46064 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46065 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46066 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46067 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46068 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46069 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46070 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46071 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46072 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46073 #endif
46074 }
46075
46076 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46077 index 958ae0e..505c9d0 100644
46078 --- a/fs/coda/cache.c
46079 +++ b/fs/coda/cache.c
46080 @@ -24,7 +24,7 @@
46081 #include "coda_linux.h"
46082 #include "coda_cache.h"
46083
46084 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46085 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46086
46087 /* replace or extend an acl cache hit */
46088 void coda_cache_enter(struct inode *inode, int mask)
46089 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46090 struct coda_inode_info *cii = ITOC(inode);
46091
46092 spin_lock(&cii->c_lock);
46093 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46094 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46095 if (cii->c_uid != current_fsuid()) {
46096 cii->c_uid = current_fsuid();
46097 cii->c_cached_perm = mask;
46098 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46099 {
46100 struct coda_inode_info *cii = ITOC(inode);
46101 spin_lock(&cii->c_lock);
46102 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46103 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46104 spin_unlock(&cii->c_lock);
46105 }
46106
46107 /* remove all acl caches */
46108 void coda_cache_clear_all(struct super_block *sb)
46109 {
46110 - atomic_inc(&permission_epoch);
46111 + atomic_inc_unchecked(&permission_epoch);
46112 }
46113
46114
46115 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46116 spin_lock(&cii->c_lock);
46117 hit = (mask & cii->c_cached_perm) == mask &&
46118 cii->c_uid == current_fsuid() &&
46119 - cii->c_cached_epoch == atomic_read(&permission_epoch);
46120 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46121 spin_unlock(&cii->c_lock);
46122
46123 return hit;
46124 diff --git a/fs/compat.c b/fs/compat.c
46125 index 015e1e1..5ce8e54 100644
46126 --- a/fs/compat.c
46127 +++ b/fs/compat.c
46128 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46129
46130 set_fs(KERNEL_DS);
46131 /* The __user pointer cast is valid because of the set_fs() */
46132 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46133 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46134 set_fs(oldfs);
46135 /* truncating is ok because it's a user address */
46136 if (!ret)
46137 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46138 goto out;
46139
46140 ret = -EINVAL;
46141 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46142 + if (nr_segs > UIO_MAXIOV)
46143 goto out;
46144 if (nr_segs > fast_segs) {
46145 ret = -ENOMEM;
46146 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46147
46148 struct compat_readdir_callback {
46149 struct compat_old_linux_dirent __user *dirent;
46150 + struct file * file;
46151 int result;
46152 };
46153
46154 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46155 buf->result = -EOVERFLOW;
46156 return -EOVERFLOW;
46157 }
46158 +
46159 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46160 + return 0;
46161 +
46162 buf->result++;
46163 dirent = buf->dirent;
46164 if (!access_ok(VERIFY_WRITE, dirent,
46165 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46166
46167 buf.result = 0;
46168 buf.dirent = dirent;
46169 + buf.file = f.file;
46170
46171 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46172 if (buf.result)
46173 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
46174 struct compat_getdents_callback {
46175 struct compat_linux_dirent __user *current_dir;
46176 struct compat_linux_dirent __user *previous;
46177 + struct file * file;
46178 int count;
46179 int error;
46180 };
46181 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46182 buf->error = -EOVERFLOW;
46183 return -EOVERFLOW;
46184 }
46185 +
46186 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46187 + return 0;
46188 +
46189 dirent = buf->previous;
46190 if (dirent) {
46191 if (__put_user(offset, &dirent->d_off))
46192 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46193 buf.previous = NULL;
46194 buf.count = count;
46195 buf.error = 0;
46196 + buf.file = f.file;
46197
46198 error = vfs_readdir(f.file, compat_filldir, &buf);
46199 if (error >= 0)
46200 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46201 struct compat_getdents_callback64 {
46202 struct linux_dirent64 __user *current_dir;
46203 struct linux_dirent64 __user *previous;
46204 + struct file * file;
46205 int count;
46206 int error;
46207 };
46208 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46209 buf->error = -EINVAL; /* only used if we fail.. */
46210 if (reclen > buf->count)
46211 return -EINVAL;
46212 +
46213 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46214 + return 0;
46215 +
46216 dirent = buf->previous;
46217
46218 if (dirent) {
46219 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46220 buf.previous = NULL;
46221 buf.count = count;
46222 buf.error = 0;
46223 + buf.file = f.file;
46224
46225 error = vfs_readdir(f.file, compat_filldir64, &buf);
46226 if (error >= 0)
46227 error = buf.error;
46228 lastdirent = buf.previous;
46229 if (lastdirent) {
46230 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
46231 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46232 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46233 error = -EFAULT;
46234 else
46235 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46236 index a81147e..20bf2b5 100644
46237 --- a/fs/compat_binfmt_elf.c
46238 +++ b/fs/compat_binfmt_elf.c
46239 @@ -30,11 +30,13 @@
46240 #undef elf_phdr
46241 #undef elf_shdr
46242 #undef elf_note
46243 +#undef elf_dyn
46244 #undef elf_addr_t
46245 #define elfhdr elf32_hdr
46246 #define elf_phdr elf32_phdr
46247 #define elf_shdr elf32_shdr
46248 #define elf_note elf32_note
46249 +#define elf_dyn Elf32_Dyn
46250 #define elf_addr_t Elf32_Addr
46251
46252 /*
46253 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46254 index 4c6285f..b7a2411 100644
46255 --- a/fs/compat_ioctl.c
46256 +++ b/fs/compat_ioctl.c
46257 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46258 return -EFAULT;
46259 if (__get_user(udata, &ss32->iomem_base))
46260 return -EFAULT;
46261 - ss.iomem_base = compat_ptr(udata);
46262 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46263 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46264 __get_user(ss.port_high, &ss32->port_high))
46265 return -EFAULT;
46266 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46267 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46268 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46269 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46270 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46271 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46272 return -EFAULT;
46273
46274 return ioctl_preallocate(file, p);
46275 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46276 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46277 {
46278 unsigned int a, b;
46279 - a = *(unsigned int *)p;
46280 - b = *(unsigned int *)q;
46281 + a = *(const unsigned int *)p;
46282 + b = *(const unsigned int *)q;
46283 if (a > b)
46284 return 1;
46285 if (a < b)
46286 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46287 index 7414ae2..d98ad6d 100644
46288 --- a/fs/configfs/dir.c
46289 +++ b/fs/configfs/dir.c
46290 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46291 }
46292 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46293 struct configfs_dirent *next;
46294 - const char * name;
46295 + const unsigned char * name;
46296 + char d_name[sizeof(next->s_dentry->d_iname)];
46297 int len;
46298 struct inode *inode = NULL;
46299
46300 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46301 continue;
46302
46303 name = configfs_get_name(next);
46304 - len = strlen(name);
46305 + if (next->s_dentry && name == next->s_dentry->d_iname) {
46306 + len = next->s_dentry->d_name.len;
46307 + memcpy(d_name, name, len);
46308 + name = d_name;
46309 + } else
46310 + len = strlen(name);
46311
46312 /*
46313 * We'll have a dentry and an inode for
46314 diff --git a/fs/coredump.c b/fs/coredump.c
46315 index ce47379..68c8e43 100644
46316 --- a/fs/coredump.c
46317 +++ b/fs/coredump.c
46318 @@ -52,7 +52,7 @@ struct core_name {
46319 char *corename;
46320 int used, size;
46321 };
46322 -static atomic_t call_count = ATOMIC_INIT(1);
46323 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46324
46325 /* The maximal length of core_pattern is also specified in sysctl.c */
46326
46327 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46328 {
46329 char *old_corename = cn->corename;
46330
46331 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46332 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46333 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46334
46335 if (!cn->corename) {
46336 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46337 int pid_in_pattern = 0;
46338 int err = 0;
46339
46340 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46341 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46342 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46343 cn->used = 0;
46344
46345 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46346 pipe = file->f_path.dentry->d_inode->i_pipe;
46347
46348 pipe_lock(pipe);
46349 - pipe->readers++;
46350 - pipe->writers--;
46351 + atomic_inc(&pipe->readers);
46352 + atomic_dec(&pipe->writers);
46353
46354 - while ((pipe->readers > 1) && (!signal_pending(current))) {
46355 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46356 wake_up_interruptible_sync(&pipe->wait);
46357 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46358 pipe_wait(pipe);
46359 }
46360
46361 - pipe->readers--;
46362 - pipe->writers++;
46363 + atomic_dec(&pipe->readers);
46364 + atomic_inc(&pipe->writers);
46365 pipe_unlock(pipe);
46366
46367 }
46368 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46369 int ispipe;
46370 struct files_struct *displaced;
46371 bool need_nonrelative = false;
46372 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46373 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46374 + long signr = siginfo->si_signo;
46375 struct coredump_params cprm = {
46376 .siginfo = siginfo,
46377 .regs = regs,
46378 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46379 .mm_flags = mm->flags,
46380 };
46381
46382 - audit_core_dumps(siginfo->si_signo);
46383 + audit_core_dumps(signr);
46384 +
46385 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46386 + gr_handle_brute_attach(cprm.mm_flags);
46387
46388 binfmt = mm->binfmt;
46389 if (!binfmt || !binfmt->core_dump)
46390 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46391 need_nonrelative = true;
46392 }
46393
46394 - retval = coredump_wait(siginfo->si_signo, &core_state);
46395 + retval = coredump_wait(signr, &core_state);
46396 if (retval < 0)
46397 goto fail_creds;
46398
46399 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46400 }
46401 cprm.limit = RLIM_INFINITY;
46402
46403 - dump_count = atomic_inc_return(&core_dump_count);
46404 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46405 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46406 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46407 task_tgid_vnr(current), current->comm);
46408 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46409 } else {
46410 struct inode *inode;
46411
46412 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46413 +
46414 if (cprm.limit < binfmt->min_coredump)
46415 goto fail_unlock;
46416
46417 @@ -640,7 +646,7 @@ close_fail:
46418 filp_close(cprm.file, NULL);
46419 fail_dropcount:
46420 if (ispipe)
46421 - atomic_dec(&core_dump_count);
46422 + atomic_dec_unchecked(&core_dump_count);
46423 fail_unlock:
46424 kfree(cn.corename);
46425 fail_corename:
46426 @@ -659,7 +665,7 @@ fail:
46427 */
46428 int dump_write(struct file *file, const void *addr, int nr)
46429 {
46430 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46431 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46432 }
46433 EXPORT_SYMBOL(dump_write);
46434
46435 diff --git a/fs/dcache.c b/fs/dcache.c
46436 index 0d0adb6..f4646e9 100644
46437 --- a/fs/dcache.c
46438 +++ b/fs/dcache.c
46439 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46440 mempages -= reserve;
46441
46442 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46443 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46444 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46445
46446 dcache_init();
46447 inode_init();
46448 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46449 index b607d92..41fda09 100644
46450 --- a/fs/debugfs/inode.c
46451 +++ b/fs/debugfs/inode.c
46452 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46453 */
46454 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46455 {
46456 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46457 + return __create_file(name, S_IFDIR | S_IRWXU,
46458 +#else
46459 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46460 +#endif
46461 parent, NULL, NULL);
46462 }
46463 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46464 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46465 index cc7709e..7e7211f 100644
46466 --- a/fs/ecryptfs/inode.c
46467 +++ b/fs/ecryptfs/inode.c
46468 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46469 old_fs = get_fs();
46470 set_fs(get_ds());
46471 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46472 - (char __user *)lower_buf,
46473 + (char __force_user *)lower_buf,
46474 PATH_MAX);
46475 set_fs(old_fs);
46476 if (rc < 0)
46477 @@ -706,7 +706,7 @@ out:
46478 static void
46479 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46480 {
46481 - char *buf = nd_get_link(nd);
46482 + const char *buf = nd_get_link(nd);
46483 if (!IS_ERR(buf)) {
46484 /* Free the char* */
46485 kfree(buf);
46486 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46487 index 412e6ed..4292d22 100644
46488 --- a/fs/ecryptfs/miscdev.c
46489 +++ b/fs/ecryptfs/miscdev.c
46490 @@ -315,7 +315,7 @@ check_list:
46491 goto out_unlock_msg_ctx;
46492 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46493 if (msg_ctx->msg) {
46494 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46495 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46496 goto out_unlock_msg_ctx;
46497 i += packet_length_size;
46498 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46499 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46500 index b2a34a1..162fa69 100644
46501 --- a/fs/ecryptfs/read_write.c
46502 +++ b/fs/ecryptfs/read_write.c
46503 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46504 return -EIO;
46505 fs_save = get_fs();
46506 set_fs(get_ds());
46507 - rc = vfs_write(lower_file, data, size, &offset);
46508 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46509 set_fs(fs_save);
46510 mark_inode_dirty_sync(ecryptfs_inode);
46511 return rc;
46512 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46513 return -EIO;
46514 fs_save = get_fs();
46515 set_fs(get_ds());
46516 - rc = vfs_read(lower_file, data, size, &offset);
46517 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46518 set_fs(fs_save);
46519 return rc;
46520 }
46521 diff --git a/fs/exec.c b/fs/exec.c
46522 index c6e6de4..45e71ad 100644
46523 --- a/fs/exec.c
46524 +++ b/fs/exec.c
46525 @@ -55,6 +55,17 @@
46526 #include <linux/pipe_fs_i.h>
46527 #include <linux/oom.h>
46528 #include <linux/compat.h>
46529 +#include <linux/random.h>
46530 +#include <linux/seq_file.h>
46531 +#include <linux/coredump.h>
46532 +#include <linux/mman.h>
46533 +
46534 +#ifdef CONFIG_PAX_REFCOUNT
46535 +#include <linux/kallsyms.h>
46536 +#include <linux/kdebug.h>
46537 +#endif
46538 +
46539 +#include <trace/events/fs.h>
46540
46541 #include <asm/uaccess.h>
46542 #include <asm/mmu_context.h>
46543 @@ -66,6 +77,18 @@
46544
46545 #include <trace/events/sched.h>
46546
46547 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46548 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46549 +{
46550 + 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");
46551 +}
46552 +#endif
46553 +
46554 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46555 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46556 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46557 +#endif
46558 +
46559 int suid_dumpable = 0;
46560
46561 static LIST_HEAD(formats);
46562 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46563 int write)
46564 {
46565 struct page *page;
46566 - int ret;
46567
46568 -#ifdef CONFIG_STACK_GROWSUP
46569 - if (write) {
46570 - ret = expand_downwards(bprm->vma, pos);
46571 - if (ret < 0)
46572 - return NULL;
46573 - }
46574 -#endif
46575 - ret = get_user_pages(current, bprm->mm, pos,
46576 - 1, write, 1, &page, NULL);
46577 - if (ret <= 0)
46578 + if (0 > expand_downwards(bprm->vma, pos))
46579 + return NULL;
46580 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46581 return NULL;
46582
46583 if (write) {
46584 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46585 if (size <= ARG_MAX)
46586 return page;
46587
46588 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46589 + // only allow 512KB for argv+env on suid/sgid binaries
46590 + // to prevent easy ASLR exhaustion
46591 + if (((bprm->cred->euid != current_euid()) ||
46592 + (bprm->cred->egid != current_egid())) &&
46593 + (size > (512 * 1024))) {
46594 + put_page(page);
46595 + return NULL;
46596 + }
46597 +#endif
46598 +
46599 /*
46600 * Limit to 1/4-th the stack size for the argv+env strings.
46601 * This ensures that:
46602 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46603 vma->vm_end = STACK_TOP_MAX;
46604 vma->vm_start = vma->vm_end - PAGE_SIZE;
46605 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46606 +
46607 +#ifdef CONFIG_PAX_SEGMEXEC
46608 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46609 +#endif
46610 +
46611 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46612 INIT_LIST_HEAD(&vma->anon_vma_chain);
46613
46614 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46615 mm->stack_vm = mm->total_vm = 1;
46616 up_write(&mm->mmap_sem);
46617 bprm->p = vma->vm_end - sizeof(void *);
46618 +
46619 +#ifdef CONFIG_PAX_RANDUSTACK
46620 + if (randomize_va_space)
46621 + bprm->p ^= random32() & ~PAGE_MASK;
46622 +#endif
46623 +
46624 return 0;
46625 err:
46626 up_write(&mm->mmap_sem);
46627 @@ -384,19 +421,7 @@ err:
46628 return err;
46629 }
46630
46631 -struct user_arg_ptr {
46632 -#ifdef CONFIG_COMPAT
46633 - bool is_compat;
46634 -#endif
46635 - union {
46636 - const char __user *const __user *native;
46637 -#ifdef CONFIG_COMPAT
46638 - const compat_uptr_t __user *compat;
46639 -#endif
46640 - } ptr;
46641 -};
46642 -
46643 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46644 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46645 {
46646 const char __user *native;
46647
46648 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46649 compat_uptr_t compat;
46650
46651 if (get_user(compat, argv.ptr.compat + nr))
46652 - return ERR_PTR(-EFAULT);
46653 + return (const char __force_user *)ERR_PTR(-EFAULT);
46654
46655 return compat_ptr(compat);
46656 }
46657 #endif
46658
46659 if (get_user(native, argv.ptr.native + nr))
46660 - return ERR_PTR(-EFAULT);
46661 + return (const char __force_user *)ERR_PTR(-EFAULT);
46662
46663 return native;
46664 }
46665 @@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46666 if (!p)
46667 break;
46668
46669 - if (IS_ERR(p))
46670 + if (IS_ERR((const char __force_kernel *)p))
46671 return -EFAULT;
46672
46673 - if (i++ >= max)
46674 + if (i >= max)
46675 return -E2BIG;
46676 + ++i;
46677
46678 if (fatal_signal_pending(current))
46679 return -ERESTARTNOHAND;
46680 @@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46681
46682 ret = -EFAULT;
46683 str = get_user_arg_ptr(argv, argc);
46684 - if (IS_ERR(str))
46685 + if (IS_ERR((const char __force_kernel *)str))
46686 goto out;
46687
46688 len = strnlen_user(str, MAX_ARG_STRLEN);
46689 @@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46690 int r;
46691 mm_segment_t oldfs = get_fs();
46692 struct user_arg_ptr argv = {
46693 - .ptr.native = (const char __user *const __user *)__argv,
46694 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46695 };
46696
46697 set_fs(KERNEL_DS);
46698 @@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46699 unsigned long new_end = old_end - shift;
46700 struct mmu_gather tlb;
46701
46702 - BUG_ON(new_start > new_end);
46703 + if (new_start >= new_end || new_start < mmap_min_addr)
46704 + return -ENOMEM;
46705
46706 /*
46707 * ensure there are no vmas between where we want to go
46708 @@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46709 if (vma != find_vma(mm, new_start))
46710 return -EFAULT;
46711
46712 +#ifdef CONFIG_PAX_SEGMEXEC
46713 + BUG_ON(pax_find_mirror_vma(vma));
46714 +#endif
46715 +
46716 /*
46717 * cover the whole range: [new_start, old_end)
46718 */
46719 @@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46720 stack_top = arch_align_stack(stack_top);
46721 stack_top = PAGE_ALIGN(stack_top);
46722
46723 - if (unlikely(stack_top < mmap_min_addr) ||
46724 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46725 - return -ENOMEM;
46726 -
46727 stack_shift = vma->vm_end - stack_top;
46728
46729 bprm->p -= stack_shift;
46730 @@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46731 bprm->exec -= stack_shift;
46732
46733 down_write(&mm->mmap_sem);
46734 +
46735 + /* Move stack pages down in memory. */
46736 + if (stack_shift) {
46737 + ret = shift_arg_pages(vma, stack_shift);
46738 + if (ret)
46739 + goto out_unlock;
46740 + }
46741 +
46742 vm_flags = VM_STACK_FLAGS;
46743
46744 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46745 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46746 + vm_flags &= ~VM_EXEC;
46747 +
46748 +#ifdef CONFIG_PAX_MPROTECT
46749 + if (mm->pax_flags & MF_PAX_MPROTECT)
46750 + vm_flags &= ~VM_MAYEXEC;
46751 +#endif
46752 +
46753 + }
46754 +#endif
46755 +
46756 /*
46757 * Adjust stack execute permissions; explicitly enable for
46758 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46759 @@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46760 goto out_unlock;
46761 BUG_ON(prev != vma);
46762
46763 - /* Move stack pages down in memory. */
46764 - if (stack_shift) {
46765 - ret = shift_arg_pages(vma, stack_shift);
46766 - if (ret)
46767 - goto out_unlock;
46768 - }
46769 -
46770 /* mprotect_fixup is overkill to remove the temporary stack flags */
46771 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46772
46773 @@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46774 #endif
46775 current->mm->start_stack = bprm->p;
46776 ret = expand_stack(vma, stack_base);
46777 +
46778 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46779 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46780 + unsigned long size, flags, vm_flags;
46781 +
46782 + size = STACK_TOP - vma->vm_end;
46783 + flags = MAP_FIXED | MAP_PRIVATE;
46784 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46785 +
46786 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46787 +
46788 +#ifdef CONFIG_X86
46789 + if (!ret) {
46790 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46791 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46792 + }
46793 +#endif
46794 +
46795 + }
46796 +#endif
46797 +
46798 if (ret)
46799 ret = -EFAULT;
46800
46801 @@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46802
46803 fsnotify_open(file);
46804
46805 + trace_open_exec(name);
46806 +
46807 err = deny_write_access(file);
46808 if (err)
46809 goto exit;
46810 @@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46811 old_fs = get_fs();
46812 set_fs(get_ds());
46813 /* The cast to a user pointer is valid due to the set_fs() */
46814 - result = vfs_read(file, (void __user *)addr, count, &pos);
46815 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
46816 set_fs(old_fs);
46817 return result;
46818 }
46819 @@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46820 }
46821 rcu_read_unlock();
46822
46823 - if (p->fs->users > n_fs) {
46824 + if (atomic_read(&p->fs->users) > n_fs) {
46825 bprm->unsafe |= LSM_UNSAFE_SHARE;
46826 } else {
46827 res = -EAGAIN;
46828 @@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46829
46830 EXPORT_SYMBOL(search_binary_handler);
46831
46832 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46833 +static DEFINE_PER_CPU(u64, exec_counter);
46834 +static int __init init_exec_counters(void)
46835 +{
46836 + unsigned int cpu;
46837 +
46838 + for_each_possible_cpu(cpu) {
46839 + per_cpu(exec_counter, cpu) = (u64)cpu;
46840 + }
46841 +
46842 + return 0;
46843 +}
46844 +early_initcall(init_exec_counters);
46845 +static inline void increment_exec_counter(void)
46846 +{
46847 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
46848 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
46849 +}
46850 +#else
46851 +static inline void increment_exec_counter(void) {}
46852 +#endif
46853 +
46854 /*
46855 * sys_execve() executes a new program.
46856 */
46857 @@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
46858 struct user_arg_ptr envp,
46859 struct pt_regs *regs)
46860 {
46861 +#ifdef CONFIG_GRKERNSEC
46862 + struct file *old_exec_file;
46863 + struct acl_subject_label *old_acl;
46864 + struct rlimit old_rlim[RLIM_NLIMITS];
46865 +#endif
46866 struct linux_binprm *bprm;
46867 struct file *file;
46868 struct files_struct *displaced;
46869 @@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
46870 int retval;
46871 const struct cred *cred = current_cred();
46872
46873 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
46874 +
46875 /*
46876 * We move the actual failure in case of RLIMIT_NPROC excess from
46877 * set*uid() to execve() because too many poorly written programs
46878 @@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
46879 if (IS_ERR(file))
46880 goto out_unmark;
46881
46882 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
46883 + retval = -EPERM;
46884 + goto out_file;
46885 + }
46886 +
46887 sched_exec();
46888
46889 bprm->file = file;
46890 bprm->filename = filename;
46891 bprm->interp = filename;
46892
46893 + if (gr_process_user_ban()) {
46894 + retval = -EPERM;
46895 + goto out_file;
46896 + }
46897 +
46898 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
46899 + retval = -EACCES;
46900 + goto out_file;
46901 + }
46902 +
46903 retval = bprm_mm_init(bprm);
46904 if (retval)
46905 goto out_file;
46906 @@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
46907 if (retval < 0)
46908 goto out;
46909
46910 +#ifdef CONFIG_GRKERNSEC
46911 + old_acl = current->acl;
46912 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
46913 + old_exec_file = current->exec_file;
46914 + get_file(file);
46915 + current->exec_file = file;
46916 +#endif
46917 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46918 + /* limit suid stack to 8MB
46919 + we saved the old limits above and will restore them if this exec fails
46920 + */
46921 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
46922 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
46923 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
46924 +#endif
46925 +
46926 + if (!gr_tpe_allow(file)) {
46927 + retval = -EACCES;
46928 + goto out_fail;
46929 + }
46930 +
46931 + if (gr_check_crash_exec(file)) {
46932 + retval = -EACCES;
46933 + goto out_fail;
46934 + }
46935 +
46936 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
46937 + bprm->unsafe);
46938 + if (retval < 0)
46939 + goto out_fail;
46940 +
46941 retval = copy_strings_kernel(1, &bprm->filename, bprm);
46942 if (retval < 0)
46943 - goto out;
46944 + goto out_fail;
46945
46946 bprm->exec = bprm->p;
46947 retval = copy_strings(bprm->envc, envp, bprm);
46948 if (retval < 0)
46949 - goto out;
46950 + goto out_fail;
46951
46952 retval = copy_strings(bprm->argc, argv, bprm);
46953 if (retval < 0)
46954 - goto out;
46955 + goto out_fail;
46956 +
46957 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
46958 +
46959 + gr_handle_exec_args(bprm, argv);
46960
46961 retval = search_binary_handler(bprm,regs);
46962 if (retval < 0)
46963 - goto out;
46964 + goto out_fail;
46965 +#ifdef CONFIG_GRKERNSEC
46966 + if (old_exec_file)
46967 + fput(old_exec_file);
46968 +#endif
46969
46970 /* execve succeeded */
46971 +
46972 + increment_exec_counter();
46973 current->fs->in_exec = 0;
46974 current->in_execve = 0;
46975 acct_update_integrals(current);
46976 @@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
46977 put_files_struct(displaced);
46978 return retval;
46979
46980 +out_fail:
46981 +#ifdef CONFIG_GRKERNSEC
46982 + current->acl = old_acl;
46983 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
46984 + fput(current->exec_file);
46985 + current->exec_file = old_exec_file;
46986 +#endif
46987 +
46988 out:
46989 if (bprm->mm) {
46990 acct_arg_size(bprm, 0);
46991 @@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
46992 ret_from_kernel_execve(p);
46993 }
46994 #endif
46995 +
46996 +int pax_check_flags(unsigned long *flags)
46997 +{
46998 + int retval = 0;
46999 +
47000 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47001 + if (*flags & MF_PAX_SEGMEXEC)
47002 + {
47003 + *flags &= ~MF_PAX_SEGMEXEC;
47004 + retval = -EINVAL;
47005 + }
47006 +#endif
47007 +
47008 + if ((*flags & MF_PAX_PAGEEXEC)
47009 +
47010 +#ifdef CONFIG_PAX_PAGEEXEC
47011 + && (*flags & MF_PAX_SEGMEXEC)
47012 +#endif
47013 +
47014 + )
47015 + {
47016 + *flags &= ~MF_PAX_PAGEEXEC;
47017 + retval = -EINVAL;
47018 + }
47019 +
47020 + if ((*flags & MF_PAX_MPROTECT)
47021 +
47022 +#ifdef CONFIG_PAX_MPROTECT
47023 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47024 +#endif
47025 +
47026 + )
47027 + {
47028 + *flags &= ~MF_PAX_MPROTECT;
47029 + retval = -EINVAL;
47030 + }
47031 +
47032 + if ((*flags & MF_PAX_EMUTRAMP)
47033 +
47034 +#ifdef CONFIG_PAX_EMUTRAMP
47035 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47036 +#endif
47037 +
47038 + )
47039 + {
47040 + *flags &= ~MF_PAX_EMUTRAMP;
47041 + retval = -EINVAL;
47042 + }
47043 +
47044 + return retval;
47045 +}
47046 +
47047 +EXPORT_SYMBOL(pax_check_flags);
47048 +
47049 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47050 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47051 +{
47052 + struct task_struct *tsk = current;
47053 + struct mm_struct *mm = current->mm;
47054 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47055 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47056 + char *path_exec = NULL;
47057 + char *path_fault = NULL;
47058 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47059 + siginfo_t info = { };
47060 +
47061 + if (buffer_exec && buffer_fault) {
47062 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47063 +
47064 + down_read(&mm->mmap_sem);
47065 + vma = mm->mmap;
47066 + while (vma && (!vma_exec || !vma_fault)) {
47067 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47068 + vma_exec = vma;
47069 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47070 + vma_fault = vma;
47071 + vma = vma->vm_next;
47072 + }
47073 + if (vma_exec) {
47074 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47075 + if (IS_ERR(path_exec))
47076 + path_exec = "<path too long>";
47077 + else {
47078 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47079 + if (path_exec) {
47080 + *path_exec = 0;
47081 + path_exec = buffer_exec;
47082 + } else
47083 + path_exec = "<path too long>";
47084 + }
47085 + }
47086 + if (vma_fault) {
47087 + start = vma_fault->vm_start;
47088 + end = vma_fault->vm_end;
47089 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47090 + if (vma_fault->vm_file) {
47091 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47092 + if (IS_ERR(path_fault))
47093 + path_fault = "<path too long>";
47094 + else {
47095 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47096 + if (path_fault) {
47097 + *path_fault = 0;
47098 + path_fault = buffer_fault;
47099 + } else
47100 + path_fault = "<path too long>";
47101 + }
47102 + } else
47103 + path_fault = "<anonymous mapping>";
47104 + }
47105 + up_read(&mm->mmap_sem);
47106 + }
47107 + if (tsk->signal->curr_ip)
47108 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47109 + else
47110 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47111 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
47112 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
47113 + free_page((unsigned long)buffer_exec);
47114 + free_page((unsigned long)buffer_fault);
47115 + pax_report_insns(regs, pc, sp);
47116 + info.si_signo = SIGKILL;
47117 + info.si_errno = 0;
47118 + info.si_code = SI_KERNEL;
47119 + info.si_pid = 0;
47120 + info.si_uid = 0;
47121 + do_coredump(&info, regs);
47122 +}
47123 +#endif
47124 +
47125 +#ifdef CONFIG_PAX_REFCOUNT
47126 +void pax_report_refcount_overflow(struct pt_regs *regs)
47127 +{
47128 + if (current->signal->curr_ip)
47129 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47130 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
47131 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47132 + else
47133 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
47134 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47135 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47136 + show_regs(regs);
47137 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47138 +}
47139 +#endif
47140 +
47141 +#ifdef CONFIG_PAX_USERCOPY
47142 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47143 +static noinline int check_stack_object(const void *obj, unsigned long len)
47144 +{
47145 + const void * const stack = task_stack_page(current);
47146 + const void * const stackend = stack + THREAD_SIZE;
47147 +
47148 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47149 + const void *frame = NULL;
47150 + const void *oldframe;
47151 +#endif
47152 +
47153 + if (obj + len < obj)
47154 + return -1;
47155 +
47156 + if (obj + len <= stack || stackend <= obj)
47157 + return 0;
47158 +
47159 + if (obj < stack || stackend < obj + len)
47160 + return -1;
47161 +
47162 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47163 + oldframe = __builtin_frame_address(1);
47164 + if (oldframe)
47165 + frame = __builtin_frame_address(2);
47166 + /*
47167 + low ----------------------------------------------> high
47168 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
47169 + ^----------------^
47170 + allow copies only within here
47171 + */
47172 + while (stack <= frame && frame < stackend) {
47173 + /* if obj + len extends past the last frame, this
47174 + check won't pass and the next frame will be 0,
47175 + causing us to bail out and correctly report
47176 + the copy as invalid
47177 + */
47178 + if (obj + len <= frame)
47179 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47180 + oldframe = frame;
47181 + frame = *(const void * const *)frame;
47182 + }
47183 + return -1;
47184 +#else
47185 + return 1;
47186 +#endif
47187 +}
47188 +
47189 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47190 +{
47191 + if (current->signal->curr_ip)
47192 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47193 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47194 + else
47195 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47196 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47197 + dump_stack();
47198 + gr_handle_kernel_exploit();
47199 + do_group_exit(SIGKILL);
47200 +}
47201 +#endif
47202 +
47203 +void __check_object_size(const void *ptr, unsigned long n, bool to)
47204 +{
47205 +
47206 +#ifdef CONFIG_PAX_USERCOPY
47207 + const char *type;
47208 +
47209 + if (!n)
47210 + return;
47211 +
47212 + type = check_heap_object(ptr, n);
47213 + if (!type) {
47214 + if (check_stack_object(ptr, n) != -1)
47215 + return;
47216 + type = "<process stack>";
47217 + }
47218 +
47219 + pax_report_usercopy(ptr, n, to, type);
47220 +#endif
47221 +
47222 +}
47223 +EXPORT_SYMBOL(__check_object_size);
47224 +
47225 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47226 +void pax_track_stack(void)
47227 +{
47228 + unsigned long sp = (unsigned long)&sp;
47229 + if (sp < current_thread_info()->lowest_stack &&
47230 + sp > (unsigned long)task_stack_page(current))
47231 + current_thread_info()->lowest_stack = sp;
47232 +}
47233 +EXPORT_SYMBOL(pax_track_stack);
47234 +#endif
47235 +
47236 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
47237 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47238 +{
47239 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47240 + dump_stack();
47241 + do_group_exit(SIGKILL);
47242 +}
47243 +EXPORT_SYMBOL(report_size_overflow);
47244 +#endif
47245 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47246 index 2616d0e..2ffdec9 100644
47247 --- a/fs/ext2/balloc.c
47248 +++ b/fs/ext2/balloc.c
47249 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47250
47251 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47252 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47253 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47254 + if (free_blocks < root_blocks + 1 &&
47255 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47256 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47257 - !in_group_p (sbi->s_resgid))) {
47258 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47259 return 0;
47260 }
47261 return 1;
47262 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47263 index 22548f5..41521d8 100644
47264 --- a/fs/ext3/balloc.c
47265 +++ b/fs/ext3/balloc.c
47266 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47267
47268 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47269 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47270 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47271 + if (free_blocks < root_blocks + 1 &&
47272 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47273 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47274 - !in_group_p (sbi->s_resgid))) {
47275 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47276 return 0;
47277 }
47278 return 1;
47279 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47280 index cf18217..8f6b9c3 100644
47281 --- a/fs/ext4/balloc.c
47282 +++ b/fs/ext4/balloc.c
47283 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47284 /* Hm, nope. Are (enough) root reserved clusters available? */
47285 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47286 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47287 - capable(CAP_SYS_RESOURCE) ||
47288 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47289 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47290 + capable_nolog(CAP_SYS_RESOURCE)) {
47291
47292 if (free_clusters >= (nclusters + dirty_clusters))
47293 return 1;
47294 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47295 index 3c20de1..6ff2460 100644
47296 --- a/fs/ext4/ext4.h
47297 +++ b/fs/ext4/ext4.h
47298 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47299 unsigned long s_mb_last_start;
47300
47301 /* stats for buddy allocator */
47302 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47303 - atomic_t s_bal_success; /* we found long enough chunks */
47304 - atomic_t s_bal_allocated; /* in blocks */
47305 - atomic_t s_bal_ex_scanned; /* total extents scanned */
47306 - atomic_t s_bal_goals; /* goal hits */
47307 - atomic_t s_bal_breaks; /* too long searches */
47308 - atomic_t s_bal_2orders; /* 2^order hits */
47309 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47310 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47311 + atomic_unchecked_t s_bal_allocated; /* in blocks */
47312 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47313 + atomic_unchecked_t s_bal_goals; /* goal hits */
47314 + atomic_unchecked_t s_bal_breaks; /* too long searches */
47315 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47316 spinlock_t s_bal_lock;
47317 unsigned long s_mb_buddies_generated;
47318 unsigned long long s_mb_generation_time;
47319 - atomic_t s_mb_lost_chunks;
47320 - atomic_t s_mb_preallocated;
47321 - atomic_t s_mb_discarded;
47322 + atomic_unchecked_t s_mb_lost_chunks;
47323 + atomic_unchecked_t s_mb_preallocated;
47324 + atomic_unchecked_t s_mb_discarded;
47325 atomic_t s_lock_busy;
47326
47327 /* locality groups */
47328 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47329 index 526e553..3f2de85 100644
47330 --- a/fs/ext4/mballoc.c
47331 +++ b/fs/ext4/mballoc.c
47332 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47333 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47334
47335 if (EXT4_SB(sb)->s_mb_stats)
47336 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47337 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47338
47339 break;
47340 }
47341 @@ -2044,7 +2044,7 @@ repeat:
47342 ac->ac_status = AC_STATUS_CONTINUE;
47343 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47344 cr = 3;
47345 - atomic_inc(&sbi->s_mb_lost_chunks);
47346 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47347 goto repeat;
47348 }
47349 }
47350 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47351 if (sbi->s_mb_stats) {
47352 ext4_msg(sb, KERN_INFO,
47353 "mballoc: %u blocks %u reqs (%u success)",
47354 - atomic_read(&sbi->s_bal_allocated),
47355 - atomic_read(&sbi->s_bal_reqs),
47356 - atomic_read(&sbi->s_bal_success));
47357 + atomic_read_unchecked(&sbi->s_bal_allocated),
47358 + atomic_read_unchecked(&sbi->s_bal_reqs),
47359 + atomic_read_unchecked(&sbi->s_bal_success));
47360 ext4_msg(sb, KERN_INFO,
47361 "mballoc: %u extents scanned, %u goal hits, "
47362 "%u 2^N hits, %u breaks, %u lost",
47363 - atomic_read(&sbi->s_bal_ex_scanned),
47364 - atomic_read(&sbi->s_bal_goals),
47365 - atomic_read(&sbi->s_bal_2orders),
47366 - atomic_read(&sbi->s_bal_breaks),
47367 - atomic_read(&sbi->s_mb_lost_chunks));
47368 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47369 + atomic_read_unchecked(&sbi->s_bal_goals),
47370 + atomic_read_unchecked(&sbi->s_bal_2orders),
47371 + atomic_read_unchecked(&sbi->s_bal_breaks),
47372 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47373 ext4_msg(sb, KERN_INFO,
47374 "mballoc: %lu generated and it took %Lu",
47375 sbi->s_mb_buddies_generated,
47376 sbi->s_mb_generation_time);
47377 ext4_msg(sb, KERN_INFO,
47378 "mballoc: %u preallocated, %u discarded",
47379 - atomic_read(&sbi->s_mb_preallocated),
47380 - atomic_read(&sbi->s_mb_discarded));
47381 + atomic_read_unchecked(&sbi->s_mb_preallocated),
47382 + atomic_read_unchecked(&sbi->s_mb_discarded));
47383 }
47384
47385 free_percpu(sbi->s_locality_groups);
47386 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47387 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47388
47389 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47390 - atomic_inc(&sbi->s_bal_reqs);
47391 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47392 + atomic_inc_unchecked(&sbi->s_bal_reqs);
47393 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47394 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47395 - atomic_inc(&sbi->s_bal_success);
47396 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47397 + atomic_inc_unchecked(&sbi->s_bal_success);
47398 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47399 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47400 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47401 - atomic_inc(&sbi->s_bal_goals);
47402 + atomic_inc_unchecked(&sbi->s_bal_goals);
47403 if (ac->ac_found > sbi->s_mb_max_to_scan)
47404 - atomic_inc(&sbi->s_bal_breaks);
47405 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47406 }
47407
47408 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47409 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47410 trace_ext4_mb_new_inode_pa(ac, pa);
47411
47412 ext4_mb_use_inode_pa(ac, pa);
47413 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47414 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47415
47416 ei = EXT4_I(ac->ac_inode);
47417 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47418 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47419 trace_ext4_mb_new_group_pa(ac, pa);
47420
47421 ext4_mb_use_group_pa(ac, pa);
47422 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47423 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47424
47425 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47426 lg = ac->ac_lg;
47427 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47428 * from the bitmap and continue.
47429 */
47430 }
47431 - atomic_add(free, &sbi->s_mb_discarded);
47432 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47433
47434 return err;
47435 }
47436 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47437 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47438 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47439 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47440 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47441 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47442 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47443
47444 return 0;
47445 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47446 index d59b351..775f8c8 100644
47447 --- a/fs/ext4/super.c
47448 +++ b/fs/ext4/super.c
47449 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47450 ext4_fsblk_t overhead = 0;
47451 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47452
47453 - memset(buf, 0, PAGE_SIZE);
47454 if (!buf)
47455 return -ENOMEM;
47456
47457 diff --git a/fs/fcntl.c b/fs/fcntl.c
47458 index 71a600a..20d87b1 100644
47459 --- a/fs/fcntl.c
47460 +++ b/fs/fcntl.c
47461 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47462 if (err)
47463 return err;
47464
47465 + if (gr_handle_chroot_fowner(pid, type))
47466 + return -ENOENT;
47467 + if (gr_check_protected_task_fowner(pid, type))
47468 + return -EACCES;
47469 +
47470 f_modown(filp, pid, type, force);
47471 return 0;
47472 }
47473 diff --git a/fs/fhandle.c b/fs/fhandle.c
47474 index f775bfd..629bd4c 100644
47475 --- a/fs/fhandle.c
47476 +++ b/fs/fhandle.c
47477 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47478 } else
47479 retval = 0;
47480 /* copy the mount id */
47481 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47482 - sizeof(*mnt_id)) ||
47483 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47484 copy_to_user(ufh, handle,
47485 sizeof(struct file_handle) + handle_bytes))
47486 retval = -EFAULT;
47487 diff --git a/fs/fifo.c b/fs/fifo.c
47488 index cf6f434..3d7942c 100644
47489 --- a/fs/fifo.c
47490 +++ b/fs/fifo.c
47491 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47492 */
47493 filp->f_op = &read_pipefifo_fops;
47494 pipe->r_counter++;
47495 - if (pipe->readers++ == 0)
47496 + if (atomic_inc_return(&pipe->readers) == 1)
47497 wake_up_partner(inode);
47498
47499 - if (!pipe->writers) {
47500 + if (!atomic_read(&pipe->writers)) {
47501 if ((filp->f_flags & O_NONBLOCK)) {
47502 /* suppress POLLHUP until we have
47503 * seen a writer */
47504 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47505 * errno=ENXIO when there is no process reading the FIFO.
47506 */
47507 ret = -ENXIO;
47508 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47509 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47510 goto err;
47511
47512 filp->f_op = &write_pipefifo_fops;
47513 pipe->w_counter++;
47514 - if (!pipe->writers++)
47515 + if (atomic_inc_return(&pipe->writers) == 1)
47516 wake_up_partner(inode);
47517
47518 - if (!pipe->readers) {
47519 + if (!atomic_read(&pipe->readers)) {
47520 if (wait_for_partner(inode, &pipe->r_counter))
47521 goto err_wr;
47522 }
47523 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47524 */
47525 filp->f_op = &rdwr_pipefifo_fops;
47526
47527 - pipe->readers++;
47528 - pipe->writers++;
47529 + atomic_inc(&pipe->readers);
47530 + atomic_inc(&pipe->writers);
47531 pipe->r_counter++;
47532 pipe->w_counter++;
47533 - if (pipe->readers == 1 || pipe->writers == 1)
47534 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47535 wake_up_partner(inode);
47536 break;
47537
47538 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47539 return 0;
47540
47541 err_rd:
47542 - if (!--pipe->readers)
47543 + if (atomic_dec_and_test(&pipe->readers))
47544 wake_up_interruptible(&pipe->wait);
47545 ret = -ERESTARTSYS;
47546 goto err;
47547
47548 err_wr:
47549 - if (!--pipe->writers)
47550 + if (atomic_dec_and_test(&pipe->writers))
47551 wake_up_interruptible(&pipe->wait);
47552 ret = -ERESTARTSYS;
47553 goto err;
47554
47555 err:
47556 - if (!pipe->readers && !pipe->writers)
47557 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47558 free_pipe_info(inode);
47559
47560 err_nocleanup:
47561 diff --git a/fs/file.c b/fs/file.c
47562 index eff2316..8c8930c 100644
47563 --- a/fs/file.c
47564 +++ b/fs/file.c
47565 @@ -16,6 +16,7 @@
47566 #include <linux/slab.h>
47567 #include <linux/vmalloc.h>
47568 #include <linux/file.h>
47569 +#include <linux/security.h>
47570 #include <linux/fdtable.h>
47571 #include <linux/bitops.h>
47572 #include <linux/interrupt.h>
47573 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47574 if (!file)
47575 return __close_fd(files, fd);
47576
47577 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47578 if (fd >= rlimit(RLIMIT_NOFILE))
47579 return -EBADF;
47580
47581 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47582 if (unlikely(oldfd == newfd))
47583 return -EINVAL;
47584
47585 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47586 if (newfd >= rlimit(RLIMIT_NOFILE))
47587 return -EBADF;
47588
47589 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47590 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47591 {
47592 int err;
47593 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47594 if (from >= rlimit(RLIMIT_NOFILE))
47595 return -EINVAL;
47596 err = alloc_fd(from, flags);
47597 diff --git a/fs/filesystems.c b/fs/filesystems.c
47598 index da165f6..3671bdb 100644
47599 --- a/fs/filesystems.c
47600 +++ b/fs/filesystems.c
47601 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47602 int len = dot ? dot - name : strlen(name);
47603
47604 fs = __get_fs_type(name, len);
47605 +
47606 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47607 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47608 +#else
47609 if (!fs && (request_module("%.*s", len, name) == 0))
47610 +#endif
47611 fs = __get_fs_type(name, len);
47612
47613 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47614 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47615 index 5df4775..9d9336f 100644
47616 --- a/fs/fs_struct.c
47617 +++ b/fs/fs_struct.c
47618 @@ -4,6 +4,7 @@
47619 #include <linux/path.h>
47620 #include <linux/slab.h>
47621 #include <linux/fs_struct.h>
47622 +#include <linux/grsecurity.h>
47623 #include "internal.h"
47624
47625 /*
47626 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47627 write_seqcount_begin(&fs->seq);
47628 old_root = fs->root;
47629 fs->root = *path;
47630 + gr_set_chroot_entries(current, path);
47631 write_seqcount_end(&fs->seq);
47632 spin_unlock(&fs->lock);
47633 if (old_root.dentry)
47634 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47635 return 1;
47636 }
47637
47638 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47639 +{
47640 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47641 + return 0;
47642 + *p = *new;
47643 +
47644 + /* This function is only called from pivot_root(). Leave our
47645 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47646 + pivoted root isn't treated as a chroot
47647 + */
47648 + //gr_set_chroot_entries(task, new);
47649 +
47650 + return 1;
47651 +}
47652 +
47653 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47654 {
47655 struct task_struct *g, *p;
47656 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47657 int hits = 0;
47658 spin_lock(&fs->lock);
47659 write_seqcount_begin(&fs->seq);
47660 - hits += replace_path(&fs->root, old_root, new_root);
47661 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47662 hits += replace_path(&fs->pwd, old_root, new_root);
47663 write_seqcount_end(&fs->seq);
47664 while (hits--) {
47665 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47666 task_lock(tsk);
47667 spin_lock(&fs->lock);
47668 tsk->fs = NULL;
47669 - kill = !--fs->users;
47670 + gr_clear_chroot_entries(tsk);
47671 + kill = !atomic_dec_return(&fs->users);
47672 spin_unlock(&fs->lock);
47673 task_unlock(tsk);
47674 if (kill)
47675 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47676 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47677 /* We don't need to lock fs - think why ;-) */
47678 if (fs) {
47679 - fs->users = 1;
47680 + atomic_set(&fs->users, 1);
47681 fs->in_exec = 0;
47682 spin_lock_init(&fs->lock);
47683 seqcount_init(&fs->seq);
47684 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47685 spin_lock(&old->lock);
47686 fs->root = old->root;
47687 path_get(&fs->root);
47688 + /* instead of calling gr_set_chroot_entries here,
47689 + we call it from every caller of this function
47690 + */
47691 fs->pwd = old->pwd;
47692 path_get(&fs->pwd);
47693 spin_unlock(&old->lock);
47694 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47695
47696 task_lock(current);
47697 spin_lock(&fs->lock);
47698 - kill = !--fs->users;
47699 + kill = !atomic_dec_return(&fs->users);
47700 current->fs = new_fs;
47701 + gr_set_chroot_entries(current, &new_fs->root);
47702 spin_unlock(&fs->lock);
47703 task_unlock(current);
47704
47705 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47706
47707 int current_umask(void)
47708 {
47709 - return current->fs->umask;
47710 + return current->fs->umask | gr_acl_umask();
47711 }
47712 EXPORT_SYMBOL(current_umask);
47713
47714 /* to be mentioned only in INIT_TASK */
47715 struct fs_struct init_fs = {
47716 - .users = 1,
47717 + .users = ATOMIC_INIT(1),
47718 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47719 .seq = SEQCNT_ZERO,
47720 .umask = 0022,
47721 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47722 task_lock(current);
47723
47724 spin_lock(&init_fs.lock);
47725 - init_fs.users++;
47726 + atomic_inc(&init_fs.users);
47727 spin_unlock(&init_fs.lock);
47728
47729 spin_lock(&fs->lock);
47730 current->fs = &init_fs;
47731 - kill = !--fs->users;
47732 + gr_set_chroot_entries(current, &current->fs->root);
47733 + kill = !atomic_dec_return(&fs->users);
47734 spin_unlock(&fs->lock);
47735
47736 task_unlock(current);
47737 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47738 index 9905350..02eaec4 100644
47739 --- a/fs/fscache/cookie.c
47740 +++ b/fs/fscache/cookie.c
47741 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47742 parent ? (char *) parent->def->name : "<no-parent>",
47743 def->name, netfs_data);
47744
47745 - fscache_stat(&fscache_n_acquires);
47746 + fscache_stat_unchecked(&fscache_n_acquires);
47747
47748 /* if there's no parent cookie, then we don't create one here either */
47749 if (!parent) {
47750 - fscache_stat(&fscache_n_acquires_null);
47751 + fscache_stat_unchecked(&fscache_n_acquires_null);
47752 _leave(" [no parent]");
47753 return NULL;
47754 }
47755 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47756 /* allocate and initialise a cookie */
47757 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47758 if (!cookie) {
47759 - fscache_stat(&fscache_n_acquires_oom);
47760 + fscache_stat_unchecked(&fscache_n_acquires_oom);
47761 _leave(" [ENOMEM]");
47762 return NULL;
47763 }
47764 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47765
47766 switch (cookie->def->type) {
47767 case FSCACHE_COOKIE_TYPE_INDEX:
47768 - fscache_stat(&fscache_n_cookie_index);
47769 + fscache_stat_unchecked(&fscache_n_cookie_index);
47770 break;
47771 case FSCACHE_COOKIE_TYPE_DATAFILE:
47772 - fscache_stat(&fscache_n_cookie_data);
47773 + fscache_stat_unchecked(&fscache_n_cookie_data);
47774 break;
47775 default:
47776 - fscache_stat(&fscache_n_cookie_special);
47777 + fscache_stat_unchecked(&fscache_n_cookie_special);
47778 break;
47779 }
47780
47781 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47782 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47783 atomic_dec(&parent->n_children);
47784 __fscache_cookie_put(cookie);
47785 - fscache_stat(&fscache_n_acquires_nobufs);
47786 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47787 _leave(" = NULL");
47788 return NULL;
47789 }
47790 }
47791
47792 - fscache_stat(&fscache_n_acquires_ok);
47793 + fscache_stat_unchecked(&fscache_n_acquires_ok);
47794 _leave(" = %p", cookie);
47795 return cookie;
47796 }
47797 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47798 cache = fscache_select_cache_for_object(cookie->parent);
47799 if (!cache) {
47800 up_read(&fscache_addremove_sem);
47801 - fscache_stat(&fscache_n_acquires_no_cache);
47802 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47803 _leave(" = -ENOMEDIUM [no cache]");
47804 return -ENOMEDIUM;
47805 }
47806 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47807 object = cache->ops->alloc_object(cache, cookie);
47808 fscache_stat_d(&fscache_n_cop_alloc_object);
47809 if (IS_ERR(object)) {
47810 - fscache_stat(&fscache_n_object_no_alloc);
47811 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
47812 ret = PTR_ERR(object);
47813 goto error;
47814 }
47815
47816 - fscache_stat(&fscache_n_object_alloc);
47817 + fscache_stat_unchecked(&fscache_n_object_alloc);
47818
47819 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47820
47821 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47822 struct fscache_object *object;
47823 struct hlist_node *_p;
47824
47825 - fscache_stat(&fscache_n_updates);
47826 + fscache_stat_unchecked(&fscache_n_updates);
47827
47828 if (!cookie) {
47829 - fscache_stat(&fscache_n_updates_null);
47830 + fscache_stat_unchecked(&fscache_n_updates_null);
47831 _leave(" [no cookie]");
47832 return;
47833 }
47834 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47835 struct fscache_object *object;
47836 unsigned long event;
47837
47838 - fscache_stat(&fscache_n_relinquishes);
47839 + fscache_stat_unchecked(&fscache_n_relinquishes);
47840 if (retire)
47841 - fscache_stat(&fscache_n_relinquishes_retire);
47842 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
47843
47844 if (!cookie) {
47845 - fscache_stat(&fscache_n_relinquishes_null);
47846 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
47847 _leave(" [no cookie]");
47848 return;
47849 }
47850 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47851
47852 /* wait for the cookie to finish being instantiated (or to fail) */
47853 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
47854 - fscache_stat(&fscache_n_relinquishes_waitcrt);
47855 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
47856 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
47857 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
47858 }
47859 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
47860 index f6aad48..88dcf26 100644
47861 --- a/fs/fscache/internal.h
47862 +++ b/fs/fscache/internal.h
47863 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
47864 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
47865 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
47866
47867 -extern atomic_t fscache_n_op_pend;
47868 -extern atomic_t fscache_n_op_run;
47869 -extern atomic_t fscache_n_op_enqueue;
47870 -extern atomic_t fscache_n_op_deferred_release;
47871 -extern atomic_t fscache_n_op_release;
47872 -extern atomic_t fscache_n_op_gc;
47873 -extern atomic_t fscache_n_op_cancelled;
47874 -extern atomic_t fscache_n_op_rejected;
47875 +extern atomic_unchecked_t fscache_n_op_pend;
47876 +extern atomic_unchecked_t fscache_n_op_run;
47877 +extern atomic_unchecked_t fscache_n_op_enqueue;
47878 +extern atomic_unchecked_t fscache_n_op_deferred_release;
47879 +extern atomic_unchecked_t fscache_n_op_release;
47880 +extern atomic_unchecked_t fscache_n_op_gc;
47881 +extern atomic_unchecked_t fscache_n_op_cancelled;
47882 +extern atomic_unchecked_t fscache_n_op_rejected;
47883
47884 -extern atomic_t fscache_n_attr_changed;
47885 -extern atomic_t fscache_n_attr_changed_ok;
47886 -extern atomic_t fscache_n_attr_changed_nobufs;
47887 -extern atomic_t fscache_n_attr_changed_nomem;
47888 -extern atomic_t fscache_n_attr_changed_calls;
47889 +extern atomic_unchecked_t fscache_n_attr_changed;
47890 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
47891 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
47892 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
47893 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
47894
47895 -extern atomic_t fscache_n_allocs;
47896 -extern atomic_t fscache_n_allocs_ok;
47897 -extern atomic_t fscache_n_allocs_wait;
47898 -extern atomic_t fscache_n_allocs_nobufs;
47899 -extern atomic_t fscache_n_allocs_intr;
47900 -extern atomic_t fscache_n_allocs_object_dead;
47901 -extern atomic_t fscache_n_alloc_ops;
47902 -extern atomic_t fscache_n_alloc_op_waits;
47903 +extern atomic_unchecked_t fscache_n_allocs;
47904 +extern atomic_unchecked_t fscache_n_allocs_ok;
47905 +extern atomic_unchecked_t fscache_n_allocs_wait;
47906 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
47907 +extern atomic_unchecked_t fscache_n_allocs_intr;
47908 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
47909 +extern atomic_unchecked_t fscache_n_alloc_ops;
47910 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
47911
47912 -extern atomic_t fscache_n_retrievals;
47913 -extern atomic_t fscache_n_retrievals_ok;
47914 -extern atomic_t fscache_n_retrievals_wait;
47915 -extern atomic_t fscache_n_retrievals_nodata;
47916 -extern atomic_t fscache_n_retrievals_nobufs;
47917 -extern atomic_t fscache_n_retrievals_intr;
47918 -extern atomic_t fscache_n_retrievals_nomem;
47919 -extern atomic_t fscache_n_retrievals_object_dead;
47920 -extern atomic_t fscache_n_retrieval_ops;
47921 -extern atomic_t fscache_n_retrieval_op_waits;
47922 +extern atomic_unchecked_t fscache_n_retrievals;
47923 +extern atomic_unchecked_t fscache_n_retrievals_ok;
47924 +extern atomic_unchecked_t fscache_n_retrievals_wait;
47925 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
47926 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
47927 +extern atomic_unchecked_t fscache_n_retrievals_intr;
47928 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
47929 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
47930 +extern atomic_unchecked_t fscache_n_retrieval_ops;
47931 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
47932
47933 -extern atomic_t fscache_n_stores;
47934 -extern atomic_t fscache_n_stores_ok;
47935 -extern atomic_t fscache_n_stores_again;
47936 -extern atomic_t fscache_n_stores_nobufs;
47937 -extern atomic_t fscache_n_stores_oom;
47938 -extern atomic_t fscache_n_store_ops;
47939 -extern atomic_t fscache_n_store_calls;
47940 -extern atomic_t fscache_n_store_pages;
47941 -extern atomic_t fscache_n_store_radix_deletes;
47942 -extern atomic_t fscache_n_store_pages_over_limit;
47943 +extern atomic_unchecked_t fscache_n_stores;
47944 +extern atomic_unchecked_t fscache_n_stores_ok;
47945 +extern atomic_unchecked_t fscache_n_stores_again;
47946 +extern atomic_unchecked_t fscache_n_stores_nobufs;
47947 +extern atomic_unchecked_t fscache_n_stores_oom;
47948 +extern atomic_unchecked_t fscache_n_store_ops;
47949 +extern atomic_unchecked_t fscache_n_store_calls;
47950 +extern atomic_unchecked_t fscache_n_store_pages;
47951 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
47952 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
47953
47954 -extern atomic_t fscache_n_store_vmscan_not_storing;
47955 -extern atomic_t fscache_n_store_vmscan_gone;
47956 -extern atomic_t fscache_n_store_vmscan_busy;
47957 -extern atomic_t fscache_n_store_vmscan_cancelled;
47958 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47959 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
47960 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
47961 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47962
47963 -extern atomic_t fscache_n_marks;
47964 -extern atomic_t fscache_n_uncaches;
47965 +extern atomic_unchecked_t fscache_n_marks;
47966 +extern atomic_unchecked_t fscache_n_uncaches;
47967
47968 -extern atomic_t fscache_n_acquires;
47969 -extern atomic_t fscache_n_acquires_null;
47970 -extern atomic_t fscache_n_acquires_no_cache;
47971 -extern atomic_t fscache_n_acquires_ok;
47972 -extern atomic_t fscache_n_acquires_nobufs;
47973 -extern atomic_t fscache_n_acquires_oom;
47974 +extern atomic_unchecked_t fscache_n_acquires;
47975 +extern atomic_unchecked_t fscache_n_acquires_null;
47976 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
47977 +extern atomic_unchecked_t fscache_n_acquires_ok;
47978 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
47979 +extern atomic_unchecked_t fscache_n_acquires_oom;
47980
47981 -extern atomic_t fscache_n_updates;
47982 -extern atomic_t fscache_n_updates_null;
47983 -extern atomic_t fscache_n_updates_run;
47984 +extern atomic_unchecked_t fscache_n_updates;
47985 +extern atomic_unchecked_t fscache_n_updates_null;
47986 +extern atomic_unchecked_t fscache_n_updates_run;
47987
47988 -extern atomic_t fscache_n_relinquishes;
47989 -extern atomic_t fscache_n_relinquishes_null;
47990 -extern atomic_t fscache_n_relinquishes_waitcrt;
47991 -extern atomic_t fscache_n_relinquishes_retire;
47992 +extern atomic_unchecked_t fscache_n_relinquishes;
47993 +extern atomic_unchecked_t fscache_n_relinquishes_null;
47994 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47995 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
47996
47997 -extern atomic_t fscache_n_cookie_index;
47998 -extern atomic_t fscache_n_cookie_data;
47999 -extern atomic_t fscache_n_cookie_special;
48000 +extern atomic_unchecked_t fscache_n_cookie_index;
48001 +extern atomic_unchecked_t fscache_n_cookie_data;
48002 +extern atomic_unchecked_t fscache_n_cookie_special;
48003
48004 -extern atomic_t fscache_n_object_alloc;
48005 -extern atomic_t fscache_n_object_no_alloc;
48006 -extern atomic_t fscache_n_object_lookups;
48007 -extern atomic_t fscache_n_object_lookups_negative;
48008 -extern atomic_t fscache_n_object_lookups_positive;
48009 -extern atomic_t fscache_n_object_lookups_timed_out;
48010 -extern atomic_t fscache_n_object_created;
48011 -extern atomic_t fscache_n_object_avail;
48012 -extern atomic_t fscache_n_object_dead;
48013 +extern atomic_unchecked_t fscache_n_object_alloc;
48014 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48015 +extern atomic_unchecked_t fscache_n_object_lookups;
48016 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48017 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48018 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48019 +extern atomic_unchecked_t fscache_n_object_created;
48020 +extern atomic_unchecked_t fscache_n_object_avail;
48021 +extern atomic_unchecked_t fscache_n_object_dead;
48022
48023 -extern atomic_t fscache_n_checkaux_none;
48024 -extern atomic_t fscache_n_checkaux_okay;
48025 -extern atomic_t fscache_n_checkaux_update;
48026 -extern atomic_t fscache_n_checkaux_obsolete;
48027 +extern atomic_unchecked_t fscache_n_checkaux_none;
48028 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48029 +extern atomic_unchecked_t fscache_n_checkaux_update;
48030 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48031
48032 extern atomic_t fscache_n_cop_alloc_object;
48033 extern atomic_t fscache_n_cop_lookup_object;
48034 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
48035 atomic_inc(stat);
48036 }
48037
48038 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48039 +{
48040 + atomic_inc_unchecked(stat);
48041 +}
48042 +
48043 static inline void fscache_stat_d(atomic_t *stat)
48044 {
48045 atomic_dec(stat);
48046 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
48047
48048 #define __fscache_stat(stat) (NULL)
48049 #define fscache_stat(stat) do {} while (0)
48050 +#define fscache_stat_unchecked(stat) do {} while (0)
48051 #define fscache_stat_d(stat) do {} while (0)
48052 #endif
48053
48054 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48055 index b6b897c..0ffff9c 100644
48056 --- a/fs/fscache/object.c
48057 +++ b/fs/fscache/object.c
48058 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48059 /* update the object metadata on disk */
48060 case FSCACHE_OBJECT_UPDATING:
48061 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48062 - fscache_stat(&fscache_n_updates_run);
48063 + fscache_stat_unchecked(&fscache_n_updates_run);
48064 fscache_stat(&fscache_n_cop_update_object);
48065 object->cache->ops->update_object(object);
48066 fscache_stat_d(&fscache_n_cop_update_object);
48067 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48068 spin_lock(&object->lock);
48069 object->state = FSCACHE_OBJECT_DEAD;
48070 spin_unlock(&object->lock);
48071 - fscache_stat(&fscache_n_object_dead);
48072 + fscache_stat_unchecked(&fscache_n_object_dead);
48073 goto terminal_transit;
48074
48075 /* handle the parent cache of this object being withdrawn from
48076 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48077 spin_lock(&object->lock);
48078 object->state = FSCACHE_OBJECT_DEAD;
48079 spin_unlock(&object->lock);
48080 - fscache_stat(&fscache_n_object_dead);
48081 + fscache_stat_unchecked(&fscache_n_object_dead);
48082 goto terminal_transit;
48083
48084 /* complain about the object being woken up once it is
48085 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48086 parent->cookie->def->name, cookie->def->name,
48087 object->cache->tag->name);
48088
48089 - fscache_stat(&fscache_n_object_lookups);
48090 + fscache_stat_unchecked(&fscache_n_object_lookups);
48091 fscache_stat(&fscache_n_cop_lookup_object);
48092 ret = object->cache->ops->lookup_object(object);
48093 fscache_stat_d(&fscache_n_cop_lookup_object);
48094 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48095 if (ret == -ETIMEDOUT) {
48096 /* probably stuck behind another object, so move this one to
48097 * the back of the queue */
48098 - fscache_stat(&fscache_n_object_lookups_timed_out);
48099 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48100 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48101 }
48102
48103 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48104
48105 spin_lock(&object->lock);
48106 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48107 - fscache_stat(&fscache_n_object_lookups_negative);
48108 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48109
48110 /* transit here to allow write requests to begin stacking up
48111 * and read requests to begin returning ENODATA */
48112 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48113 * result, in which case there may be data available */
48114 spin_lock(&object->lock);
48115 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48116 - fscache_stat(&fscache_n_object_lookups_positive);
48117 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48118
48119 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48120
48121 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48122 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48123 } else {
48124 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48125 - fscache_stat(&fscache_n_object_created);
48126 + fscache_stat_unchecked(&fscache_n_object_created);
48127
48128 object->state = FSCACHE_OBJECT_AVAILABLE;
48129 spin_unlock(&object->lock);
48130 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48131 fscache_enqueue_dependents(object);
48132
48133 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48134 - fscache_stat(&fscache_n_object_avail);
48135 + fscache_stat_unchecked(&fscache_n_object_avail);
48136
48137 _leave("");
48138 }
48139 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48140 enum fscache_checkaux result;
48141
48142 if (!object->cookie->def->check_aux) {
48143 - fscache_stat(&fscache_n_checkaux_none);
48144 + fscache_stat_unchecked(&fscache_n_checkaux_none);
48145 return FSCACHE_CHECKAUX_OKAY;
48146 }
48147
48148 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48149 switch (result) {
48150 /* entry okay as is */
48151 case FSCACHE_CHECKAUX_OKAY:
48152 - fscache_stat(&fscache_n_checkaux_okay);
48153 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
48154 break;
48155
48156 /* entry requires update */
48157 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48158 - fscache_stat(&fscache_n_checkaux_update);
48159 + fscache_stat_unchecked(&fscache_n_checkaux_update);
48160 break;
48161
48162 /* entry requires deletion */
48163 case FSCACHE_CHECKAUX_OBSOLETE:
48164 - fscache_stat(&fscache_n_checkaux_obsolete);
48165 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48166 break;
48167
48168 default:
48169 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48170 index 30afdfa..2256596 100644
48171 --- a/fs/fscache/operation.c
48172 +++ b/fs/fscache/operation.c
48173 @@ -17,7 +17,7 @@
48174 #include <linux/slab.h>
48175 #include "internal.h"
48176
48177 -atomic_t fscache_op_debug_id;
48178 +atomic_unchecked_t fscache_op_debug_id;
48179 EXPORT_SYMBOL(fscache_op_debug_id);
48180
48181 /**
48182 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48183 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48184 ASSERTCMP(atomic_read(&op->usage), >, 0);
48185
48186 - fscache_stat(&fscache_n_op_enqueue);
48187 + fscache_stat_unchecked(&fscache_n_op_enqueue);
48188 switch (op->flags & FSCACHE_OP_TYPE) {
48189 case FSCACHE_OP_ASYNC:
48190 _debug("queue async");
48191 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48192 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48193 if (op->processor)
48194 fscache_enqueue_operation(op);
48195 - fscache_stat(&fscache_n_op_run);
48196 + fscache_stat_unchecked(&fscache_n_op_run);
48197 }
48198
48199 /*
48200 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48201 if (object->n_ops > 1) {
48202 atomic_inc(&op->usage);
48203 list_add_tail(&op->pend_link, &object->pending_ops);
48204 - fscache_stat(&fscache_n_op_pend);
48205 + fscache_stat_unchecked(&fscache_n_op_pend);
48206 } else if (!list_empty(&object->pending_ops)) {
48207 atomic_inc(&op->usage);
48208 list_add_tail(&op->pend_link, &object->pending_ops);
48209 - fscache_stat(&fscache_n_op_pend);
48210 + fscache_stat_unchecked(&fscache_n_op_pend);
48211 fscache_start_operations(object);
48212 } else {
48213 ASSERTCMP(object->n_in_progress, ==, 0);
48214 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48215 object->n_exclusive++; /* reads and writes must wait */
48216 atomic_inc(&op->usage);
48217 list_add_tail(&op->pend_link, &object->pending_ops);
48218 - fscache_stat(&fscache_n_op_pend);
48219 + fscache_stat_unchecked(&fscache_n_op_pend);
48220 ret = 0;
48221 } else {
48222 /* not allowed to submit ops in any other state */
48223 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48224 if (object->n_exclusive > 0) {
48225 atomic_inc(&op->usage);
48226 list_add_tail(&op->pend_link, &object->pending_ops);
48227 - fscache_stat(&fscache_n_op_pend);
48228 + fscache_stat_unchecked(&fscache_n_op_pend);
48229 } else if (!list_empty(&object->pending_ops)) {
48230 atomic_inc(&op->usage);
48231 list_add_tail(&op->pend_link, &object->pending_ops);
48232 - fscache_stat(&fscache_n_op_pend);
48233 + fscache_stat_unchecked(&fscache_n_op_pend);
48234 fscache_start_operations(object);
48235 } else {
48236 ASSERTCMP(object->n_exclusive, ==, 0);
48237 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48238 object->n_ops++;
48239 atomic_inc(&op->usage);
48240 list_add_tail(&op->pend_link, &object->pending_ops);
48241 - fscache_stat(&fscache_n_op_pend);
48242 + fscache_stat_unchecked(&fscache_n_op_pend);
48243 ret = 0;
48244 } else if (object->state == FSCACHE_OBJECT_DYING ||
48245 object->state == FSCACHE_OBJECT_LC_DYING ||
48246 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48247 - fscache_stat(&fscache_n_op_rejected);
48248 + fscache_stat_unchecked(&fscache_n_op_rejected);
48249 ret = -ENOBUFS;
48250 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48251 fscache_report_unexpected_submission(object, op, ostate);
48252 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48253
48254 ret = -EBUSY;
48255 if (!list_empty(&op->pend_link)) {
48256 - fscache_stat(&fscache_n_op_cancelled);
48257 + fscache_stat_unchecked(&fscache_n_op_cancelled);
48258 list_del_init(&op->pend_link);
48259 object->n_ops--;
48260 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48261 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48262 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48263 BUG();
48264
48265 - fscache_stat(&fscache_n_op_release);
48266 + fscache_stat_unchecked(&fscache_n_op_release);
48267
48268 if (op->release) {
48269 op->release(op);
48270 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48271 * lock, and defer it otherwise */
48272 if (!spin_trylock(&object->lock)) {
48273 _debug("defer put");
48274 - fscache_stat(&fscache_n_op_deferred_release);
48275 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
48276
48277 cache = object->cache;
48278 spin_lock(&cache->op_gc_list_lock);
48279 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48280
48281 _debug("GC DEFERRED REL OBJ%x OP%x",
48282 object->debug_id, op->debug_id);
48283 - fscache_stat(&fscache_n_op_gc);
48284 + fscache_stat_unchecked(&fscache_n_op_gc);
48285
48286 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48287
48288 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48289 index 3f7a59b..cf196cc 100644
48290 --- a/fs/fscache/page.c
48291 +++ b/fs/fscache/page.c
48292 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48293 val = radix_tree_lookup(&cookie->stores, page->index);
48294 if (!val) {
48295 rcu_read_unlock();
48296 - fscache_stat(&fscache_n_store_vmscan_not_storing);
48297 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48298 __fscache_uncache_page(cookie, page);
48299 return true;
48300 }
48301 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48302 spin_unlock(&cookie->stores_lock);
48303
48304 if (xpage) {
48305 - fscache_stat(&fscache_n_store_vmscan_cancelled);
48306 - fscache_stat(&fscache_n_store_radix_deletes);
48307 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48308 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48309 ASSERTCMP(xpage, ==, page);
48310 } else {
48311 - fscache_stat(&fscache_n_store_vmscan_gone);
48312 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48313 }
48314
48315 wake_up_bit(&cookie->flags, 0);
48316 @@ -107,7 +107,7 @@ page_busy:
48317 /* we might want to wait here, but that could deadlock the allocator as
48318 * the work threads writing to the cache may all end up sleeping
48319 * on memory allocation */
48320 - fscache_stat(&fscache_n_store_vmscan_busy);
48321 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48322 return false;
48323 }
48324 EXPORT_SYMBOL(__fscache_maybe_release_page);
48325 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48326 FSCACHE_COOKIE_STORING_TAG);
48327 if (!radix_tree_tag_get(&cookie->stores, page->index,
48328 FSCACHE_COOKIE_PENDING_TAG)) {
48329 - fscache_stat(&fscache_n_store_radix_deletes);
48330 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48331 xpage = radix_tree_delete(&cookie->stores, page->index);
48332 }
48333 spin_unlock(&cookie->stores_lock);
48334 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48335
48336 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48337
48338 - fscache_stat(&fscache_n_attr_changed_calls);
48339 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48340
48341 if (fscache_object_is_active(object)) {
48342 fscache_stat(&fscache_n_cop_attr_changed);
48343 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48344
48345 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48346
48347 - fscache_stat(&fscache_n_attr_changed);
48348 + fscache_stat_unchecked(&fscache_n_attr_changed);
48349
48350 op = kzalloc(sizeof(*op), GFP_KERNEL);
48351 if (!op) {
48352 - fscache_stat(&fscache_n_attr_changed_nomem);
48353 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48354 _leave(" = -ENOMEM");
48355 return -ENOMEM;
48356 }
48357 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48358 if (fscache_submit_exclusive_op(object, op) < 0)
48359 goto nobufs;
48360 spin_unlock(&cookie->lock);
48361 - fscache_stat(&fscache_n_attr_changed_ok);
48362 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48363 fscache_put_operation(op);
48364 _leave(" = 0");
48365 return 0;
48366 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48367 nobufs:
48368 spin_unlock(&cookie->lock);
48369 kfree(op);
48370 - fscache_stat(&fscache_n_attr_changed_nobufs);
48371 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48372 _leave(" = %d", -ENOBUFS);
48373 return -ENOBUFS;
48374 }
48375 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48376 /* allocate a retrieval operation and attempt to submit it */
48377 op = kzalloc(sizeof(*op), GFP_NOIO);
48378 if (!op) {
48379 - fscache_stat(&fscache_n_retrievals_nomem);
48380 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48381 return NULL;
48382 }
48383
48384 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48385 return 0;
48386 }
48387
48388 - fscache_stat(&fscache_n_retrievals_wait);
48389 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
48390
48391 jif = jiffies;
48392 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48393 fscache_wait_bit_interruptible,
48394 TASK_INTERRUPTIBLE) != 0) {
48395 - fscache_stat(&fscache_n_retrievals_intr);
48396 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48397 _leave(" = -ERESTARTSYS");
48398 return -ERESTARTSYS;
48399 }
48400 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48401 */
48402 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48403 struct fscache_retrieval *op,
48404 - atomic_t *stat_op_waits,
48405 - atomic_t *stat_object_dead)
48406 + atomic_unchecked_t *stat_op_waits,
48407 + atomic_unchecked_t *stat_object_dead)
48408 {
48409 int ret;
48410
48411 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48412 goto check_if_dead;
48413
48414 _debug(">>> WT");
48415 - fscache_stat(stat_op_waits);
48416 + fscache_stat_unchecked(stat_op_waits);
48417 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48418 fscache_wait_bit_interruptible,
48419 TASK_INTERRUPTIBLE) < 0) {
48420 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48421
48422 check_if_dead:
48423 if (unlikely(fscache_object_is_dead(object))) {
48424 - fscache_stat(stat_object_dead);
48425 + fscache_stat_unchecked(stat_object_dead);
48426 return -ENOBUFS;
48427 }
48428 return 0;
48429 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48430
48431 _enter("%p,%p,,,", cookie, page);
48432
48433 - fscache_stat(&fscache_n_retrievals);
48434 + fscache_stat_unchecked(&fscache_n_retrievals);
48435
48436 if (hlist_empty(&cookie->backing_objects))
48437 goto nobufs;
48438 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48439 goto nobufs_unlock;
48440 spin_unlock(&cookie->lock);
48441
48442 - fscache_stat(&fscache_n_retrieval_ops);
48443 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48444
48445 /* pin the netfs read context in case we need to do the actual netfs
48446 * read because we've encountered a cache read failure */
48447 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48448
48449 error:
48450 if (ret == -ENOMEM)
48451 - fscache_stat(&fscache_n_retrievals_nomem);
48452 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48453 else if (ret == -ERESTARTSYS)
48454 - fscache_stat(&fscache_n_retrievals_intr);
48455 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48456 else if (ret == -ENODATA)
48457 - fscache_stat(&fscache_n_retrievals_nodata);
48458 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48459 else if (ret < 0)
48460 - fscache_stat(&fscache_n_retrievals_nobufs);
48461 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48462 else
48463 - fscache_stat(&fscache_n_retrievals_ok);
48464 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48465
48466 fscache_put_retrieval(op);
48467 _leave(" = %d", ret);
48468 @@ -429,7 +429,7 @@ nobufs_unlock:
48469 spin_unlock(&cookie->lock);
48470 kfree(op);
48471 nobufs:
48472 - fscache_stat(&fscache_n_retrievals_nobufs);
48473 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48474 _leave(" = -ENOBUFS");
48475 return -ENOBUFS;
48476 }
48477 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48478
48479 _enter("%p,,%d,,,", cookie, *nr_pages);
48480
48481 - fscache_stat(&fscache_n_retrievals);
48482 + fscache_stat_unchecked(&fscache_n_retrievals);
48483
48484 if (hlist_empty(&cookie->backing_objects))
48485 goto nobufs;
48486 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48487 goto nobufs_unlock;
48488 spin_unlock(&cookie->lock);
48489
48490 - fscache_stat(&fscache_n_retrieval_ops);
48491 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48492
48493 /* pin the netfs read context in case we need to do the actual netfs
48494 * read because we've encountered a cache read failure */
48495 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48496
48497 error:
48498 if (ret == -ENOMEM)
48499 - fscache_stat(&fscache_n_retrievals_nomem);
48500 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48501 else if (ret == -ERESTARTSYS)
48502 - fscache_stat(&fscache_n_retrievals_intr);
48503 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48504 else if (ret == -ENODATA)
48505 - fscache_stat(&fscache_n_retrievals_nodata);
48506 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48507 else if (ret < 0)
48508 - fscache_stat(&fscache_n_retrievals_nobufs);
48509 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48510 else
48511 - fscache_stat(&fscache_n_retrievals_ok);
48512 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48513
48514 fscache_put_retrieval(op);
48515 _leave(" = %d", ret);
48516 @@ -545,7 +545,7 @@ nobufs_unlock:
48517 spin_unlock(&cookie->lock);
48518 kfree(op);
48519 nobufs:
48520 - fscache_stat(&fscache_n_retrievals_nobufs);
48521 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48522 _leave(" = -ENOBUFS");
48523 return -ENOBUFS;
48524 }
48525 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48526
48527 _enter("%p,%p,,,", cookie, page);
48528
48529 - fscache_stat(&fscache_n_allocs);
48530 + fscache_stat_unchecked(&fscache_n_allocs);
48531
48532 if (hlist_empty(&cookie->backing_objects))
48533 goto nobufs;
48534 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48535 goto nobufs_unlock;
48536 spin_unlock(&cookie->lock);
48537
48538 - fscache_stat(&fscache_n_alloc_ops);
48539 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48540
48541 ret = fscache_wait_for_retrieval_activation(
48542 object, op,
48543 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48544
48545 error:
48546 if (ret == -ERESTARTSYS)
48547 - fscache_stat(&fscache_n_allocs_intr);
48548 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48549 else if (ret < 0)
48550 - fscache_stat(&fscache_n_allocs_nobufs);
48551 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48552 else
48553 - fscache_stat(&fscache_n_allocs_ok);
48554 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48555
48556 fscache_put_retrieval(op);
48557 _leave(" = %d", ret);
48558 @@ -625,7 +625,7 @@ nobufs_unlock:
48559 spin_unlock(&cookie->lock);
48560 kfree(op);
48561 nobufs:
48562 - fscache_stat(&fscache_n_allocs_nobufs);
48563 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48564 _leave(" = -ENOBUFS");
48565 return -ENOBUFS;
48566 }
48567 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48568
48569 spin_lock(&cookie->stores_lock);
48570
48571 - fscache_stat(&fscache_n_store_calls);
48572 + fscache_stat_unchecked(&fscache_n_store_calls);
48573
48574 /* find a page to store */
48575 page = NULL;
48576 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48577 page = results[0];
48578 _debug("gang %d [%lx]", n, page->index);
48579 if (page->index > op->store_limit) {
48580 - fscache_stat(&fscache_n_store_pages_over_limit);
48581 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48582 goto superseded;
48583 }
48584
48585 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48586 spin_unlock(&cookie->stores_lock);
48587 spin_unlock(&object->lock);
48588
48589 - fscache_stat(&fscache_n_store_pages);
48590 + fscache_stat_unchecked(&fscache_n_store_pages);
48591 fscache_stat(&fscache_n_cop_write_page);
48592 ret = object->cache->ops->write_page(op, page);
48593 fscache_stat_d(&fscache_n_cop_write_page);
48594 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48595 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48596 ASSERT(PageFsCache(page));
48597
48598 - fscache_stat(&fscache_n_stores);
48599 + fscache_stat_unchecked(&fscache_n_stores);
48600
48601 op = kzalloc(sizeof(*op), GFP_NOIO);
48602 if (!op)
48603 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48604 spin_unlock(&cookie->stores_lock);
48605 spin_unlock(&object->lock);
48606
48607 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48608 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48609 op->store_limit = object->store_limit;
48610
48611 if (fscache_submit_op(object, &op->op) < 0)
48612 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48613
48614 spin_unlock(&cookie->lock);
48615 radix_tree_preload_end();
48616 - fscache_stat(&fscache_n_store_ops);
48617 - fscache_stat(&fscache_n_stores_ok);
48618 + fscache_stat_unchecked(&fscache_n_store_ops);
48619 + fscache_stat_unchecked(&fscache_n_stores_ok);
48620
48621 /* the work queue now carries its own ref on the object */
48622 fscache_put_operation(&op->op);
48623 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48624 return 0;
48625
48626 already_queued:
48627 - fscache_stat(&fscache_n_stores_again);
48628 + fscache_stat_unchecked(&fscache_n_stores_again);
48629 already_pending:
48630 spin_unlock(&cookie->stores_lock);
48631 spin_unlock(&object->lock);
48632 spin_unlock(&cookie->lock);
48633 radix_tree_preload_end();
48634 kfree(op);
48635 - fscache_stat(&fscache_n_stores_ok);
48636 + fscache_stat_unchecked(&fscache_n_stores_ok);
48637 _leave(" = 0");
48638 return 0;
48639
48640 @@ -851,14 +851,14 @@ nobufs:
48641 spin_unlock(&cookie->lock);
48642 radix_tree_preload_end();
48643 kfree(op);
48644 - fscache_stat(&fscache_n_stores_nobufs);
48645 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48646 _leave(" = -ENOBUFS");
48647 return -ENOBUFS;
48648
48649 nomem_free:
48650 kfree(op);
48651 nomem:
48652 - fscache_stat(&fscache_n_stores_oom);
48653 + fscache_stat_unchecked(&fscache_n_stores_oom);
48654 _leave(" = -ENOMEM");
48655 return -ENOMEM;
48656 }
48657 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48658 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48659 ASSERTCMP(page, !=, NULL);
48660
48661 - fscache_stat(&fscache_n_uncaches);
48662 + fscache_stat_unchecked(&fscache_n_uncaches);
48663
48664 /* cache withdrawal may beat us to it */
48665 if (!PageFsCache(page))
48666 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48667 unsigned long loop;
48668
48669 #ifdef CONFIG_FSCACHE_STATS
48670 - atomic_add(pagevec->nr, &fscache_n_marks);
48671 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48672 #endif
48673
48674 for (loop = 0; loop < pagevec->nr; loop++) {
48675 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48676 index 4765190..2a067f2 100644
48677 --- a/fs/fscache/stats.c
48678 +++ b/fs/fscache/stats.c
48679 @@ -18,95 +18,95 @@
48680 /*
48681 * operation counters
48682 */
48683 -atomic_t fscache_n_op_pend;
48684 -atomic_t fscache_n_op_run;
48685 -atomic_t fscache_n_op_enqueue;
48686 -atomic_t fscache_n_op_requeue;
48687 -atomic_t fscache_n_op_deferred_release;
48688 -atomic_t fscache_n_op_release;
48689 -atomic_t fscache_n_op_gc;
48690 -atomic_t fscache_n_op_cancelled;
48691 -atomic_t fscache_n_op_rejected;
48692 +atomic_unchecked_t fscache_n_op_pend;
48693 +atomic_unchecked_t fscache_n_op_run;
48694 +atomic_unchecked_t fscache_n_op_enqueue;
48695 +atomic_unchecked_t fscache_n_op_requeue;
48696 +atomic_unchecked_t fscache_n_op_deferred_release;
48697 +atomic_unchecked_t fscache_n_op_release;
48698 +atomic_unchecked_t fscache_n_op_gc;
48699 +atomic_unchecked_t fscache_n_op_cancelled;
48700 +atomic_unchecked_t fscache_n_op_rejected;
48701
48702 -atomic_t fscache_n_attr_changed;
48703 -atomic_t fscache_n_attr_changed_ok;
48704 -atomic_t fscache_n_attr_changed_nobufs;
48705 -atomic_t fscache_n_attr_changed_nomem;
48706 -atomic_t fscache_n_attr_changed_calls;
48707 +atomic_unchecked_t fscache_n_attr_changed;
48708 +atomic_unchecked_t fscache_n_attr_changed_ok;
48709 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48710 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48711 +atomic_unchecked_t fscache_n_attr_changed_calls;
48712
48713 -atomic_t fscache_n_allocs;
48714 -atomic_t fscache_n_allocs_ok;
48715 -atomic_t fscache_n_allocs_wait;
48716 -atomic_t fscache_n_allocs_nobufs;
48717 -atomic_t fscache_n_allocs_intr;
48718 -atomic_t fscache_n_allocs_object_dead;
48719 -atomic_t fscache_n_alloc_ops;
48720 -atomic_t fscache_n_alloc_op_waits;
48721 +atomic_unchecked_t fscache_n_allocs;
48722 +atomic_unchecked_t fscache_n_allocs_ok;
48723 +atomic_unchecked_t fscache_n_allocs_wait;
48724 +atomic_unchecked_t fscache_n_allocs_nobufs;
48725 +atomic_unchecked_t fscache_n_allocs_intr;
48726 +atomic_unchecked_t fscache_n_allocs_object_dead;
48727 +atomic_unchecked_t fscache_n_alloc_ops;
48728 +atomic_unchecked_t fscache_n_alloc_op_waits;
48729
48730 -atomic_t fscache_n_retrievals;
48731 -atomic_t fscache_n_retrievals_ok;
48732 -atomic_t fscache_n_retrievals_wait;
48733 -atomic_t fscache_n_retrievals_nodata;
48734 -atomic_t fscache_n_retrievals_nobufs;
48735 -atomic_t fscache_n_retrievals_intr;
48736 -atomic_t fscache_n_retrievals_nomem;
48737 -atomic_t fscache_n_retrievals_object_dead;
48738 -atomic_t fscache_n_retrieval_ops;
48739 -atomic_t fscache_n_retrieval_op_waits;
48740 +atomic_unchecked_t fscache_n_retrievals;
48741 +atomic_unchecked_t fscache_n_retrievals_ok;
48742 +atomic_unchecked_t fscache_n_retrievals_wait;
48743 +atomic_unchecked_t fscache_n_retrievals_nodata;
48744 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48745 +atomic_unchecked_t fscache_n_retrievals_intr;
48746 +atomic_unchecked_t fscache_n_retrievals_nomem;
48747 +atomic_unchecked_t fscache_n_retrievals_object_dead;
48748 +atomic_unchecked_t fscache_n_retrieval_ops;
48749 +atomic_unchecked_t fscache_n_retrieval_op_waits;
48750
48751 -atomic_t fscache_n_stores;
48752 -atomic_t fscache_n_stores_ok;
48753 -atomic_t fscache_n_stores_again;
48754 -atomic_t fscache_n_stores_nobufs;
48755 -atomic_t fscache_n_stores_oom;
48756 -atomic_t fscache_n_store_ops;
48757 -atomic_t fscache_n_store_calls;
48758 -atomic_t fscache_n_store_pages;
48759 -atomic_t fscache_n_store_radix_deletes;
48760 -atomic_t fscache_n_store_pages_over_limit;
48761 +atomic_unchecked_t fscache_n_stores;
48762 +atomic_unchecked_t fscache_n_stores_ok;
48763 +atomic_unchecked_t fscache_n_stores_again;
48764 +atomic_unchecked_t fscache_n_stores_nobufs;
48765 +atomic_unchecked_t fscache_n_stores_oom;
48766 +atomic_unchecked_t fscache_n_store_ops;
48767 +atomic_unchecked_t fscache_n_store_calls;
48768 +atomic_unchecked_t fscache_n_store_pages;
48769 +atomic_unchecked_t fscache_n_store_radix_deletes;
48770 +atomic_unchecked_t fscache_n_store_pages_over_limit;
48771
48772 -atomic_t fscache_n_store_vmscan_not_storing;
48773 -atomic_t fscache_n_store_vmscan_gone;
48774 -atomic_t fscache_n_store_vmscan_busy;
48775 -atomic_t fscache_n_store_vmscan_cancelled;
48776 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48777 +atomic_unchecked_t fscache_n_store_vmscan_gone;
48778 +atomic_unchecked_t fscache_n_store_vmscan_busy;
48779 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48780
48781 -atomic_t fscache_n_marks;
48782 -atomic_t fscache_n_uncaches;
48783 +atomic_unchecked_t fscache_n_marks;
48784 +atomic_unchecked_t fscache_n_uncaches;
48785
48786 -atomic_t fscache_n_acquires;
48787 -atomic_t fscache_n_acquires_null;
48788 -atomic_t fscache_n_acquires_no_cache;
48789 -atomic_t fscache_n_acquires_ok;
48790 -atomic_t fscache_n_acquires_nobufs;
48791 -atomic_t fscache_n_acquires_oom;
48792 +atomic_unchecked_t fscache_n_acquires;
48793 +atomic_unchecked_t fscache_n_acquires_null;
48794 +atomic_unchecked_t fscache_n_acquires_no_cache;
48795 +atomic_unchecked_t fscache_n_acquires_ok;
48796 +atomic_unchecked_t fscache_n_acquires_nobufs;
48797 +atomic_unchecked_t fscache_n_acquires_oom;
48798
48799 -atomic_t fscache_n_updates;
48800 -atomic_t fscache_n_updates_null;
48801 -atomic_t fscache_n_updates_run;
48802 +atomic_unchecked_t fscache_n_updates;
48803 +atomic_unchecked_t fscache_n_updates_null;
48804 +atomic_unchecked_t fscache_n_updates_run;
48805
48806 -atomic_t fscache_n_relinquishes;
48807 -atomic_t fscache_n_relinquishes_null;
48808 -atomic_t fscache_n_relinquishes_waitcrt;
48809 -atomic_t fscache_n_relinquishes_retire;
48810 +atomic_unchecked_t fscache_n_relinquishes;
48811 +atomic_unchecked_t fscache_n_relinquishes_null;
48812 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48813 +atomic_unchecked_t fscache_n_relinquishes_retire;
48814
48815 -atomic_t fscache_n_cookie_index;
48816 -atomic_t fscache_n_cookie_data;
48817 -atomic_t fscache_n_cookie_special;
48818 +atomic_unchecked_t fscache_n_cookie_index;
48819 +atomic_unchecked_t fscache_n_cookie_data;
48820 +atomic_unchecked_t fscache_n_cookie_special;
48821
48822 -atomic_t fscache_n_object_alloc;
48823 -atomic_t fscache_n_object_no_alloc;
48824 -atomic_t fscache_n_object_lookups;
48825 -atomic_t fscache_n_object_lookups_negative;
48826 -atomic_t fscache_n_object_lookups_positive;
48827 -atomic_t fscache_n_object_lookups_timed_out;
48828 -atomic_t fscache_n_object_created;
48829 -atomic_t fscache_n_object_avail;
48830 -atomic_t fscache_n_object_dead;
48831 +atomic_unchecked_t fscache_n_object_alloc;
48832 +atomic_unchecked_t fscache_n_object_no_alloc;
48833 +atomic_unchecked_t fscache_n_object_lookups;
48834 +atomic_unchecked_t fscache_n_object_lookups_negative;
48835 +atomic_unchecked_t fscache_n_object_lookups_positive;
48836 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
48837 +atomic_unchecked_t fscache_n_object_created;
48838 +atomic_unchecked_t fscache_n_object_avail;
48839 +atomic_unchecked_t fscache_n_object_dead;
48840
48841 -atomic_t fscache_n_checkaux_none;
48842 -atomic_t fscache_n_checkaux_okay;
48843 -atomic_t fscache_n_checkaux_update;
48844 -atomic_t fscache_n_checkaux_obsolete;
48845 +atomic_unchecked_t fscache_n_checkaux_none;
48846 +atomic_unchecked_t fscache_n_checkaux_okay;
48847 +atomic_unchecked_t fscache_n_checkaux_update;
48848 +atomic_unchecked_t fscache_n_checkaux_obsolete;
48849
48850 atomic_t fscache_n_cop_alloc_object;
48851 atomic_t fscache_n_cop_lookup_object;
48852 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
48853 seq_puts(m, "FS-Cache statistics\n");
48854
48855 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
48856 - atomic_read(&fscache_n_cookie_index),
48857 - atomic_read(&fscache_n_cookie_data),
48858 - atomic_read(&fscache_n_cookie_special));
48859 + atomic_read_unchecked(&fscache_n_cookie_index),
48860 + atomic_read_unchecked(&fscache_n_cookie_data),
48861 + atomic_read_unchecked(&fscache_n_cookie_special));
48862
48863 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
48864 - atomic_read(&fscache_n_object_alloc),
48865 - atomic_read(&fscache_n_object_no_alloc),
48866 - atomic_read(&fscache_n_object_avail),
48867 - atomic_read(&fscache_n_object_dead));
48868 + atomic_read_unchecked(&fscache_n_object_alloc),
48869 + atomic_read_unchecked(&fscache_n_object_no_alloc),
48870 + atomic_read_unchecked(&fscache_n_object_avail),
48871 + atomic_read_unchecked(&fscache_n_object_dead));
48872 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
48873 - atomic_read(&fscache_n_checkaux_none),
48874 - atomic_read(&fscache_n_checkaux_okay),
48875 - atomic_read(&fscache_n_checkaux_update),
48876 - atomic_read(&fscache_n_checkaux_obsolete));
48877 + atomic_read_unchecked(&fscache_n_checkaux_none),
48878 + atomic_read_unchecked(&fscache_n_checkaux_okay),
48879 + atomic_read_unchecked(&fscache_n_checkaux_update),
48880 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
48881
48882 seq_printf(m, "Pages : mrk=%u unc=%u\n",
48883 - atomic_read(&fscache_n_marks),
48884 - atomic_read(&fscache_n_uncaches));
48885 + atomic_read_unchecked(&fscache_n_marks),
48886 + atomic_read_unchecked(&fscache_n_uncaches));
48887
48888 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
48889 " oom=%u\n",
48890 - atomic_read(&fscache_n_acquires),
48891 - atomic_read(&fscache_n_acquires_null),
48892 - atomic_read(&fscache_n_acquires_no_cache),
48893 - atomic_read(&fscache_n_acquires_ok),
48894 - atomic_read(&fscache_n_acquires_nobufs),
48895 - atomic_read(&fscache_n_acquires_oom));
48896 + atomic_read_unchecked(&fscache_n_acquires),
48897 + atomic_read_unchecked(&fscache_n_acquires_null),
48898 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
48899 + atomic_read_unchecked(&fscache_n_acquires_ok),
48900 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
48901 + atomic_read_unchecked(&fscache_n_acquires_oom));
48902
48903 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
48904 - atomic_read(&fscache_n_object_lookups),
48905 - atomic_read(&fscache_n_object_lookups_negative),
48906 - atomic_read(&fscache_n_object_lookups_positive),
48907 - atomic_read(&fscache_n_object_created),
48908 - atomic_read(&fscache_n_object_lookups_timed_out));
48909 + atomic_read_unchecked(&fscache_n_object_lookups),
48910 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
48911 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
48912 + atomic_read_unchecked(&fscache_n_object_created),
48913 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
48914
48915 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
48916 - atomic_read(&fscache_n_updates),
48917 - atomic_read(&fscache_n_updates_null),
48918 - atomic_read(&fscache_n_updates_run));
48919 + atomic_read_unchecked(&fscache_n_updates),
48920 + atomic_read_unchecked(&fscache_n_updates_null),
48921 + atomic_read_unchecked(&fscache_n_updates_run));
48922
48923 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
48924 - atomic_read(&fscache_n_relinquishes),
48925 - atomic_read(&fscache_n_relinquishes_null),
48926 - atomic_read(&fscache_n_relinquishes_waitcrt),
48927 - atomic_read(&fscache_n_relinquishes_retire));
48928 + atomic_read_unchecked(&fscache_n_relinquishes),
48929 + atomic_read_unchecked(&fscache_n_relinquishes_null),
48930 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
48931 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
48932
48933 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
48934 - atomic_read(&fscache_n_attr_changed),
48935 - atomic_read(&fscache_n_attr_changed_ok),
48936 - atomic_read(&fscache_n_attr_changed_nobufs),
48937 - atomic_read(&fscache_n_attr_changed_nomem),
48938 - atomic_read(&fscache_n_attr_changed_calls));
48939 + atomic_read_unchecked(&fscache_n_attr_changed),
48940 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
48941 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
48942 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
48943 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
48944
48945 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
48946 - atomic_read(&fscache_n_allocs),
48947 - atomic_read(&fscache_n_allocs_ok),
48948 - atomic_read(&fscache_n_allocs_wait),
48949 - atomic_read(&fscache_n_allocs_nobufs),
48950 - atomic_read(&fscache_n_allocs_intr));
48951 + atomic_read_unchecked(&fscache_n_allocs),
48952 + atomic_read_unchecked(&fscache_n_allocs_ok),
48953 + atomic_read_unchecked(&fscache_n_allocs_wait),
48954 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
48955 + atomic_read_unchecked(&fscache_n_allocs_intr));
48956 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
48957 - atomic_read(&fscache_n_alloc_ops),
48958 - atomic_read(&fscache_n_alloc_op_waits),
48959 - atomic_read(&fscache_n_allocs_object_dead));
48960 + atomic_read_unchecked(&fscache_n_alloc_ops),
48961 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
48962 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
48963
48964 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
48965 " int=%u oom=%u\n",
48966 - atomic_read(&fscache_n_retrievals),
48967 - atomic_read(&fscache_n_retrievals_ok),
48968 - atomic_read(&fscache_n_retrievals_wait),
48969 - atomic_read(&fscache_n_retrievals_nodata),
48970 - atomic_read(&fscache_n_retrievals_nobufs),
48971 - atomic_read(&fscache_n_retrievals_intr),
48972 - atomic_read(&fscache_n_retrievals_nomem));
48973 + atomic_read_unchecked(&fscache_n_retrievals),
48974 + atomic_read_unchecked(&fscache_n_retrievals_ok),
48975 + atomic_read_unchecked(&fscache_n_retrievals_wait),
48976 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
48977 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
48978 + atomic_read_unchecked(&fscache_n_retrievals_intr),
48979 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
48980 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
48981 - atomic_read(&fscache_n_retrieval_ops),
48982 - atomic_read(&fscache_n_retrieval_op_waits),
48983 - atomic_read(&fscache_n_retrievals_object_dead));
48984 + atomic_read_unchecked(&fscache_n_retrieval_ops),
48985 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
48986 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
48987
48988 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
48989 - atomic_read(&fscache_n_stores),
48990 - atomic_read(&fscache_n_stores_ok),
48991 - atomic_read(&fscache_n_stores_again),
48992 - atomic_read(&fscache_n_stores_nobufs),
48993 - atomic_read(&fscache_n_stores_oom));
48994 + atomic_read_unchecked(&fscache_n_stores),
48995 + atomic_read_unchecked(&fscache_n_stores_ok),
48996 + atomic_read_unchecked(&fscache_n_stores_again),
48997 + atomic_read_unchecked(&fscache_n_stores_nobufs),
48998 + atomic_read_unchecked(&fscache_n_stores_oom));
48999 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49000 - atomic_read(&fscache_n_store_ops),
49001 - atomic_read(&fscache_n_store_calls),
49002 - atomic_read(&fscache_n_store_pages),
49003 - atomic_read(&fscache_n_store_radix_deletes),
49004 - atomic_read(&fscache_n_store_pages_over_limit));
49005 + atomic_read_unchecked(&fscache_n_store_ops),
49006 + atomic_read_unchecked(&fscache_n_store_calls),
49007 + atomic_read_unchecked(&fscache_n_store_pages),
49008 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49009 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49010
49011 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
49012 - atomic_read(&fscache_n_store_vmscan_not_storing),
49013 - atomic_read(&fscache_n_store_vmscan_gone),
49014 - atomic_read(&fscache_n_store_vmscan_busy),
49015 - atomic_read(&fscache_n_store_vmscan_cancelled));
49016 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49017 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49018 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49019 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
49020
49021 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49022 - atomic_read(&fscache_n_op_pend),
49023 - atomic_read(&fscache_n_op_run),
49024 - atomic_read(&fscache_n_op_enqueue),
49025 - atomic_read(&fscache_n_op_cancelled),
49026 - atomic_read(&fscache_n_op_rejected));
49027 + atomic_read_unchecked(&fscache_n_op_pend),
49028 + atomic_read_unchecked(&fscache_n_op_run),
49029 + atomic_read_unchecked(&fscache_n_op_enqueue),
49030 + atomic_read_unchecked(&fscache_n_op_cancelled),
49031 + atomic_read_unchecked(&fscache_n_op_rejected));
49032 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49033 - atomic_read(&fscache_n_op_deferred_release),
49034 - atomic_read(&fscache_n_op_release),
49035 - atomic_read(&fscache_n_op_gc));
49036 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49037 + atomic_read_unchecked(&fscache_n_op_release),
49038 + atomic_read_unchecked(&fscache_n_op_gc));
49039
49040 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49041 atomic_read(&fscache_n_cop_alloc_object),
49042 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49043 index ee8d550..7189d8c 100644
49044 --- a/fs/fuse/cuse.c
49045 +++ b/fs/fuse/cuse.c
49046 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
49047 INIT_LIST_HEAD(&cuse_conntbl[i]);
49048
49049 /* inherit and extend fuse_dev_operations */
49050 - cuse_channel_fops = fuse_dev_operations;
49051 - cuse_channel_fops.owner = THIS_MODULE;
49052 - cuse_channel_fops.open = cuse_channel_open;
49053 - cuse_channel_fops.release = cuse_channel_release;
49054 + pax_open_kernel();
49055 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49056 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49057 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
49058 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
49059 + pax_close_kernel();
49060
49061 cuse_class = class_create(THIS_MODULE, "cuse");
49062 if (IS_ERR(cuse_class))
49063 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49064 index 8c23fa7..0e3aac7 100644
49065 --- a/fs/fuse/dev.c
49066 +++ b/fs/fuse/dev.c
49067 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49068 ret = 0;
49069 pipe_lock(pipe);
49070
49071 - if (!pipe->readers) {
49072 + if (!atomic_read(&pipe->readers)) {
49073 send_sig(SIGPIPE, current, 0);
49074 if (!ret)
49075 ret = -EPIPE;
49076 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
49077 index 324bc08..4fdd56e 100644
49078 --- a/fs/fuse/dir.c
49079 +++ b/fs/fuse/dir.c
49080 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49081 return link;
49082 }
49083
49084 -static void free_link(char *link)
49085 +static void free_link(const char *link)
49086 {
49087 if (!IS_ERR(link))
49088 free_page((unsigned long) link);
49089 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49090 index 381893c..3793318 100644
49091 --- a/fs/gfs2/inode.c
49092 +++ b/fs/gfs2/inode.c
49093 @@ -1490,7 +1490,7 @@ out:
49094
49095 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49096 {
49097 - char *s = nd_get_link(nd);
49098 + const char *s = nd_get_link(nd);
49099 if (!IS_ERR(s))
49100 kfree(s);
49101 }
49102 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49103 index c5bc355..163a13e 100644
49104 --- a/fs/hugetlbfs/inode.c
49105 +++ b/fs/hugetlbfs/inode.c
49106 @@ -153,6 +153,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49107 struct vm_area_struct *vma;
49108 unsigned long start_addr;
49109 struct hstate *h = hstate_file(file);
49110 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
49111
49112 if (len & ~huge_page_mask(h))
49113 return -EINVAL;
49114 @@ -165,18 +166,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49115 return addr;
49116 }
49117
49118 +#ifdef CONFIG_PAX_RANDMMAP
49119 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
49120 +#endif
49121 +
49122 if (addr) {
49123 addr = ALIGN(addr, huge_page_size(h));
49124 vma = find_vma(mm, addr);
49125 - if (TASK_SIZE - len >= addr &&
49126 - (!vma || addr + len <= vma->vm_start))
49127 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
49128 return addr;
49129 }
49130
49131 if (len > mm->cached_hole_size)
49132 start_addr = mm->free_area_cache;
49133 else {
49134 - start_addr = TASK_UNMAPPED_BASE;
49135 + start_addr = mm->mmap_base;
49136 mm->cached_hole_size = 0;
49137 }
49138
49139 @@ -190,15 +194,15 @@ full_search:
49140 * Start a new search - just in case we missed
49141 * some holes.
49142 */
49143 - if (start_addr != TASK_UNMAPPED_BASE) {
49144 - start_addr = TASK_UNMAPPED_BASE;
49145 + if (start_addr != mm->mmap_base) {
49146 + start_addr = mm->mmap_base;
49147 mm->cached_hole_size = 0;
49148 goto full_search;
49149 }
49150 return -ENOMEM;
49151 }
49152
49153 - if (!vma || addr + len <= vma->vm_start) {
49154 + if (check_heap_stack_gap(vma, addr, len, offset)) {
49155 mm->free_area_cache = addr + len;
49156 return addr;
49157 }
49158 @@ -923,7 +927,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49159 .kill_sb = kill_litter_super,
49160 };
49161
49162 -static struct vfsmount *hugetlbfs_vfsmount;
49163 +struct vfsmount *hugetlbfs_vfsmount;
49164
49165 static int can_do_hugetlb_shm(void)
49166 {
49167 diff --git a/fs/inode.c b/fs/inode.c
49168 index 64999f1..8fad608 100644
49169 --- a/fs/inode.c
49170 +++ b/fs/inode.c
49171 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49172
49173 #ifdef CONFIG_SMP
49174 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49175 - static atomic_t shared_last_ino;
49176 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49177 + static atomic_unchecked_t shared_last_ino;
49178 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49179
49180 res = next - LAST_INO_BATCH;
49181 }
49182 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49183 index 4a6cf28..d3a29d3 100644
49184 --- a/fs/jffs2/erase.c
49185 +++ b/fs/jffs2/erase.c
49186 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49187 struct jffs2_unknown_node marker = {
49188 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49189 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49190 - .totlen = cpu_to_je32(c->cleanmarker_size)
49191 + .totlen = cpu_to_je32(c->cleanmarker_size),
49192 + .hdr_crc = cpu_to_je32(0)
49193 };
49194
49195 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49196 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49197 index a6597d6..41b30ec 100644
49198 --- a/fs/jffs2/wbuf.c
49199 +++ b/fs/jffs2/wbuf.c
49200 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49201 {
49202 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49203 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49204 - .totlen = constant_cpu_to_je32(8)
49205 + .totlen = constant_cpu_to_je32(8),
49206 + .hdr_crc = constant_cpu_to_je32(0)
49207 };
49208
49209 /*
49210 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49211 index 1a543be..d803c40 100644
49212 --- a/fs/jfs/super.c
49213 +++ b/fs/jfs/super.c
49214 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49215
49216 jfs_inode_cachep =
49217 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49218 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49219 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49220 init_once);
49221 if (jfs_inode_cachep == NULL)
49222 return -ENOMEM;
49223 diff --git a/fs/libfs.c b/fs/libfs.c
49224 index 7cc37ca..b3e3eec 100644
49225 --- a/fs/libfs.c
49226 +++ b/fs/libfs.c
49227 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49228
49229 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49230 struct dentry *next;
49231 + char d_name[sizeof(next->d_iname)];
49232 + const unsigned char *name;
49233 +
49234 next = list_entry(p, struct dentry, d_u.d_child);
49235 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49236 if (!simple_positive(next)) {
49237 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49238
49239 spin_unlock(&next->d_lock);
49240 spin_unlock(&dentry->d_lock);
49241 - if (filldir(dirent, next->d_name.name,
49242 + name = next->d_name.name;
49243 + if (name == next->d_iname) {
49244 + memcpy(d_name, name, next->d_name.len);
49245 + name = d_name;
49246 + }
49247 + if (filldir(dirent, name,
49248 next->d_name.len, filp->f_pos,
49249 next->d_inode->i_ino,
49250 dt_type(next->d_inode)) < 0)
49251 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49252 index 05d2912..760abfa 100644
49253 --- a/fs/lockd/clntproc.c
49254 +++ b/fs/lockd/clntproc.c
49255 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49256 /*
49257 * Cookie counter for NLM requests
49258 */
49259 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49260 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49261
49262 void nlmclnt_next_cookie(struct nlm_cookie *c)
49263 {
49264 - u32 cookie = atomic_inc_return(&nlm_cookie);
49265 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49266
49267 memcpy(c->data, &cookie, 4);
49268 c->len=4;
49269 diff --git a/fs/locks.c b/fs/locks.c
49270 index a94e331..060bce3 100644
49271 --- a/fs/locks.c
49272 +++ b/fs/locks.c
49273 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49274 return;
49275
49276 if (filp->f_op && filp->f_op->flock) {
49277 - struct file_lock fl = {
49278 + struct file_lock flock = {
49279 .fl_pid = current->tgid,
49280 .fl_file = filp,
49281 .fl_flags = FL_FLOCK,
49282 .fl_type = F_UNLCK,
49283 .fl_end = OFFSET_MAX,
49284 };
49285 - filp->f_op->flock(filp, F_SETLKW, &fl);
49286 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
49287 - fl.fl_ops->fl_release_private(&fl);
49288 + filp->f_op->flock(filp, F_SETLKW, &flock);
49289 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
49290 + flock.fl_ops->fl_release_private(&flock);
49291 }
49292
49293 lock_flocks();
49294 diff --git a/fs/namei.c b/fs/namei.c
49295 index 5f4cdf3..959a013 100644
49296 --- a/fs/namei.c
49297 +++ b/fs/namei.c
49298 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49299 if (ret != -EACCES)
49300 return ret;
49301
49302 +#ifdef CONFIG_GRKERNSEC
49303 + /* we'll block if we have to log due to a denied capability use */
49304 + if (mask & MAY_NOT_BLOCK)
49305 + return -ECHILD;
49306 +#endif
49307 +
49308 if (S_ISDIR(inode->i_mode)) {
49309 /* DACs are overridable for directories */
49310 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
49311 - return 0;
49312 if (!(mask & MAY_WRITE))
49313 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49314 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49315 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49316 return 0;
49317 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
49318 + return 0;
49319 return -EACCES;
49320 }
49321 /*
49322 + * Searching includes executable on directories, else just read.
49323 + */
49324 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49325 + if (mask == MAY_READ)
49326 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49327 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49328 + return 0;
49329 +
49330 + /*
49331 * Read/write DACs are always overridable.
49332 * Executable DACs are overridable when there is
49333 * at least one exec bit set.
49334 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49335 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49336 return 0;
49337
49338 - /*
49339 - * Searching includes executable on directories, else just read.
49340 - */
49341 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49342 - if (mask == MAY_READ)
49343 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49344 - return 0;
49345 -
49346 return -EACCES;
49347 }
49348
49349 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49350 {
49351 struct dentry *dentry = link->dentry;
49352 int error;
49353 - char *s;
49354 + const char *s;
49355
49356 BUG_ON(nd->flags & LOOKUP_RCU);
49357
49358 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49359 if (error)
49360 goto out_put_nd_path;
49361
49362 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
49363 + dentry->d_inode, dentry, nd->path.mnt)) {
49364 + error = -EACCES;
49365 + goto out_put_nd_path;
49366 + }
49367 +
49368 nd->last_type = LAST_BIND;
49369 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49370 error = PTR_ERR(*p);
49371 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49372 break;
49373 res = walk_component(nd, path, &nd->last,
49374 nd->last_type, LOOKUP_FOLLOW);
49375 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49376 + res = -EACCES;
49377 put_link(nd, &link, cookie);
49378 } while (res > 0);
49379
49380 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49381 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49382 {
49383 unsigned long a, b, adata, bdata, mask, hash, len;
49384 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49385 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49386
49387 hash = a = 0;
49388 len = -sizeof(unsigned long);
49389 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49390 if (err)
49391 break;
49392 err = lookup_last(nd, &path);
49393 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
49394 + err = -EACCES;
49395 put_link(nd, &link, cookie);
49396 }
49397 }
49398 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49399 if (!err)
49400 err = complete_walk(nd);
49401
49402 + if (!(nd->flags & LOOKUP_PARENT)) {
49403 +#ifdef CONFIG_GRKERNSEC
49404 + if (flags & LOOKUP_RCU) {
49405 + if (!err)
49406 + path_put(&nd->path);
49407 + err = -ECHILD;
49408 + } else
49409 +#endif
49410 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49411 + if (!err)
49412 + path_put(&nd->path);
49413 + err = -ENOENT;
49414 + }
49415 + }
49416 +
49417 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49418 if (!nd->inode->i_op->lookup) {
49419 path_put(&nd->path);
49420 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49421 retval = path_lookupat(dfd, name->name,
49422 flags | LOOKUP_REVAL, nd);
49423
49424 - if (likely(!retval))
49425 + if (likely(!retval)) {
49426 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49427 +#ifdef CONFIG_GRKERNSEC
49428 + if (flags & LOOKUP_RCU)
49429 + return -ECHILD;
49430 +#endif
49431 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49432 + return -ENOENT;
49433 + }
49434 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49435 + }
49436 return retval;
49437 }
49438
49439 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49440 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49441 return -EPERM;
49442
49443 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49444 + return -EPERM;
49445 + if (gr_handle_rawio(inode))
49446 + return -EPERM;
49447 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49448 + return -EACCES;
49449 +
49450 return 0;
49451 }
49452
49453 @@ -2623,7 +2672,7 @@ looked_up:
49454 * cleared otherwise prior to returning.
49455 */
49456 static int lookup_open(struct nameidata *nd, struct path *path,
49457 - struct file *file,
49458 + struct path *link, struct file *file,
49459 const struct open_flags *op,
49460 bool got_write, int *opened)
49461 {
49462 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49463 /* Negative dentry, just create the file */
49464 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49465 umode_t mode = op->mode;
49466 +
49467 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49468 + error = -EACCES;
49469 + goto out_dput;
49470 + }
49471 +
49472 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49473 + error = -EACCES;
49474 + goto out_dput;
49475 + }
49476 +
49477 if (!IS_POSIXACL(dir->d_inode))
49478 mode &= ~current_umask();
49479 /*
49480 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49481 nd->flags & LOOKUP_EXCL);
49482 if (error)
49483 goto out_dput;
49484 + else
49485 + gr_handle_create(dentry, nd->path.mnt);
49486 }
49487 out_no_open:
49488 path->dentry = dentry;
49489 @@ -2693,7 +2755,7 @@ out_dput:
49490 /*
49491 * Handle the last step of open()
49492 */
49493 -static int do_last(struct nameidata *nd, struct path *path,
49494 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49495 struct file *file, const struct open_flags *op,
49496 int *opened, struct filename *name)
49497 {
49498 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49499 error = complete_walk(nd);
49500 if (error)
49501 return error;
49502 +#ifdef CONFIG_GRKERNSEC
49503 + if (nd->flags & LOOKUP_RCU) {
49504 + error = -ECHILD;
49505 + goto out;
49506 + }
49507 +#endif
49508 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49509 + error = -ENOENT;
49510 + goto out;
49511 + }
49512 audit_inode(name, nd->path.dentry, 0);
49513 if (open_flag & O_CREAT) {
49514 error = -EISDIR;
49515 goto out;
49516 }
49517 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49518 + error = -EACCES;
49519 + goto out;
49520 + }
49521 goto finish_open;
49522 case LAST_BIND:
49523 error = complete_walk(nd);
49524 if (error)
49525 return error;
49526 +#ifdef CONFIG_GRKERNSEC
49527 + if (nd->flags & LOOKUP_RCU) {
49528 + error = -ECHILD;
49529 + goto out;
49530 + }
49531 +#endif
49532 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49533 + error = -ENOENT;
49534 + goto out;
49535 + }
49536 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49537 + error = -EACCES;
49538 + goto out;
49539 + }
49540 audit_inode(name, dir, 0);
49541 goto finish_open;
49542 }
49543 @@ -2780,7 +2870,7 @@ retry_lookup:
49544 */
49545 }
49546 mutex_lock(&dir->d_inode->i_mutex);
49547 - error = lookup_open(nd, path, file, op, got_write, opened);
49548 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49549 mutex_unlock(&dir->d_inode->i_mutex);
49550
49551 if (error <= 0) {
49552 @@ -2804,11 +2894,28 @@ retry_lookup:
49553 goto finish_open_created;
49554 }
49555
49556 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49557 + error = -ENOENT;
49558 + goto exit_dput;
49559 + }
49560 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49561 + error = -EACCES;
49562 + goto exit_dput;
49563 + }
49564 +
49565 /*
49566 * create/update audit record if it already exists.
49567 */
49568 - if (path->dentry->d_inode)
49569 + if (path->dentry->d_inode) {
49570 + /* only check if O_CREAT is specified, all other checks need to go
49571 + into may_open */
49572 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49573 + error = -EACCES;
49574 + goto exit_dput;
49575 + }
49576 +
49577 audit_inode(name, path->dentry, 0);
49578 + }
49579
49580 /*
49581 * If atomic_open() acquired write access it is dropped now due to
49582 @@ -2849,6 +2956,11 @@ finish_lookup:
49583 }
49584 }
49585 BUG_ON(inode != path->dentry->d_inode);
49586 + /* if we're resolving a symlink to another symlink */
49587 + if (link && gr_handle_symlink_owner(link, inode)) {
49588 + error = -EACCES;
49589 + goto out;
49590 + }
49591 return 1;
49592 }
49593
49594 @@ -2858,7 +2970,6 @@ finish_lookup:
49595 save_parent.dentry = nd->path.dentry;
49596 save_parent.mnt = mntget(path->mnt);
49597 nd->path.dentry = path->dentry;
49598 -
49599 }
49600 nd->inode = inode;
49601 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49602 @@ -2867,6 +2978,22 @@ finish_lookup:
49603 path_put(&save_parent);
49604 return error;
49605 }
49606 +
49607 +#ifdef CONFIG_GRKERNSEC
49608 + if (nd->flags & LOOKUP_RCU) {
49609 + error = -ECHILD;
49610 + goto out;
49611 + }
49612 +#endif
49613 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49614 + error = -ENOENT;
49615 + goto out;
49616 + }
49617 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49618 + error = -EACCES;
49619 + goto out;
49620 + }
49621 +
49622 error = -EISDIR;
49623 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49624 goto out;
49625 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49626 if (unlikely(error))
49627 goto out;
49628
49629 - error = do_last(nd, &path, file, op, &opened, pathname);
49630 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49631 while (unlikely(error > 0)) { /* trailing symlink */
49632 struct path link = path;
49633 void *cookie;
49634 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49635 error = follow_link(&link, nd, &cookie);
49636 if (unlikely(error))
49637 break;
49638 - error = do_last(nd, &path, file, op, &opened, pathname);
49639 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49640 put_link(nd, &link, cookie);
49641 }
49642 out:
49643 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49644 goto unlock;
49645
49646 error = -EEXIST;
49647 - if (dentry->d_inode)
49648 + if (dentry->d_inode) {
49649 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49650 + error = -ENOENT;
49651 + }
49652 goto fail;
49653 + }
49654 /*
49655 * Special case - lookup gave negative, but... we had foo/bar/
49656 * From the vfs_mknod() POV we just have a negative dentry -
49657 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49658 }
49659 EXPORT_SYMBOL(user_path_create);
49660
49661 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49662 +{
49663 + struct filename *tmp = getname(pathname);
49664 + struct dentry *res;
49665 + if (IS_ERR(tmp))
49666 + return ERR_CAST(tmp);
49667 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49668 + if (IS_ERR(res))
49669 + putname(tmp);
49670 + else
49671 + *to = tmp;
49672 + return res;
49673 +}
49674 +
49675 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49676 {
49677 int error = may_create(dir, dentry);
49678 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49679
49680 if (!IS_POSIXACL(path.dentry->d_inode))
49681 mode &= ~current_umask();
49682 +
49683 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49684 + error = -EPERM;
49685 + goto out;
49686 + }
49687 +
49688 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49689 + error = -EACCES;
49690 + goto out;
49691 + }
49692 +
49693 error = security_path_mknod(&path, dentry, mode, dev);
49694 if (error)
49695 goto out;
49696 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49697 break;
49698 }
49699 out:
49700 + if (!error)
49701 + gr_handle_create(dentry, path.mnt);
49702 done_path_create(&path, dentry);
49703 return error;
49704 }
49705 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49706
49707 if (!IS_POSIXACL(path.dentry->d_inode))
49708 mode &= ~current_umask();
49709 +
49710 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49711 + error = -EACCES;
49712 + goto out;
49713 + }
49714 +
49715 error = security_path_mkdir(&path, dentry, mode);
49716 if (!error)
49717 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49718 + if (!error)
49719 + gr_handle_create(dentry, path.mnt);
49720 +out:
49721 done_path_create(&path, dentry);
49722 return error;
49723 }
49724 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49725 struct filename *name;
49726 struct dentry *dentry;
49727 struct nameidata nd;
49728 + ino_t saved_ino = 0;
49729 + dev_t saved_dev = 0;
49730
49731 name = user_path_parent(dfd, pathname, &nd);
49732 if (IS_ERR(name))
49733 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49734 error = -ENOENT;
49735 goto exit3;
49736 }
49737 +
49738 + saved_ino = dentry->d_inode->i_ino;
49739 + saved_dev = gr_get_dev_from_dentry(dentry);
49740 +
49741 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49742 + error = -EACCES;
49743 + goto exit3;
49744 + }
49745 +
49746 error = security_path_rmdir(&nd.path, dentry);
49747 if (error)
49748 goto exit3;
49749 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49750 + if (!error && (saved_dev || saved_ino))
49751 + gr_handle_delete(saved_ino, saved_dev);
49752 exit3:
49753 dput(dentry);
49754 exit2:
49755 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49756 struct dentry *dentry;
49757 struct nameidata nd;
49758 struct inode *inode = NULL;
49759 + ino_t saved_ino = 0;
49760 + dev_t saved_dev = 0;
49761
49762 name = user_path_parent(dfd, pathname, &nd);
49763 if (IS_ERR(name))
49764 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49765 if (!inode)
49766 goto slashes;
49767 ihold(inode);
49768 +
49769 + if (inode->i_nlink <= 1) {
49770 + saved_ino = inode->i_ino;
49771 + saved_dev = gr_get_dev_from_dentry(dentry);
49772 + }
49773 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49774 + error = -EACCES;
49775 + goto exit2;
49776 + }
49777 +
49778 error = security_path_unlink(&nd.path, dentry);
49779 if (error)
49780 goto exit2;
49781 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49782 + if (!error && (saved_ino || saved_dev))
49783 + gr_handle_delete(saved_ino, saved_dev);
49784 exit2:
49785 dput(dentry);
49786 }
49787 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49788 if (IS_ERR(dentry))
49789 goto out_putname;
49790
49791 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49792 + error = -EACCES;
49793 + goto out;
49794 + }
49795 +
49796 error = security_path_symlink(&path, dentry, from->name);
49797 if (!error)
49798 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49799 + if (!error)
49800 + gr_handle_create(dentry, path.mnt);
49801 +out:
49802 done_path_create(&path, dentry);
49803 out_putname:
49804 putname(from);
49805 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49806 {
49807 struct dentry *new_dentry;
49808 struct path old_path, new_path;
49809 + struct filename *to = NULL;
49810 int how = 0;
49811 int error;
49812
49813 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49814 if (error)
49815 return error;
49816
49817 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49818 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49819 error = PTR_ERR(new_dentry);
49820 if (IS_ERR(new_dentry))
49821 goto out;
49822 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49823 error = may_linkat(&old_path);
49824 if (unlikely(error))
49825 goto out_dput;
49826 +
49827 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49828 + old_path.dentry->d_inode,
49829 + old_path.dentry->d_inode->i_mode, to)) {
49830 + error = -EACCES;
49831 + goto out_dput;
49832 + }
49833 +
49834 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49835 + old_path.dentry, old_path.mnt, to)) {
49836 + error = -EACCES;
49837 + goto out_dput;
49838 + }
49839 +
49840 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49841 if (error)
49842 goto out_dput;
49843 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49844 + if (!error)
49845 + gr_handle_create(new_dentry, new_path.mnt);
49846 out_dput:
49847 + putname(to);
49848 done_path_create(&new_path, new_dentry);
49849 out:
49850 path_put(&old_path);
49851 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49852 if (new_dentry == trap)
49853 goto exit5;
49854
49855 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49856 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
49857 + to);
49858 + if (error)
49859 + goto exit5;
49860 +
49861 error = security_path_rename(&oldnd.path, old_dentry,
49862 &newnd.path, new_dentry);
49863 if (error)
49864 goto exit5;
49865 error = vfs_rename(old_dir->d_inode, old_dentry,
49866 new_dir->d_inode, new_dentry);
49867 + if (!error)
49868 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49869 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49870 exit5:
49871 dput(new_dentry);
49872 exit4:
49873 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49874
49875 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49876 {
49877 + char tmpbuf[64];
49878 + const char *newlink;
49879 int len;
49880
49881 len = PTR_ERR(link);
49882 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49883 len = strlen(link);
49884 if (len > (unsigned) buflen)
49885 len = buflen;
49886 - if (copy_to_user(buffer, link, len))
49887 +
49888 + if (len < sizeof(tmpbuf)) {
49889 + memcpy(tmpbuf, link, len);
49890 + newlink = tmpbuf;
49891 + } else
49892 + newlink = link;
49893 +
49894 + if (copy_to_user(buffer, newlink, len))
49895 len = -EFAULT;
49896 out:
49897 return len;
49898 diff --git a/fs/namespace.c b/fs/namespace.c
49899 index 2496062..e26f6d6 100644
49900 --- a/fs/namespace.c
49901 +++ b/fs/namespace.c
49902 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
49903 if (!(sb->s_flags & MS_RDONLY))
49904 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
49905 up_write(&sb->s_umount);
49906 +
49907 + gr_log_remount(mnt->mnt_devname, retval);
49908 +
49909 return retval;
49910 }
49911
49912 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
49913 br_write_unlock(&vfsmount_lock);
49914 up_write(&namespace_sem);
49915 release_mounts(&umount_list);
49916 +
49917 + gr_log_unmount(mnt->mnt_devname, retval);
49918 +
49919 return retval;
49920 }
49921
49922 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
49923 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
49924 MS_STRICTATIME);
49925
49926 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
49927 + retval = -EPERM;
49928 + goto dput_out;
49929 + }
49930 +
49931 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
49932 + retval = -EPERM;
49933 + goto dput_out;
49934 + }
49935 +
49936 if (flags & MS_REMOUNT)
49937 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
49938 data_page);
49939 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
49940 dev_name, data_page);
49941 dput_out:
49942 path_put(&path);
49943 +
49944 + gr_log_mount(dev_name, dir_name, retval);
49945 +
49946 return retval;
49947 }
49948
49949 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
49950 if (error)
49951 goto out2;
49952
49953 + if (gr_handle_chroot_pivot()) {
49954 + error = -EPERM;
49955 + goto out2;
49956 + }
49957 +
49958 get_fs_root(current->fs, &root);
49959 error = lock_mount(&old);
49960 if (error)
49961 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
49962 index 6fa01ae..2790820 100644
49963 --- a/fs/nfs/inode.c
49964 +++ b/fs/nfs/inode.c
49965 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
49966 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
49967 }
49968
49969 -static atomic_long_t nfs_attr_generation_counter;
49970 +static atomic_long_unchecked_t nfs_attr_generation_counter;
49971
49972 static unsigned long nfs_read_attr_generation_counter(void)
49973 {
49974 - return atomic_long_read(&nfs_attr_generation_counter);
49975 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
49976 }
49977
49978 unsigned long nfs_inc_attr_generation_counter(void)
49979 {
49980 - return atomic_long_inc_return(&nfs_attr_generation_counter);
49981 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
49982 }
49983
49984 void nfs_fattr_init(struct nfs_fattr *fattr)
49985 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
49986 index f59169e..fd7d359 100644
49987 --- a/fs/nfsd/vfs.c
49988 +++ b/fs/nfsd/vfs.c
49989 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49990 } else {
49991 oldfs = get_fs();
49992 set_fs(KERNEL_DS);
49993 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
49994 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
49995 set_fs(oldfs);
49996 }
49997
49998 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49999
50000 /* Write the data. */
50001 oldfs = get_fs(); set_fs(KERNEL_DS);
50002 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50003 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50004 set_fs(oldfs);
50005 if (host_err < 0)
50006 goto out_nfserr;
50007 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50008 */
50009
50010 oldfs = get_fs(); set_fs(KERNEL_DS);
50011 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50012 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50013 set_fs(oldfs);
50014
50015 if (host_err < 0)
50016 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50017 index 6fcaeb8..9d16d04 100644
50018 --- a/fs/notify/fanotify/fanotify_user.c
50019 +++ b/fs/notify/fanotify/fanotify_user.c
50020 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50021
50022 fd = fanotify_event_metadata.fd;
50023 ret = -EFAULT;
50024 - if (copy_to_user(buf, &fanotify_event_metadata,
50025 - fanotify_event_metadata.event_len))
50026 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50027 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50028 goto out_close_fd;
50029
50030 ret = prepare_for_access_response(group, event, fd);
50031 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50032 index c887b13..0fdf472 100644
50033 --- a/fs/notify/notification.c
50034 +++ b/fs/notify/notification.c
50035 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50036 * get set to 0 so it will never get 'freed'
50037 */
50038 static struct fsnotify_event *q_overflow_event;
50039 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50040 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50041
50042 /**
50043 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50044 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50045 */
50046 u32 fsnotify_get_cookie(void)
50047 {
50048 - return atomic_inc_return(&fsnotify_sync_cookie);
50049 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50050 }
50051 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50052
50053 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50054 index 99e3610..02c1068 100644
50055 --- a/fs/ntfs/dir.c
50056 +++ b/fs/ntfs/dir.c
50057 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
50058 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50059 ~(s64)(ndir->itype.index.block_size - 1)));
50060 /* Bounds checks. */
50061 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50062 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50063 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50064 "inode 0x%lx or driver bug.", vdir->i_ino);
50065 goto err_out;
50066 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50067 index 1ecf464..e1ff8bf 100644
50068 --- a/fs/ntfs/file.c
50069 +++ b/fs/ntfs/file.c
50070 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50071 #endif /* NTFS_RW */
50072 };
50073
50074 -const struct file_operations ntfs_empty_file_ops = {};
50075 +const struct file_operations ntfs_empty_file_ops __read_only;
50076
50077 -const struct inode_operations ntfs_empty_inode_ops = {};
50078 +const struct inode_operations ntfs_empty_inode_ops __read_only;
50079 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
50080 index a9f78c7..ed8a381 100644
50081 --- a/fs/ocfs2/localalloc.c
50082 +++ b/fs/ocfs2/localalloc.c
50083 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
50084 goto bail;
50085 }
50086
50087 - atomic_inc(&osb->alloc_stats.moves);
50088 + atomic_inc_unchecked(&osb->alloc_stats.moves);
50089
50090 bail:
50091 if (handle)
50092 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
50093 index d355e6e..578d905 100644
50094 --- a/fs/ocfs2/ocfs2.h
50095 +++ b/fs/ocfs2/ocfs2.h
50096 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
50097
50098 struct ocfs2_alloc_stats
50099 {
50100 - atomic_t moves;
50101 - atomic_t local_data;
50102 - atomic_t bitmap_data;
50103 - atomic_t bg_allocs;
50104 - atomic_t bg_extends;
50105 + atomic_unchecked_t moves;
50106 + atomic_unchecked_t local_data;
50107 + atomic_unchecked_t bitmap_data;
50108 + atomic_unchecked_t bg_allocs;
50109 + atomic_unchecked_t bg_extends;
50110 };
50111
50112 enum ocfs2_local_alloc_state
50113 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
50114 index f169da4..9112253 100644
50115 --- a/fs/ocfs2/suballoc.c
50116 +++ b/fs/ocfs2/suballoc.c
50117 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
50118 mlog_errno(status);
50119 goto bail;
50120 }
50121 - atomic_inc(&osb->alloc_stats.bg_extends);
50122 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
50123
50124 /* You should never ask for this much metadata */
50125 BUG_ON(bits_wanted >
50126 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
50127 mlog_errno(status);
50128 goto bail;
50129 }
50130 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50131 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50132
50133 *suballoc_loc = res.sr_bg_blkno;
50134 *suballoc_bit_start = res.sr_bit_offset;
50135 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50136 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50137 res->sr_bits);
50138
50139 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50140 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50141
50142 BUG_ON(res->sr_bits != 1);
50143
50144 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50145 mlog_errno(status);
50146 goto bail;
50147 }
50148 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50149 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50150
50151 BUG_ON(res.sr_bits != 1);
50152
50153 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50154 cluster_start,
50155 num_clusters);
50156 if (!status)
50157 - atomic_inc(&osb->alloc_stats.local_data);
50158 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
50159 } else {
50160 if (min_clusters > (osb->bitmap_cpg - 1)) {
50161 /* The only paths asking for contiguousness
50162 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50163 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50164 res.sr_bg_blkno,
50165 res.sr_bit_offset);
50166 - atomic_inc(&osb->alloc_stats.bitmap_data);
50167 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50168 *num_clusters = res.sr_bits;
50169 }
50170 }
50171 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50172 index 0e91ec2..f4b3fc6 100644
50173 --- a/fs/ocfs2/super.c
50174 +++ b/fs/ocfs2/super.c
50175 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50176 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50177 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50178 "Stats",
50179 - atomic_read(&osb->alloc_stats.bitmap_data),
50180 - atomic_read(&osb->alloc_stats.local_data),
50181 - atomic_read(&osb->alloc_stats.bg_allocs),
50182 - atomic_read(&osb->alloc_stats.moves),
50183 - atomic_read(&osb->alloc_stats.bg_extends));
50184 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50185 + atomic_read_unchecked(&osb->alloc_stats.local_data),
50186 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50187 + atomic_read_unchecked(&osb->alloc_stats.moves),
50188 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50189
50190 out += snprintf(buf + out, len - out,
50191 "%10s => State: %u Descriptor: %llu Size: %u bits "
50192 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50193 spin_lock_init(&osb->osb_xattr_lock);
50194 ocfs2_init_steal_slots(osb);
50195
50196 - atomic_set(&osb->alloc_stats.moves, 0);
50197 - atomic_set(&osb->alloc_stats.local_data, 0);
50198 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
50199 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
50200 - atomic_set(&osb->alloc_stats.bg_extends, 0);
50201 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50202 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50203 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50204 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50205 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50206
50207 /* Copy the blockcheck stats from the superblock probe */
50208 osb->osb_ecc_stats = *stats;
50209 diff --git a/fs/open.c b/fs/open.c
50210 index 59071f5..c6229a0 100644
50211 --- a/fs/open.c
50212 +++ b/fs/open.c
50213 @@ -31,6 +31,8 @@
50214 #include <linux/ima.h>
50215 #include <linux/dnotify.h>
50216
50217 +#define CREATE_TRACE_POINTS
50218 +#include <trace/events/fs.h>
50219 #include "internal.h"
50220
50221 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50222 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50223 error = locks_verify_truncate(inode, NULL, length);
50224 if (!error)
50225 error = security_path_truncate(&path);
50226 +
50227 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50228 + error = -EACCES;
50229 +
50230 if (!error)
50231 error = do_truncate(path.dentry, length, 0, NULL);
50232
50233 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50234 if (__mnt_is_readonly(path.mnt))
50235 res = -EROFS;
50236
50237 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50238 + res = -EACCES;
50239 +
50240 out_path_release:
50241 path_put(&path);
50242 out:
50243 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50244 if (error)
50245 goto dput_and_out;
50246
50247 + gr_log_chdir(path.dentry, path.mnt);
50248 +
50249 set_fs_pwd(current->fs, &path);
50250
50251 dput_and_out:
50252 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50253 goto out_putf;
50254
50255 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50256 +
50257 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50258 + error = -EPERM;
50259 +
50260 + if (!error)
50261 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50262 +
50263 if (!error)
50264 set_fs_pwd(current->fs, &f.file->f_path);
50265 out_putf:
50266 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50267 if (error)
50268 goto dput_and_out;
50269
50270 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50271 + goto dput_and_out;
50272 +
50273 set_fs_root(current->fs, &path);
50274 +
50275 + gr_handle_chroot_chdir(&path);
50276 +
50277 error = 0;
50278 dput_and_out:
50279 path_put(&path);
50280 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50281 if (error)
50282 return error;
50283 mutex_lock(&inode->i_mutex);
50284 +
50285 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50286 + error = -EACCES;
50287 + goto out_unlock;
50288 + }
50289 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50290 + error = -EACCES;
50291 + goto out_unlock;
50292 + }
50293 +
50294 error = security_path_chmod(path, mode);
50295 if (error)
50296 goto out_unlock;
50297 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50298 uid = make_kuid(current_user_ns(), user);
50299 gid = make_kgid(current_user_ns(), group);
50300
50301 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
50302 + return -EACCES;
50303 +
50304 newattrs.ia_valid = ATTR_CTIME;
50305 if (user != (uid_t) -1) {
50306 if (!uid_valid(uid))
50307 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50308 } else {
50309 fsnotify_open(f);
50310 fd_install(fd, f);
50311 + trace_do_sys_open(tmp->name, flags, mode);
50312 }
50313 }
50314 putname(tmp);
50315 diff --git a/fs/pipe.c b/fs/pipe.c
50316 index bd3479d..fb92c4d 100644
50317 --- a/fs/pipe.c
50318 +++ b/fs/pipe.c
50319 @@ -438,9 +438,9 @@ redo:
50320 }
50321 if (bufs) /* More to do? */
50322 continue;
50323 - if (!pipe->writers)
50324 + if (!atomic_read(&pipe->writers))
50325 break;
50326 - if (!pipe->waiting_writers) {
50327 + if (!atomic_read(&pipe->waiting_writers)) {
50328 /* syscall merging: Usually we must not sleep
50329 * if O_NONBLOCK is set, or if we got some data.
50330 * But if a writer sleeps in kernel space, then
50331 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50332 mutex_lock(&inode->i_mutex);
50333 pipe = inode->i_pipe;
50334
50335 - if (!pipe->readers) {
50336 + if (!atomic_read(&pipe->readers)) {
50337 send_sig(SIGPIPE, current, 0);
50338 ret = -EPIPE;
50339 goto out;
50340 @@ -553,7 +553,7 @@ redo1:
50341 for (;;) {
50342 int bufs;
50343
50344 - if (!pipe->readers) {
50345 + if (!atomic_read(&pipe->readers)) {
50346 send_sig(SIGPIPE, current, 0);
50347 if (!ret)
50348 ret = -EPIPE;
50349 @@ -644,9 +644,9 @@ redo2:
50350 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50351 do_wakeup = 0;
50352 }
50353 - pipe->waiting_writers++;
50354 + atomic_inc(&pipe->waiting_writers);
50355 pipe_wait(pipe);
50356 - pipe->waiting_writers--;
50357 + atomic_dec(&pipe->waiting_writers);
50358 }
50359 out:
50360 mutex_unlock(&inode->i_mutex);
50361 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50362 mask = 0;
50363 if (filp->f_mode & FMODE_READ) {
50364 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50365 - if (!pipe->writers && filp->f_version != pipe->w_counter)
50366 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50367 mask |= POLLHUP;
50368 }
50369
50370 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50371 * Most Unices do not set POLLERR for FIFOs but on Linux they
50372 * behave exactly like pipes for poll().
50373 */
50374 - if (!pipe->readers)
50375 + if (!atomic_read(&pipe->readers))
50376 mask |= POLLERR;
50377 }
50378
50379 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50380
50381 mutex_lock(&inode->i_mutex);
50382 pipe = inode->i_pipe;
50383 - pipe->readers -= decr;
50384 - pipe->writers -= decw;
50385 + atomic_sub(decr, &pipe->readers);
50386 + atomic_sub(decw, &pipe->writers);
50387
50388 - if (!pipe->readers && !pipe->writers) {
50389 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50390 free_pipe_info(inode);
50391 } else {
50392 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50393 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50394
50395 if (inode->i_pipe) {
50396 ret = 0;
50397 - inode->i_pipe->readers++;
50398 + atomic_inc(&inode->i_pipe->readers);
50399 }
50400
50401 mutex_unlock(&inode->i_mutex);
50402 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50403
50404 if (inode->i_pipe) {
50405 ret = 0;
50406 - inode->i_pipe->writers++;
50407 + atomic_inc(&inode->i_pipe->writers);
50408 }
50409
50410 mutex_unlock(&inode->i_mutex);
50411 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50412 if (inode->i_pipe) {
50413 ret = 0;
50414 if (filp->f_mode & FMODE_READ)
50415 - inode->i_pipe->readers++;
50416 + atomic_inc(&inode->i_pipe->readers);
50417 if (filp->f_mode & FMODE_WRITE)
50418 - inode->i_pipe->writers++;
50419 + atomic_inc(&inode->i_pipe->writers);
50420 }
50421
50422 mutex_unlock(&inode->i_mutex);
50423 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50424 inode->i_pipe = NULL;
50425 }
50426
50427 -static struct vfsmount *pipe_mnt __read_mostly;
50428 +struct vfsmount *pipe_mnt __read_mostly;
50429
50430 /*
50431 * pipefs_dname() is called from d_path().
50432 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50433 goto fail_iput;
50434 inode->i_pipe = pipe;
50435
50436 - pipe->readers = pipe->writers = 1;
50437 + atomic_set(&pipe->readers, 1);
50438 + atomic_set(&pipe->writers, 1);
50439 inode->i_fop = &rdwr_pipefifo_fops;
50440
50441 /*
50442 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50443 index 15af622..0e9f4467 100644
50444 --- a/fs/proc/Kconfig
50445 +++ b/fs/proc/Kconfig
50446 @@ -30,12 +30,12 @@ config PROC_FS
50447
50448 config PROC_KCORE
50449 bool "/proc/kcore support" if !ARM
50450 - depends on PROC_FS && MMU
50451 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50452
50453 config PROC_VMCORE
50454 bool "/proc/vmcore support"
50455 - depends on PROC_FS && CRASH_DUMP
50456 - default y
50457 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50458 + default n
50459 help
50460 Exports the dump image of crashed kernel in ELF format.
50461
50462 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50463 limited in memory.
50464
50465 config PROC_PAGE_MONITOR
50466 - default y
50467 - depends on PROC_FS && MMU
50468 + default n
50469 + depends on PROC_FS && MMU && !GRKERNSEC
50470 bool "Enable /proc page monitoring" if EXPERT
50471 help
50472 Various /proc files exist to monitor process memory utilization:
50473 diff --git a/fs/proc/array.c b/fs/proc/array.c
50474 index bd31e02..15cae71 100644
50475 --- a/fs/proc/array.c
50476 +++ b/fs/proc/array.c
50477 @@ -60,6 +60,7 @@
50478 #include <linux/tty.h>
50479 #include <linux/string.h>
50480 #include <linux/mman.h>
50481 +#include <linux/grsecurity.h>
50482 #include <linux/proc_fs.h>
50483 #include <linux/ioport.h>
50484 #include <linux/uaccess.h>
50485 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50486 seq_putc(m, '\n');
50487 }
50488
50489 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50490 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50491 +{
50492 + if (p->mm)
50493 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50494 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50495 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50496 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50497 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50498 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50499 + else
50500 + seq_printf(m, "PaX:\t-----\n");
50501 +}
50502 +#endif
50503 +
50504 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50505 struct pid *pid, struct task_struct *task)
50506 {
50507 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50508 task_cpus_allowed(m, task);
50509 cpuset_task_status_allowed(m, task);
50510 task_context_switch_counts(m, task);
50511 +
50512 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50513 + task_pax(m, task);
50514 +#endif
50515 +
50516 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50517 + task_grsec_rbac(m, task);
50518 +#endif
50519 +
50520 return 0;
50521 }
50522
50523 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50524 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50525 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50526 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50527 +#endif
50528 +
50529 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50530 struct pid *pid, struct task_struct *task, int whole)
50531 {
50532 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50533 char tcomm[sizeof(task->comm)];
50534 unsigned long flags;
50535
50536 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50537 + if (current->exec_id != m->exec_id) {
50538 + gr_log_badprocpid("stat");
50539 + return 0;
50540 + }
50541 +#endif
50542 +
50543 state = *get_task_state(task);
50544 vsize = eip = esp = 0;
50545 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50546 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50547 gtime = task->gtime;
50548 }
50549
50550 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50551 + if (PAX_RAND_FLAGS(mm)) {
50552 + eip = 0;
50553 + esp = 0;
50554 + wchan = 0;
50555 + }
50556 +#endif
50557 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50558 + wchan = 0;
50559 + eip =0;
50560 + esp =0;
50561 +#endif
50562 +
50563 /* scale priority and nice values from timeslices to -20..20 */
50564 /* to make it look like a "normal" Unix priority/nice value */
50565 priority = task_prio(task);
50566 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50567 seq_put_decimal_ull(m, ' ', vsize);
50568 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50569 seq_put_decimal_ull(m, ' ', rsslim);
50570 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50571 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50572 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50573 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50574 +#else
50575 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50576 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50577 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50578 +#endif
50579 seq_put_decimal_ull(m, ' ', esp);
50580 seq_put_decimal_ull(m, ' ', eip);
50581 /* The signal information here is obsolete.
50582 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50583 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50584 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50585
50586 - if (mm && permitted) {
50587 + if (mm && permitted
50588 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50589 + && !PAX_RAND_FLAGS(mm)
50590 +#endif
50591 + ) {
50592 seq_put_decimal_ull(m, ' ', mm->start_data);
50593 seq_put_decimal_ull(m, ' ', mm->end_data);
50594 seq_put_decimal_ull(m, ' ', mm->start_brk);
50595 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50596 struct pid *pid, struct task_struct *task)
50597 {
50598 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50599 - struct mm_struct *mm = get_task_mm(task);
50600 + struct mm_struct *mm;
50601
50602 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50603 + if (current->exec_id != m->exec_id) {
50604 + gr_log_badprocpid("statm");
50605 + return 0;
50606 + }
50607 +#endif
50608 + mm = get_task_mm(task);
50609 if (mm) {
50610 size = task_statm(mm, &shared, &text, &data, &resident);
50611 mmput(mm);
50612 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50613 return 0;
50614 }
50615
50616 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50617 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50618 +{
50619 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50620 +}
50621 +#endif
50622 +
50623 #ifdef CONFIG_CHECKPOINT_RESTORE
50624 static struct pid *
50625 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50626 diff --git a/fs/proc/base.c b/fs/proc/base.c
50627 index 9e28356..c485b3c 100644
50628 --- a/fs/proc/base.c
50629 +++ b/fs/proc/base.c
50630 @@ -111,6 +111,14 @@ struct pid_entry {
50631 union proc_op op;
50632 };
50633
50634 +struct getdents_callback {
50635 + struct linux_dirent __user * current_dir;
50636 + struct linux_dirent __user * previous;
50637 + struct file * file;
50638 + int count;
50639 + int error;
50640 +};
50641 +
50642 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50643 .name = (NAME), \
50644 .len = sizeof(NAME) - 1, \
50645 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50646 if (!mm->arg_end)
50647 goto out_mm; /* Shh! No looking before we're done */
50648
50649 + if (gr_acl_handle_procpidmem(task))
50650 + goto out_mm;
50651 +
50652 len = mm->arg_end - mm->arg_start;
50653
50654 if (len > PAGE_SIZE)
50655 @@ -235,12 +246,28 @@ out:
50656 return res;
50657 }
50658
50659 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50660 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50661 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50662 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50663 +#endif
50664 +
50665 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50666 {
50667 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50668 int res = PTR_ERR(mm);
50669 if (mm && !IS_ERR(mm)) {
50670 unsigned int nwords = 0;
50671 +
50672 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50673 + /* allow if we're currently ptracing this task */
50674 + if (PAX_RAND_FLAGS(mm) &&
50675 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50676 + mmput(mm);
50677 + return 0;
50678 + }
50679 +#endif
50680 +
50681 do {
50682 nwords += 2;
50683 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50684 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50685 }
50686
50687
50688 -#ifdef CONFIG_KALLSYMS
50689 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50690 /*
50691 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50692 * Returns the resolved symbol. If that fails, simply return the address.
50693 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50694 mutex_unlock(&task->signal->cred_guard_mutex);
50695 }
50696
50697 -#ifdef CONFIG_STACKTRACE
50698 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50699
50700 #define MAX_STACK_TRACE_DEPTH 64
50701
50702 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50703 return count;
50704 }
50705
50706 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50707 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50708 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50709 {
50710 long nr;
50711 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50712 /************************************************************************/
50713
50714 /* permission checks */
50715 -static int proc_fd_access_allowed(struct inode *inode)
50716 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50717 {
50718 struct task_struct *task;
50719 int allowed = 0;
50720 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50721 */
50722 task = get_proc_task(inode);
50723 if (task) {
50724 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50725 + if (log)
50726 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50727 + else
50728 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50729 put_task_struct(task);
50730 }
50731 return allowed;
50732 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50733 struct task_struct *task,
50734 int hide_pid_min)
50735 {
50736 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50737 + return false;
50738 +
50739 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50740 + rcu_read_lock();
50741 + {
50742 + const struct cred *tmpcred = current_cred();
50743 + const struct cred *cred = __task_cred(task);
50744 +
50745 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50746 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50747 + || in_group_p(grsec_proc_gid)
50748 +#endif
50749 + ) {
50750 + rcu_read_unlock();
50751 + return true;
50752 + }
50753 + }
50754 + rcu_read_unlock();
50755 +
50756 + if (!pid->hide_pid)
50757 + return false;
50758 +#endif
50759 +
50760 if (pid->hide_pid < hide_pid_min)
50761 return true;
50762 if (in_group_p(pid->pid_gid))
50763 return true;
50764 +
50765 return ptrace_may_access(task, PTRACE_MODE_READ);
50766 }
50767
50768 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50769 put_task_struct(task);
50770
50771 if (!has_perms) {
50772 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50773 + {
50774 +#else
50775 if (pid->hide_pid == 2) {
50776 +#endif
50777 /*
50778 * Let's make getdents(), stat(), and open()
50779 * consistent with each other. If a process
50780 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50781 if (!task)
50782 return -ESRCH;
50783
50784 + if (gr_acl_handle_procpidmem(task)) {
50785 + put_task_struct(task);
50786 + return -EPERM;
50787 + }
50788 +
50789 mm = mm_access(task, mode);
50790 put_task_struct(task);
50791
50792 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50793
50794 file->private_data = mm;
50795
50796 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50797 + file->f_version = current->exec_id;
50798 +#endif
50799 +
50800 return 0;
50801 }
50802
50803 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50804 ssize_t copied;
50805 char *page;
50806
50807 +#ifdef CONFIG_GRKERNSEC
50808 + if (write)
50809 + return -EPERM;
50810 +#endif
50811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50812 + if (file->f_version != current->exec_id) {
50813 + gr_log_badprocpid("mem");
50814 + return 0;
50815 + }
50816 +#endif
50817 +
50818 if (!mm)
50819 return 0;
50820
50821 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50822 if (!mm)
50823 return 0;
50824
50825 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50826 + if (file->f_version != current->exec_id) {
50827 + gr_log_badprocpid("environ");
50828 + return 0;
50829 + }
50830 +#endif
50831 +
50832 page = (char *)__get_free_page(GFP_TEMPORARY);
50833 if (!page)
50834 return -ENOMEM;
50835 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50836 int error = -EACCES;
50837
50838 /* Are we allowed to snoop on the tasks file descriptors? */
50839 - if (!proc_fd_access_allowed(inode))
50840 + if (!proc_fd_access_allowed(inode, 0))
50841 goto out;
50842
50843 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50844 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50845 struct path path;
50846
50847 /* Are we allowed to snoop on the tasks file descriptors? */
50848 - if (!proc_fd_access_allowed(inode))
50849 - goto out;
50850 + /* logging this is needed for learning on chromium to work properly,
50851 + but we don't want to flood the logs from 'ps' which does a readlink
50852 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50853 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
50854 + */
50855 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50856 + if (!proc_fd_access_allowed(inode,0))
50857 + goto out;
50858 + } else {
50859 + if (!proc_fd_access_allowed(inode,1))
50860 + goto out;
50861 + }
50862
50863 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50864 if (error)
50865 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50866 rcu_read_lock();
50867 cred = __task_cred(task);
50868 inode->i_uid = cred->euid;
50869 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50870 + inode->i_gid = grsec_proc_gid;
50871 +#else
50872 inode->i_gid = cred->egid;
50873 +#endif
50874 rcu_read_unlock();
50875 }
50876 security_task_to_inode(task, inode);
50877 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50878 return -ENOENT;
50879 }
50880 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50881 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50882 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50883 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50884 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50885 +#endif
50886 task_dumpable(task)) {
50887 cred = __task_cred(task);
50888 stat->uid = cred->euid;
50889 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50890 + stat->gid = grsec_proc_gid;
50891 +#else
50892 stat->gid = cred->egid;
50893 +#endif
50894 }
50895 }
50896 rcu_read_unlock();
50897 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
50898
50899 if (task) {
50900 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50901 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50902 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50903 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50904 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50905 +#endif
50906 task_dumpable(task)) {
50907 rcu_read_lock();
50908 cred = __task_cred(task);
50909 inode->i_uid = cred->euid;
50910 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50911 + inode->i_gid = grsec_proc_gid;
50912 +#else
50913 inode->i_gid = cred->egid;
50914 +#endif
50915 rcu_read_unlock();
50916 } else {
50917 inode->i_uid = GLOBAL_ROOT_UID;
50918 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
50919 if (!task)
50920 goto out_no_task;
50921
50922 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50923 + goto out;
50924 +
50925 /*
50926 * Yes, it does not scale. And it should not. Don't add
50927 * new entries into /proc/<tgid>/ without very good reasons.
50928 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
50929 if (!task)
50930 goto out_no_task;
50931
50932 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50933 + goto out;
50934 +
50935 ret = 0;
50936 i = filp->f_pos;
50937 switch (i) {
50938 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
50939 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
50940 void *cookie)
50941 {
50942 - char *s = nd_get_link(nd);
50943 + const char *s = nd_get_link(nd);
50944 if (!IS_ERR(s))
50945 kfree(s);
50946 }
50947 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
50948 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
50949 #endif
50950 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50951 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50952 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50953 INF("syscall", S_IRUGO, proc_pid_syscall),
50954 #endif
50955 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50956 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
50957 #ifdef CONFIG_SECURITY
50958 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50959 #endif
50960 -#ifdef CONFIG_KALLSYMS
50961 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50962 INF("wchan", S_IRUGO, proc_pid_wchan),
50963 #endif
50964 -#ifdef CONFIG_STACKTRACE
50965 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50966 ONE("stack", S_IRUGO, proc_pid_stack),
50967 #endif
50968 #ifdef CONFIG_SCHEDSTATS
50969 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
50970 #ifdef CONFIG_HARDWALL
50971 INF("hardwall", S_IRUGO, proc_pid_hardwall),
50972 #endif
50973 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50974 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
50975 +#endif
50976 #ifdef CONFIG_USER_NS
50977 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
50978 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
50979 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
50980 if (!inode)
50981 goto out;
50982
50983 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50984 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
50985 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50986 + inode->i_gid = grsec_proc_gid;
50987 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
50988 +#else
50989 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
50990 +#endif
50991 inode->i_op = &proc_tgid_base_inode_operations;
50992 inode->i_fop = &proc_tgid_base_operations;
50993 inode->i_flags|=S_IMMUTABLE;
50994 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
50995 if (!task)
50996 goto out;
50997
50998 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50999 + goto out_put_task;
51000 +
51001 result = proc_pid_instantiate(dir, dentry, task, NULL);
51002 +out_put_task:
51003 put_task_struct(task);
51004 out:
51005 return result;
51006 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51007 static int fake_filldir(void *buf, const char *name, int namelen,
51008 loff_t offset, u64 ino, unsigned d_type)
51009 {
51010 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
51011 + __buf->error = -EINVAL;
51012 return 0;
51013 }
51014
51015 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
51016 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51017 #endif
51018 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51019 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51020 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51021 INF("syscall", S_IRUGO, proc_pid_syscall),
51022 #endif
51023 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51024 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
51025 #ifdef CONFIG_SECURITY
51026 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51027 #endif
51028 -#ifdef CONFIG_KALLSYMS
51029 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51030 INF("wchan", S_IRUGO, proc_pid_wchan),
51031 #endif
51032 -#ifdef CONFIG_STACKTRACE
51033 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51034 ONE("stack", S_IRUGO, proc_pid_stack),
51035 #endif
51036 #ifdef CONFIG_SCHEDSTATS
51037 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51038 index 82676e3..5f8518a 100644
51039 --- a/fs/proc/cmdline.c
51040 +++ b/fs/proc/cmdline.c
51041 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51042
51043 static int __init proc_cmdline_init(void)
51044 {
51045 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51046 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51047 +#else
51048 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51049 +#endif
51050 return 0;
51051 }
51052 module_init(proc_cmdline_init);
51053 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51054 index b143471..bb105e5 100644
51055 --- a/fs/proc/devices.c
51056 +++ b/fs/proc/devices.c
51057 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51058
51059 static int __init proc_devices_init(void)
51060 {
51061 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51062 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51063 +#else
51064 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51065 +#endif
51066 return 0;
51067 }
51068 module_init(proc_devices_init);
51069 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51070 index f28a875..c467953 100644
51071 --- a/fs/proc/fd.c
51072 +++ b/fs/proc/fd.c
51073 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51074 if (!task)
51075 return -ENOENT;
51076
51077 - files = get_files_struct(task);
51078 + if (!gr_acl_handle_procpidmem(task))
51079 + files = get_files_struct(task);
51080 put_task_struct(task);
51081
51082 if (files) {
51083 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
51084 */
51085 int proc_fd_permission(struct inode *inode, int mask)
51086 {
51087 + struct task_struct *task;
51088 int rv = generic_permission(inode, mask);
51089 - if (rv == 0)
51090 - return 0;
51091 +
51092 if (task_pid(current) == proc_pid(inode))
51093 rv = 0;
51094 +
51095 + task = get_proc_task(inode);
51096 + if (task == NULL)
51097 + return rv;
51098 +
51099 + if (gr_acl_handle_procpidmem(task))
51100 + rv = -EACCES;
51101 +
51102 + put_task_struct(task);
51103 +
51104 return rv;
51105 }
51106
51107 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
51108 index 3b22bbd..895b58c 100644
51109 --- a/fs/proc/inode.c
51110 +++ b/fs/proc/inode.c
51111 @@ -21,11 +21,17 @@
51112 #include <linux/seq_file.h>
51113 #include <linux/slab.h>
51114 #include <linux/mount.h>
51115 +#include <linux/grsecurity.h>
51116
51117 #include <asm/uaccess.h>
51118
51119 #include "internal.h"
51120
51121 +#ifdef CONFIG_PROC_SYSCTL
51122 +extern const struct inode_operations proc_sys_inode_operations;
51123 +extern const struct inode_operations proc_sys_dir_operations;
51124 +#endif
51125 +
51126 static void proc_evict_inode(struct inode *inode)
51127 {
51128 struct proc_dir_entry *de;
51129 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
51130 ns_ops = PROC_I(inode)->ns_ops;
51131 if (ns_ops && ns_ops->put)
51132 ns_ops->put(PROC_I(inode)->ns);
51133 +
51134 +#ifdef CONFIG_PROC_SYSCTL
51135 + if (inode->i_op == &proc_sys_inode_operations ||
51136 + inode->i_op == &proc_sys_dir_operations)
51137 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51138 +#endif
51139 +
51140 }
51141
51142 static struct kmem_cache * proc_inode_cachep;
51143 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51144 if (de->mode) {
51145 inode->i_mode = de->mode;
51146 inode->i_uid = de->uid;
51147 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51148 + inode->i_gid = grsec_proc_gid;
51149 +#else
51150 inode->i_gid = de->gid;
51151 +#endif
51152 }
51153 if (de->size)
51154 inode->i_size = de->size;
51155 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51156 index 43973b0..a20e704 100644
51157 --- a/fs/proc/internal.h
51158 +++ b/fs/proc/internal.h
51159 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51160 struct pid *pid, struct task_struct *task);
51161 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51162 struct pid *pid, struct task_struct *task);
51163 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51164 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51165 +#endif
51166 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51167
51168 extern const struct file_operations proc_tid_children_operations;
51169 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51170 index 86c67ee..cdca321 100644
51171 --- a/fs/proc/kcore.c
51172 +++ b/fs/proc/kcore.c
51173 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51174 * the addresses in the elf_phdr on our list.
51175 */
51176 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51177 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51178 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51179 + if (tsz > buflen)
51180 tsz = buflen;
51181 -
51182 +
51183 while (buflen) {
51184 struct kcore_list *m;
51185
51186 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51187 kfree(elf_buf);
51188 } else {
51189 if (kern_addr_valid(start)) {
51190 - unsigned long n;
51191 + char *elf_buf;
51192 + mm_segment_t oldfs;
51193
51194 - n = copy_to_user(buffer, (char *)start, tsz);
51195 - /*
51196 - * We cannot distinguish between fault on source
51197 - * and fault on destination. When this happens
51198 - * we clear too and hope it will trigger the
51199 - * EFAULT again.
51200 - */
51201 - if (n) {
51202 - if (clear_user(buffer + tsz - n,
51203 - n))
51204 + elf_buf = kmalloc(tsz, GFP_KERNEL);
51205 + if (!elf_buf)
51206 + return -ENOMEM;
51207 + oldfs = get_fs();
51208 + set_fs(KERNEL_DS);
51209 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51210 + set_fs(oldfs);
51211 + if (copy_to_user(buffer, elf_buf, tsz)) {
51212 + kfree(elf_buf);
51213 return -EFAULT;
51214 + }
51215 }
51216 + set_fs(oldfs);
51217 + kfree(elf_buf);
51218 } else {
51219 if (clear_user(buffer, tsz))
51220 return -EFAULT;
51221 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51222
51223 static int open_kcore(struct inode *inode, struct file *filp)
51224 {
51225 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51226 + return -EPERM;
51227 +#endif
51228 if (!capable(CAP_SYS_RAWIO))
51229 return -EPERM;
51230 if (kcore_need_update)
51231 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51232 index 80e4645..53e5fcf 100644
51233 --- a/fs/proc/meminfo.c
51234 +++ b/fs/proc/meminfo.c
51235 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51236 vmi.used >> 10,
51237 vmi.largest_chunk >> 10
51238 #ifdef CONFIG_MEMORY_FAILURE
51239 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51240 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51241 #endif
51242 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51243 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51244 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51245 index b1822dd..df622cb 100644
51246 --- a/fs/proc/nommu.c
51247 +++ b/fs/proc/nommu.c
51248 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51249 if (len < 1)
51250 len = 1;
51251 seq_printf(m, "%*c", len, ' ');
51252 - seq_path(m, &file->f_path, "");
51253 + seq_path(m, &file->f_path, "\n\\");
51254 }
51255
51256 seq_putc(m, '\n');
51257 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51258 index fe72cd0..cb9b67d 100644
51259 --- a/fs/proc/proc_net.c
51260 +++ b/fs/proc/proc_net.c
51261 @@ -23,6 +23,7 @@
51262 #include <linux/nsproxy.h>
51263 #include <net/net_namespace.h>
51264 #include <linux/seq_file.h>
51265 +#include <linux/grsecurity.h>
51266
51267 #include "internal.h"
51268
51269 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51270 struct task_struct *task;
51271 struct nsproxy *ns;
51272 struct net *net = NULL;
51273 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51274 + const struct cred *cred = current_cred();
51275 +#endif
51276 +
51277 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51278 + if (cred->fsuid)
51279 + return net;
51280 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51281 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
51282 + return net;
51283 +#endif
51284
51285 rcu_read_lock();
51286 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51287 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51288 index a781bdf..6665284 100644
51289 --- a/fs/proc/proc_sysctl.c
51290 +++ b/fs/proc/proc_sysctl.c
51291 @@ -12,11 +12,15 @@
51292 #include <linux/module.h>
51293 #include "internal.h"
51294
51295 +extern int gr_handle_chroot_sysctl(const int op);
51296 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51297 + const int op);
51298 +
51299 static const struct dentry_operations proc_sys_dentry_operations;
51300 static const struct file_operations proc_sys_file_operations;
51301 -static const struct inode_operations proc_sys_inode_operations;
51302 +const struct inode_operations proc_sys_inode_operations;
51303 static const struct file_operations proc_sys_dir_file_operations;
51304 -static const struct inode_operations proc_sys_dir_operations;
51305 +const struct inode_operations proc_sys_dir_operations;
51306
51307 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51308 {
51309 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51310
51311 err = NULL;
51312 d_set_d_op(dentry, &proc_sys_dentry_operations);
51313 +
51314 + gr_handle_proc_create(dentry, inode);
51315 +
51316 d_add(dentry, inode);
51317
51318 out:
51319 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51320 struct inode *inode = filp->f_path.dentry->d_inode;
51321 struct ctl_table_header *head = grab_header(inode);
51322 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51323 + int op = write ? MAY_WRITE : MAY_READ;
51324 ssize_t error;
51325 size_t res;
51326
51327 if (IS_ERR(head))
51328 return PTR_ERR(head);
51329
51330 +
51331 /*
51332 * At this point we know that the sysctl was not unregistered
51333 * and won't be until we finish.
51334 */
51335 error = -EPERM;
51336 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51337 + if (sysctl_perm(head->root, table, op))
51338 goto out;
51339
51340 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51341 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51342 if (!table->proc_handler)
51343 goto out;
51344
51345 +#ifdef CONFIG_GRKERNSEC
51346 + error = -EPERM;
51347 + if (gr_handle_chroot_sysctl(op))
51348 + goto out;
51349 + dget(filp->f_path.dentry);
51350 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51351 + dput(filp->f_path.dentry);
51352 + goto out;
51353 + }
51354 + dput(filp->f_path.dentry);
51355 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51356 + goto out;
51357 + if (write && !capable(CAP_SYS_ADMIN))
51358 + goto out;
51359 +#endif
51360 +
51361 /* careful: calling conventions are nasty here */
51362 res = count;
51363 error = table->proc_handler(table, write, buf, &res, ppos);
51364 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51365 return -ENOMEM;
51366 } else {
51367 d_set_d_op(child, &proc_sys_dentry_operations);
51368 +
51369 + gr_handle_proc_create(child, inode);
51370 +
51371 d_add(child, inode);
51372 }
51373 } else {
51374 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51375 if ((*pos)++ < file->f_pos)
51376 return 0;
51377
51378 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51379 + return 0;
51380 +
51381 if (unlikely(S_ISLNK(table->mode)))
51382 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51383 else
51384 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51385 if (IS_ERR(head))
51386 return PTR_ERR(head);
51387
51388 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51389 + return -ENOENT;
51390 +
51391 generic_fillattr(inode, stat);
51392 if (table)
51393 stat->mode = (stat->mode & S_IFMT) | table->mode;
51394 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51395 .llseek = generic_file_llseek,
51396 };
51397
51398 -static const struct inode_operations proc_sys_inode_operations = {
51399 +const struct inode_operations proc_sys_inode_operations = {
51400 .permission = proc_sys_permission,
51401 .setattr = proc_sys_setattr,
51402 .getattr = proc_sys_getattr,
51403 };
51404
51405 -static const struct inode_operations proc_sys_dir_operations = {
51406 +const struct inode_operations proc_sys_dir_operations = {
51407 .lookup = proc_sys_lookup,
51408 .permission = proc_sys_permission,
51409 .setattr = proc_sys_setattr,
51410 diff --git a/fs/proc/root.c b/fs/proc/root.c
51411 index 9889a92..2613b48 100644
51412 --- a/fs/proc/root.c
51413 +++ b/fs/proc/root.c
51414 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
51415 #ifdef CONFIG_PROC_DEVICETREE
51416 proc_device_tree_init();
51417 #endif
51418 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51419 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51420 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51421 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51422 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51423 +#endif
51424 +#else
51425 proc_mkdir("bus", NULL);
51426 +#endif
51427 proc_sys_init();
51428 }
51429
51430 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51431 index 90c63f9..e662cfc 100644
51432 --- a/fs/proc/task_mmu.c
51433 +++ b/fs/proc/task_mmu.c
51434 @@ -11,12 +11,19 @@
51435 #include <linux/rmap.h>
51436 #include <linux/swap.h>
51437 #include <linux/swapops.h>
51438 +#include <linux/grsecurity.h>
51439
51440 #include <asm/elf.h>
51441 #include <asm/uaccess.h>
51442 #include <asm/tlbflush.h>
51443 #include "internal.h"
51444
51445 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51446 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51447 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51448 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51449 +#endif
51450 +
51451 void task_mem(struct seq_file *m, struct mm_struct *mm)
51452 {
51453 unsigned long data, text, lib, swap;
51454 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51455 "VmExe:\t%8lu kB\n"
51456 "VmLib:\t%8lu kB\n"
51457 "VmPTE:\t%8lu kB\n"
51458 - "VmSwap:\t%8lu kB\n",
51459 - hiwater_vm << (PAGE_SHIFT-10),
51460 + "VmSwap:\t%8lu kB\n"
51461 +
51462 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51463 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51464 +#endif
51465 +
51466 + ,hiwater_vm << (PAGE_SHIFT-10),
51467 total_vm << (PAGE_SHIFT-10),
51468 mm->locked_vm << (PAGE_SHIFT-10),
51469 mm->pinned_vm << (PAGE_SHIFT-10),
51470 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51471 data << (PAGE_SHIFT-10),
51472 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51473 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51474 - swap << (PAGE_SHIFT-10));
51475 + swap << (PAGE_SHIFT-10)
51476 +
51477 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51478 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51479 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51480 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51481 +#else
51482 + , mm->context.user_cs_base
51483 + , mm->context.user_cs_limit
51484 +#endif
51485 +#endif
51486 +
51487 + );
51488 }
51489
51490 unsigned long task_vsize(struct mm_struct *mm)
51491 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51492 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51493 }
51494
51495 - /* We don't show the stack guard page in /proc/maps */
51496 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51497 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51498 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51499 +#else
51500 start = vma->vm_start;
51501 - if (stack_guard_page_start(vma, start))
51502 - start += PAGE_SIZE;
51503 end = vma->vm_end;
51504 - if (stack_guard_page_end(vma, end))
51505 - end -= PAGE_SIZE;
51506 +#endif
51507
51508 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51509 start,
51510 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51511 flags & VM_WRITE ? 'w' : '-',
51512 flags & VM_EXEC ? 'x' : '-',
51513 flags & VM_MAYSHARE ? 's' : 'p',
51514 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51515 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51516 +#else
51517 pgoff,
51518 +#endif
51519 MAJOR(dev), MINOR(dev), ino, &len);
51520
51521 /*
51522 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51523 */
51524 if (file) {
51525 pad_len_spaces(m, len);
51526 - seq_path(m, &file->f_path, "\n");
51527 + seq_path(m, &file->f_path, "\n\\");
51528 goto done;
51529 }
51530
51531 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51532 * Thread stack in /proc/PID/task/TID/maps or
51533 * the main process stack.
51534 */
51535 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51536 - vma->vm_end >= mm->start_stack)) {
51537 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51538 + (vma->vm_start <= mm->start_stack &&
51539 + vma->vm_end >= mm->start_stack)) {
51540 name = "[stack]";
51541 } else {
51542 /* Thread stack in /proc/PID/maps */
51543 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51544 struct proc_maps_private *priv = m->private;
51545 struct task_struct *task = priv->task;
51546
51547 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51548 + if (current->exec_id != m->exec_id) {
51549 + gr_log_badprocpid("maps");
51550 + return 0;
51551 + }
51552 +#endif
51553 +
51554 show_map_vma(m, vma, is_pid);
51555
51556 if (m->count < m->size) /* vma is copied successfully */
51557 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51558 .private = &mss,
51559 };
51560
51561 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51562 + if (current->exec_id != m->exec_id) {
51563 + gr_log_badprocpid("smaps");
51564 + return 0;
51565 + }
51566 +#endif
51567 memset(&mss, 0, sizeof mss);
51568 - mss.vma = vma;
51569 - /* mmap_sem is held in m_start */
51570 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51571 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51572 -
51573 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51574 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51575 +#endif
51576 + mss.vma = vma;
51577 + /* mmap_sem is held in m_start */
51578 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51579 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51580 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51581 + }
51582 +#endif
51583 show_map_vma(m, vma, is_pid);
51584
51585 seq_printf(m,
51586 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51587 "KernelPageSize: %8lu kB\n"
51588 "MMUPageSize: %8lu kB\n"
51589 "Locked: %8lu kB\n",
51590 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51591 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51592 +#else
51593 (vma->vm_end - vma->vm_start) >> 10,
51594 +#endif
51595 mss.resident >> 10,
51596 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51597 mss.shared_clean >> 10,
51598 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51599 int n;
51600 char buffer[50];
51601
51602 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51603 + if (current->exec_id != m->exec_id) {
51604 + gr_log_badprocpid("numa_maps");
51605 + return 0;
51606 + }
51607 +#endif
51608 +
51609 if (!mm)
51610 return 0;
51611
51612 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51613 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51614 mpol_cond_put(pol);
51615
51616 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51617 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51618 +#else
51619 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51620 +#endif
51621
51622 if (file) {
51623 seq_printf(m, " file=");
51624 - seq_path(m, &file->f_path, "\n\t= ");
51625 + seq_path(m, &file->f_path, "\n\t\\= ");
51626 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51627 seq_printf(m, " heap");
51628 } else {
51629 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51630 index 1ccfa53..0848f95 100644
51631 --- a/fs/proc/task_nommu.c
51632 +++ b/fs/proc/task_nommu.c
51633 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51634 else
51635 bytes += kobjsize(mm);
51636
51637 - if (current->fs && current->fs->users > 1)
51638 + if (current->fs && atomic_read(&current->fs->users) > 1)
51639 sbytes += kobjsize(current->fs);
51640 else
51641 bytes += kobjsize(current->fs);
51642 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51643
51644 if (file) {
51645 pad_len_spaces(m, len);
51646 - seq_path(m, &file->f_path, "");
51647 + seq_path(m, &file->f_path, "\n\\");
51648 } else if (mm) {
51649 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51650
51651 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51652 index 2d57e1a..43b1280 100644
51653 --- a/fs/pstore/ftrace.c
51654 +++ b/fs/pstore/ftrace.c
51655 @@ -28,7 +28,9 @@
51656 #include "internal.h"
51657
51658 static void notrace pstore_ftrace_call(unsigned long ip,
51659 - unsigned long parent_ip)
51660 + unsigned long parent_ip,
51661 + struct ftrace_ops *op,
51662 + struct pt_regs *regs)
51663 {
51664 unsigned long flags;
51665 struct pstore_ftrace_record rec = {};
51666 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51667 index 16e8abb..2dcf914 100644
51668 --- a/fs/quota/netlink.c
51669 +++ b/fs/quota/netlink.c
51670 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51671 void quota_send_warning(struct kqid qid, dev_t dev,
51672 const char warntype)
51673 {
51674 - static atomic_t seq;
51675 + static atomic_unchecked_t seq;
51676 struct sk_buff *skb;
51677 void *msg_head;
51678 int ret;
51679 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51680 "VFS: Not enough memory to send quota warning.\n");
51681 return;
51682 }
51683 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51684 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51685 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51686 if (!msg_head) {
51687 printk(KERN_ERR
51688 diff --git a/fs/read_write.c b/fs/read_write.c
51689 index d065348..8e2b43d 100644
51690 --- a/fs/read_write.c
51691 +++ b/fs/read_write.c
51692 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51693 if (retval > 0) {
51694 add_rchar(current, retval);
51695 add_wchar(current, retval);
51696 + fsnotify_access(in.file);
51697 + fsnotify_modify(out.file);
51698 }
51699
51700 inc_syscr(current);
51701 diff --git a/fs/readdir.c b/fs/readdir.c
51702 index 5e69ef5..e5d9099 100644
51703 --- a/fs/readdir.c
51704 +++ b/fs/readdir.c
51705 @@ -17,6 +17,7 @@
51706 #include <linux/security.h>
51707 #include <linux/syscalls.h>
51708 #include <linux/unistd.h>
51709 +#include <linux/namei.h>
51710
51711 #include <asm/uaccess.h>
51712
51713 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51714
51715 struct readdir_callback {
51716 struct old_linux_dirent __user * dirent;
51717 + struct file * file;
51718 int result;
51719 };
51720
51721 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51722 buf->result = -EOVERFLOW;
51723 return -EOVERFLOW;
51724 }
51725 +
51726 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51727 + return 0;
51728 +
51729 buf->result++;
51730 dirent = buf->dirent;
51731 if (!access_ok(VERIFY_WRITE, dirent,
51732 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51733
51734 buf.result = 0;
51735 buf.dirent = dirent;
51736 + buf.file = f.file;
51737
51738 error = vfs_readdir(f.file, fillonedir, &buf);
51739 if (buf.result)
51740 @@ -139,6 +146,7 @@ struct linux_dirent {
51741 struct getdents_callback {
51742 struct linux_dirent __user * current_dir;
51743 struct linux_dirent __user * previous;
51744 + struct file * file;
51745 int count;
51746 int error;
51747 };
51748 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51749 buf->error = -EOVERFLOW;
51750 return -EOVERFLOW;
51751 }
51752 +
51753 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51754 + return 0;
51755 +
51756 dirent = buf->previous;
51757 if (dirent) {
51758 if (__put_user(offset, &dirent->d_off))
51759 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51760 buf.previous = NULL;
51761 buf.count = count;
51762 buf.error = 0;
51763 + buf.file = f.file;
51764
51765 error = vfs_readdir(f.file, filldir, &buf);
51766 if (error >= 0)
51767 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51768 struct getdents_callback64 {
51769 struct linux_dirent64 __user * current_dir;
51770 struct linux_dirent64 __user * previous;
51771 + struct file *file;
51772 int count;
51773 int error;
51774 };
51775 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51776 buf->error = -EINVAL; /* only used if we fail.. */
51777 if (reclen > buf->count)
51778 return -EINVAL;
51779 +
51780 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51781 + return 0;
51782 +
51783 dirent = buf->previous;
51784 if (dirent) {
51785 if (__put_user(offset, &dirent->d_off))
51786 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51787
51788 buf.current_dir = dirent;
51789 buf.previous = NULL;
51790 + buf.file = f.file;
51791 buf.count = count;
51792 buf.error = 0;
51793
51794 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51795 error = buf.error;
51796 lastdirent = buf.previous;
51797 if (lastdirent) {
51798 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
51799 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51800 if (__put_user(d_off, &lastdirent->d_off))
51801 error = -EFAULT;
51802 else
51803 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51804 index 2b7882b..1c5ef48 100644
51805 --- a/fs/reiserfs/do_balan.c
51806 +++ b/fs/reiserfs/do_balan.c
51807 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51808 return;
51809 }
51810
51811 - atomic_inc(&(fs_generation(tb->tb_sb)));
51812 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51813 do_balance_starts(tb);
51814
51815 /* balance leaf returns 0 except if combining L R and S into
51816 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51817 index e60e870..f40ac16 100644
51818 --- a/fs/reiserfs/procfs.c
51819 +++ b/fs/reiserfs/procfs.c
51820 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51821 "SMALL_TAILS " : "NO_TAILS ",
51822 replay_only(sb) ? "REPLAY_ONLY " : "",
51823 convert_reiserfs(sb) ? "CONV " : "",
51824 - atomic_read(&r->s_generation_counter),
51825 + atomic_read_unchecked(&r->s_generation_counter),
51826 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51827 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51828 SF(s_good_search_by_key_reada), SF(s_bmaps),
51829 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51830 index 33215f5..c5d427a 100644
51831 --- a/fs/reiserfs/reiserfs.h
51832 +++ b/fs/reiserfs/reiserfs.h
51833 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51834 /* Comment? -Hans */
51835 wait_queue_head_t s_wait;
51836 /* To be obsoleted soon by per buffer seals.. -Hans */
51837 - atomic_t s_generation_counter; // increased by one every time the
51838 + atomic_unchecked_t s_generation_counter; // increased by one every time the
51839 // tree gets re-balanced
51840 unsigned long s_properties; /* File system properties. Currently holds
51841 on-disk FS format */
51842 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51843 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51844
51845 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51846 -#define get_generation(s) atomic_read (&fs_generation(s))
51847 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51848 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51849 #define __fs_changed(gen,s) (gen != get_generation (s))
51850 #define fs_changed(gen,s) \
51851 diff --git a/fs/select.c b/fs/select.c
51852 index 2ef72d9..f213b17 100644
51853 --- a/fs/select.c
51854 +++ b/fs/select.c
51855 @@ -20,6 +20,7 @@
51856 #include <linux/export.h>
51857 #include <linux/slab.h>
51858 #include <linux/poll.h>
51859 +#include <linux/security.h>
51860 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51861 #include <linux/file.h>
51862 #include <linux/fdtable.h>
51863 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51864 struct poll_list *walk = head;
51865 unsigned long todo = nfds;
51866
51867 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51868 if (nfds > rlimit(RLIMIT_NOFILE))
51869 return -EINVAL;
51870
51871 diff --git a/fs/seq_file.c b/fs/seq_file.c
51872 index 99dffab..e4fcb71 100644
51873 --- a/fs/seq_file.c
51874 +++ b/fs/seq_file.c
51875 @@ -10,6 +10,7 @@
51876 #include <linux/seq_file.h>
51877 #include <linux/slab.h>
51878 #include <linux/cred.h>
51879 +#include <linux/sched.h>
51880
51881 #include <asm/uaccess.h>
51882 #include <asm/page.h>
51883 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51884 #ifdef CONFIG_USER_NS
51885 p->user_ns = file->f_cred->user_ns;
51886 #endif
51887 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51888 + p->exec_id = current->exec_id;
51889 +#endif
51890
51891 /*
51892 * Wrappers around seq_open(e.g. swaps_open) need to be
51893 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51894 return 0;
51895 }
51896 if (!m->buf) {
51897 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51898 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51899 if (!m->buf)
51900 return -ENOMEM;
51901 }
51902 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51903 Eoverflow:
51904 m->op->stop(m, p);
51905 kfree(m->buf);
51906 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51907 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51908 return !m->buf ? -ENOMEM : -EAGAIN;
51909 }
51910
51911 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51912
51913 /* grab buffer if we didn't have one */
51914 if (!m->buf) {
51915 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51916 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51917 if (!m->buf)
51918 goto Enomem;
51919 }
51920 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51921 goto Fill;
51922 m->op->stop(m, p);
51923 kfree(m->buf);
51924 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51925 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51926 if (!m->buf)
51927 goto Enomem;
51928 m->count = 0;
51929 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
51930 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
51931 void *data)
51932 {
51933 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
51934 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
51935 int res = -ENOMEM;
51936
51937 if (op) {
51938 diff --git a/fs/splice.c b/fs/splice.c
51939 index 48c7bd1..d0740e4 100644
51940 --- a/fs/splice.c
51941 +++ b/fs/splice.c
51942 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51943 pipe_lock(pipe);
51944
51945 for (;;) {
51946 - if (!pipe->readers) {
51947 + if (!atomic_read(&pipe->readers)) {
51948 send_sig(SIGPIPE, current, 0);
51949 if (!ret)
51950 ret = -EPIPE;
51951 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51952 do_wakeup = 0;
51953 }
51954
51955 - pipe->waiting_writers++;
51956 + atomic_inc(&pipe->waiting_writers);
51957 pipe_wait(pipe);
51958 - pipe->waiting_writers--;
51959 + atomic_dec(&pipe->waiting_writers);
51960 }
51961
51962 pipe_unlock(pipe);
51963 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
51964 old_fs = get_fs();
51965 set_fs(get_ds());
51966 /* The cast to a user pointer is valid due to the set_fs() */
51967 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
51968 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
51969 set_fs(old_fs);
51970
51971 return res;
51972 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
51973 old_fs = get_fs();
51974 set_fs(get_ds());
51975 /* The cast to a user pointer is valid due to the set_fs() */
51976 - res = vfs_write(file, (const char __user *)buf, count, &pos);
51977 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
51978 set_fs(old_fs);
51979
51980 return res;
51981 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
51982 goto err;
51983
51984 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
51985 - vec[i].iov_base = (void __user *) page_address(page);
51986 + vec[i].iov_base = (void __force_user *) page_address(page);
51987 vec[i].iov_len = this_len;
51988 spd.pages[i] = page;
51989 spd.nr_pages++;
51990 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
51991 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
51992 {
51993 while (!pipe->nrbufs) {
51994 - if (!pipe->writers)
51995 + if (!atomic_read(&pipe->writers))
51996 return 0;
51997
51998 - if (!pipe->waiting_writers && sd->num_spliced)
51999 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52000 return 0;
52001
52002 if (sd->flags & SPLICE_F_NONBLOCK)
52003 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52004 * out of the pipe right after the splice_to_pipe(). So set
52005 * PIPE_READERS appropriately.
52006 */
52007 - pipe->readers = 1;
52008 + atomic_set(&pipe->readers, 1);
52009
52010 current->splice_pipe = pipe;
52011 }
52012 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52013 ret = -ERESTARTSYS;
52014 break;
52015 }
52016 - if (!pipe->writers)
52017 + if (!atomic_read(&pipe->writers))
52018 break;
52019 - if (!pipe->waiting_writers) {
52020 + if (!atomic_read(&pipe->waiting_writers)) {
52021 if (flags & SPLICE_F_NONBLOCK) {
52022 ret = -EAGAIN;
52023 break;
52024 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52025 pipe_lock(pipe);
52026
52027 while (pipe->nrbufs >= pipe->buffers) {
52028 - if (!pipe->readers) {
52029 + if (!atomic_read(&pipe->readers)) {
52030 send_sig(SIGPIPE, current, 0);
52031 ret = -EPIPE;
52032 break;
52033 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52034 ret = -ERESTARTSYS;
52035 break;
52036 }
52037 - pipe->waiting_writers++;
52038 + atomic_inc(&pipe->waiting_writers);
52039 pipe_wait(pipe);
52040 - pipe->waiting_writers--;
52041 + atomic_dec(&pipe->waiting_writers);
52042 }
52043
52044 pipe_unlock(pipe);
52045 @@ -1826,14 +1826,14 @@ retry:
52046 pipe_double_lock(ipipe, opipe);
52047
52048 do {
52049 - if (!opipe->readers) {
52050 + if (!atomic_read(&opipe->readers)) {
52051 send_sig(SIGPIPE, current, 0);
52052 if (!ret)
52053 ret = -EPIPE;
52054 break;
52055 }
52056
52057 - if (!ipipe->nrbufs && !ipipe->writers)
52058 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52059 break;
52060
52061 /*
52062 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52063 pipe_double_lock(ipipe, opipe);
52064
52065 do {
52066 - if (!opipe->readers) {
52067 + if (!atomic_read(&opipe->readers)) {
52068 send_sig(SIGPIPE, current, 0);
52069 if (!ret)
52070 ret = -EPIPE;
52071 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52072 * return EAGAIN if we have the potential of some data in the
52073 * future, otherwise just return 0
52074 */
52075 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52076 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52077 ret = -EAGAIN;
52078
52079 pipe_unlock(ipipe);
52080 diff --git a/fs/stat.c b/fs/stat.c
52081 index eae4946..6198f55 100644
52082 --- a/fs/stat.c
52083 +++ b/fs/stat.c
52084 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52085 stat->gid = inode->i_gid;
52086 stat->rdev = inode->i_rdev;
52087 stat->size = i_size_read(inode);
52088 - stat->atime = inode->i_atime;
52089 - stat->mtime = inode->i_mtime;
52090 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52091 + stat->atime = inode->i_ctime;
52092 + stat->mtime = inode->i_ctime;
52093 + } else {
52094 + stat->atime = inode->i_atime;
52095 + stat->mtime = inode->i_mtime;
52096 + }
52097 stat->ctime = inode->i_ctime;
52098 stat->blksize = (1 << inode->i_blkbits);
52099 stat->blocks = inode->i_blocks;
52100 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
52101 if (retval)
52102 return retval;
52103
52104 - if (inode->i_op->getattr)
52105 - return inode->i_op->getattr(mnt, dentry, stat);
52106 + if (inode->i_op->getattr) {
52107 + retval = inode->i_op->getattr(mnt, dentry, stat);
52108 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52109 + stat->atime = stat->ctime;
52110 + stat->mtime = stat->ctime;
52111 + }
52112 + return retval;
52113 + }
52114
52115 generic_fillattr(inode, stat);
52116 return 0;
52117 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
52118 index 2fbdff6..5530a61 100644
52119 --- a/fs/sysfs/dir.c
52120 +++ b/fs/sysfs/dir.c
52121 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
52122 struct sysfs_dirent *sd;
52123 int rc;
52124
52125 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52126 + const char *parent_name = parent_sd->s_name;
52127 +
52128 + mode = S_IFDIR | S_IRWXU;
52129 +
52130 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
52131 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
52132 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52133 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52134 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52135 +#endif
52136 +
52137 /* allocate */
52138 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52139 if (!sd)
52140 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52141 index 00012e3..8392349 100644
52142 --- a/fs/sysfs/file.c
52143 +++ b/fs/sysfs/file.c
52144 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52145
52146 struct sysfs_open_dirent {
52147 atomic_t refcnt;
52148 - atomic_t event;
52149 + atomic_unchecked_t event;
52150 wait_queue_head_t poll;
52151 struct list_head buffers; /* goes through sysfs_buffer.list */
52152 };
52153 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52154 if (!sysfs_get_active(attr_sd))
52155 return -ENODEV;
52156
52157 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52158 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52159 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52160
52161 sysfs_put_active(attr_sd);
52162 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52163 return -ENOMEM;
52164
52165 atomic_set(&new_od->refcnt, 0);
52166 - atomic_set(&new_od->event, 1);
52167 + atomic_set_unchecked(&new_od->event, 1);
52168 init_waitqueue_head(&new_od->poll);
52169 INIT_LIST_HEAD(&new_od->buffers);
52170 goto retry;
52171 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52172
52173 sysfs_put_active(attr_sd);
52174
52175 - if (buffer->event != atomic_read(&od->event))
52176 + if (buffer->event != atomic_read_unchecked(&od->event))
52177 goto trigger;
52178
52179 return DEFAULT_POLLMASK;
52180 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52181
52182 od = sd->s_attr.open;
52183 if (od) {
52184 - atomic_inc(&od->event);
52185 + atomic_inc_unchecked(&od->event);
52186 wake_up_interruptible(&od->poll);
52187 }
52188
52189 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52190 index 3c9eb56..9dea5be 100644
52191 --- a/fs/sysfs/symlink.c
52192 +++ b/fs/sysfs/symlink.c
52193 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52194
52195 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52196 {
52197 - char *page = nd_get_link(nd);
52198 + const char *page = nd_get_link(nd);
52199 if (!IS_ERR(page))
52200 free_page((unsigned long)page);
52201 }
52202 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52203 index c175b4d..8f36a16 100644
52204 --- a/fs/udf/misc.c
52205 +++ b/fs/udf/misc.c
52206 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52207
52208 u8 udf_tag_checksum(const struct tag *t)
52209 {
52210 - u8 *data = (u8 *)t;
52211 + const u8 *data = (const u8 *)t;
52212 u8 checksum = 0;
52213 int i;
52214 for (i = 0; i < sizeof(struct tag); ++i)
52215 diff --git a/fs/utimes.c b/fs/utimes.c
52216 index bb0696a..552054b 100644
52217 --- a/fs/utimes.c
52218 +++ b/fs/utimes.c
52219 @@ -1,6 +1,7 @@
52220 #include <linux/compiler.h>
52221 #include <linux/file.h>
52222 #include <linux/fs.h>
52223 +#include <linux/security.h>
52224 #include <linux/linkage.h>
52225 #include <linux/mount.h>
52226 #include <linux/namei.h>
52227 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52228 goto mnt_drop_write_and_out;
52229 }
52230 }
52231 +
52232 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52233 + error = -EACCES;
52234 + goto mnt_drop_write_and_out;
52235 + }
52236 +
52237 mutex_lock(&inode->i_mutex);
52238 error = notify_change(path->dentry, &newattrs);
52239 mutex_unlock(&inode->i_mutex);
52240 diff --git a/fs/xattr.c b/fs/xattr.c
52241 index e21c119..21dfc7c 100644
52242 --- a/fs/xattr.c
52243 +++ b/fs/xattr.c
52244 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52245 * Extended attribute SET operations
52246 */
52247 static long
52248 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
52249 +setxattr(struct path *path, const char __user *name, const void __user *value,
52250 size_t size, int flags)
52251 {
52252 int error;
52253 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52254 posix_acl_fix_xattr_from_user(kvalue, size);
52255 }
52256
52257 - error = vfs_setxattr(d, kname, kvalue, size, flags);
52258 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52259 + error = -EACCES;
52260 + goto out;
52261 + }
52262 +
52263 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52264 out:
52265 if (vvalue)
52266 vfree(vvalue);
52267 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52268 return error;
52269 error = mnt_want_write(path.mnt);
52270 if (!error) {
52271 - error = setxattr(path.dentry, name, value, size, flags);
52272 + error = setxattr(&path, name, value, size, flags);
52273 mnt_drop_write(path.mnt);
52274 }
52275 path_put(&path);
52276 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52277 return error;
52278 error = mnt_want_write(path.mnt);
52279 if (!error) {
52280 - error = setxattr(path.dentry, name, value, size, flags);
52281 + error = setxattr(&path, name, value, size, flags);
52282 mnt_drop_write(path.mnt);
52283 }
52284 path_put(&path);
52285 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52286 const void __user *,value, size_t, size, int, flags)
52287 {
52288 struct fd f = fdget(fd);
52289 - struct dentry *dentry;
52290 int error = -EBADF;
52291
52292 if (!f.file)
52293 return error;
52294 - dentry = f.file->f_path.dentry;
52295 - audit_inode(NULL, dentry, 0);
52296 + audit_inode(NULL, f.file->f_path.dentry, 0);
52297 error = mnt_want_write_file(f.file);
52298 if (!error) {
52299 - error = setxattr(dentry, name, value, size, flags);
52300 + error = setxattr(&f.file->f_path, name, value, size, flags);
52301 mnt_drop_write_file(f.file);
52302 }
52303 fdput(f);
52304 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52305 index 9fbea87..6b19972 100644
52306 --- a/fs/xattr_acl.c
52307 +++ b/fs/xattr_acl.c
52308 @@ -76,8 +76,8 @@ struct posix_acl *
52309 posix_acl_from_xattr(struct user_namespace *user_ns,
52310 const void *value, size_t size)
52311 {
52312 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52313 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52314 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52315 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52316 int count;
52317 struct posix_acl *acl;
52318 struct posix_acl_entry *acl_e;
52319 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52320 index 83d0cf3..2ef526b 100644
52321 --- a/fs/xfs/xfs_bmap.c
52322 +++ b/fs/xfs/xfs_bmap.c
52323 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52324 int nmap,
52325 int ret_nmap);
52326 #else
52327 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52328 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52329 #endif /* DEBUG */
52330
52331 STATIC int
52332 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52333 index 1b9fc3e..e1bdde0 100644
52334 --- a/fs/xfs/xfs_dir2_sf.c
52335 +++ b/fs/xfs/xfs_dir2_sf.c
52336 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52337 }
52338
52339 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52340 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52341 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52342 + char name[sfep->namelen];
52343 + memcpy(name, sfep->name, sfep->namelen);
52344 + if (filldir(dirent, name, sfep->namelen,
52345 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
52346 + *offset = off & 0x7fffffff;
52347 + return 0;
52348 + }
52349 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52350 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52351 *offset = off & 0x7fffffff;
52352 return 0;
52353 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52354 index c1df3c6..f987db6 100644
52355 --- a/fs/xfs/xfs_ioctl.c
52356 +++ b/fs/xfs/xfs_ioctl.c
52357 @@ -126,7 +126,7 @@ xfs_find_handle(
52358 }
52359
52360 error = -EFAULT;
52361 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52362 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52363 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52364 goto out_put;
52365
52366 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52367 index 4e00cf0..3374374 100644
52368 --- a/fs/xfs/xfs_iops.c
52369 +++ b/fs/xfs/xfs_iops.c
52370 @@ -394,7 +394,7 @@ xfs_vn_put_link(
52371 struct nameidata *nd,
52372 void *p)
52373 {
52374 - char *s = nd_get_link(nd);
52375 + const char *s = nd_get_link(nd);
52376
52377 if (!IS_ERR(s))
52378 kfree(s);
52379 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52380 new file mode 100644
52381 index 0000000..92247e4
52382 --- /dev/null
52383 +++ b/grsecurity/Kconfig
52384 @@ -0,0 +1,1021 @@
52385 +#
52386 +# grecurity configuration
52387 +#
52388 +menu "Memory Protections"
52389 +depends on GRKERNSEC
52390 +
52391 +config GRKERNSEC_KMEM
52392 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52393 + default y if GRKERNSEC_CONFIG_AUTO
52394 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52395 + help
52396 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52397 + be written to or read from to modify or leak the contents of the running
52398 + kernel. /dev/port will also not be allowed to be opened and support
52399 + for /dev/cpu/*/msr will be removed. If you have module
52400 + support disabled, enabling this will close up five ways that are
52401 + currently used to insert malicious code into the running kernel.
52402 +
52403 + Even with all these features enabled, we still highly recommend that
52404 + you use the RBAC system, as it is still possible for an attacker to
52405 + modify the running kernel through privileged I/O granted by ioperm/iopl.
52406 +
52407 + If you are not using XFree86, you may be able to stop this additional
52408 + case by enabling the 'Disable privileged I/O' option. Though nothing
52409 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52410 + but only to video memory, which is the only writing we allow in this
52411 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52412 + not be allowed to mprotect it with PROT_WRITE later.
52413 + Enabling this feature will prevent the "cpupower" and "powertop" tools
52414 + from working.
52415 +
52416 + It is highly recommended that you say Y here if you meet all the
52417 + conditions above.
52418 +
52419 +config GRKERNSEC_VM86
52420 + bool "Restrict VM86 mode"
52421 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52422 + depends on X86_32
52423 +
52424 + help
52425 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52426 + make use of a special execution mode on 32bit x86 processors called
52427 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52428 + video cards and will still work with this option enabled. The purpose
52429 + of the option is to prevent exploitation of emulation errors in
52430 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
52431 + Nearly all users should be able to enable this option.
52432 +
52433 +config GRKERNSEC_IO
52434 + bool "Disable privileged I/O"
52435 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52436 + depends on X86
52437 + select RTC_CLASS
52438 + select RTC_INTF_DEV
52439 + select RTC_DRV_CMOS
52440 +
52441 + help
52442 + If you say Y here, all ioperm and iopl calls will return an error.
52443 + Ioperm and iopl can be used to modify the running kernel.
52444 + Unfortunately, some programs need this access to operate properly,
52445 + the most notable of which are XFree86 and hwclock. hwclock can be
52446 + remedied by having RTC support in the kernel, so real-time
52447 + clock support is enabled if this option is enabled, to ensure
52448 + that hwclock operates correctly. XFree86 still will not
52449 + operate correctly with this option enabled, so DO NOT CHOOSE Y
52450 + IF YOU USE XFree86. If you use XFree86 and you still want to
52451 + protect your kernel against modification, use the RBAC system.
52452 +
52453 +config GRKERNSEC_JIT_HARDEN
52454 + bool "Harden BPF JIT against spray attacks"
52455 + default y if GRKERNSEC_CONFIG_AUTO
52456 + depends on BPF_JIT
52457 + help
52458 + If you say Y here, the native code generated by the kernel's Berkeley
52459 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52460 + attacks that attempt to fit attacker-beneficial instructions in
52461 + 32bit immediate fields of JIT-generated native instructions. The
52462 + attacker will generally aim to cause an unintended instruction sequence
52463 + of JIT-generated native code to execute by jumping into the middle of
52464 + a generated instruction. This feature effectively randomizes the 32bit
52465 + immediate constants present in the generated code to thwart such attacks.
52466 +
52467 + If you're using KERNEXEC, it's recommended that you enable this option
52468 + to supplement the hardening of the kernel.
52469 +
52470 +config GRKERNSEC_RAND_THREADSTACK
52471 + bool "Insert random gaps between thread stacks"
52472 + default y if GRKERNSEC_CONFIG_AUTO
52473 + depends on PAX_RANDMMAP && !PPC
52474 + help
52475 + If you say Y here, a random-sized gap will be enforced between allocated
52476 + thread stacks. Glibc's NPTL and other threading libraries that
52477 + pass MAP_STACK to the kernel for thread stack allocation are supported.
52478 + The implementation currently provides 8 bits of entropy for the gap.
52479 +
52480 + Many distributions do not compile threaded remote services with the
52481 + -fstack-check argument to GCC, causing the variable-sized stack-based
52482 + allocator, alloca(), to not probe the stack on allocation. This
52483 + permits an unbounded alloca() to skip over any guard page and potentially
52484 + modify another thread's stack reliably. An enforced random gap
52485 + reduces the reliability of such an attack and increases the chance
52486 + that such a read/write to another thread's stack instead lands in
52487 + an unmapped area, causing a crash and triggering grsecurity's
52488 + anti-bruteforcing logic.
52489 +
52490 +config GRKERNSEC_PROC_MEMMAP
52491 + bool "Harden ASLR against information leaks and entropy reduction"
52492 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52493 + depends on PAX_NOEXEC || PAX_ASLR
52494 + help
52495 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52496 + give no information about the addresses of its mappings if
52497 + PaX features that rely on random addresses are enabled on the task.
52498 + In addition to sanitizing this information and disabling other
52499 + dangerous sources of information, this option causes reads of sensitive
52500 + /proc/<pid> entries where the file descriptor was opened in a different
52501 + task than the one performing the read. Such attempts are logged.
52502 + This option also limits argv/env strings for suid/sgid binaries
52503 + to 512KB to prevent a complete exhaustion of the stack entropy provided
52504 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52505 + binaries to prevent alternative mmap layouts from being abused.
52506 +
52507 + If you use PaX it is essential that you say Y here as it closes up
52508 + several holes that make full ASLR useless locally.
52509 +
52510 +config GRKERNSEC_BRUTE
52511 + bool "Deter exploit bruteforcing"
52512 + default y if GRKERNSEC_CONFIG_AUTO
52513 + help
52514 + If you say Y here, attempts to bruteforce exploits against forking
52515 + daemons such as apache or sshd, as well as against suid/sgid binaries
52516 + will be deterred. When a child of a forking daemon is killed by PaX
52517 + or crashes due to an illegal instruction or other suspicious signal,
52518 + the parent process will be delayed 30 seconds upon every subsequent
52519 + fork until the administrator is able to assess the situation and
52520 + restart the daemon.
52521 + In the suid/sgid case, the attempt is logged, the user has all their
52522 + processes terminated, and they are prevented from executing any further
52523 + processes for 15 minutes.
52524 + It is recommended that you also enable signal logging in the auditing
52525 + section so that logs are generated when a process triggers a suspicious
52526 + signal.
52527 + If the sysctl option is enabled, a sysctl option with name
52528 + "deter_bruteforce" is created.
52529 +
52530 +
52531 +config GRKERNSEC_MODHARDEN
52532 + bool "Harden module auto-loading"
52533 + default y if GRKERNSEC_CONFIG_AUTO
52534 + depends on MODULES
52535 + help
52536 + If you say Y here, module auto-loading in response to use of some
52537 + feature implemented by an unloaded module will be restricted to
52538 + root users. Enabling this option helps defend against attacks
52539 + by unprivileged users who abuse the auto-loading behavior to
52540 + cause a vulnerable module to load that is then exploited.
52541 +
52542 + If this option prevents a legitimate use of auto-loading for a
52543 + non-root user, the administrator can execute modprobe manually
52544 + with the exact name of the module mentioned in the alert log.
52545 + Alternatively, the administrator can add the module to the list
52546 + of modules loaded at boot by modifying init scripts.
52547 +
52548 + Modification of init scripts will most likely be needed on
52549 + Ubuntu servers with encrypted home directory support enabled,
52550 + as the first non-root user logging in will cause the ecb(aes),
52551 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52552 +
52553 +config GRKERNSEC_HIDESYM
52554 + bool "Hide kernel symbols"
52555 + default y if GRKERNSEC_CONFIG_AUTO
52556 + select PAX_USERCOPY_SLABS
52557 + help
52558 + If you say Y here, getting information on loaded modules, and
52559 + displaying all kernel symbols through a syscall will be restricted
52560 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52561 + /proc/kallsyms will be restricted to the root user. The RBAC
52562 + system can hide that entry even from root.
52563 +
52564 + This option also prevents leaking of kernel addresses through
52565 + several /proc entries.
52566 +
52567 + Note that this option is only effective provided the following
52568 + conditions are met:
52569 + 1) The kernel using grsecurity is not precompiled by some distribution
52570 + 2) You have also enabled GRKERNSEC_DMESG
52571 + 3) You are using the RBAC system and hiding other files such as your
52572 + kernel image and System.map. Alternatively, enabling this option
52573 + causes the permissions on /boot, /lib/modules, and the kernel
52574 + source directory to change at compile time to prevent
52575 + reading by non-root users.
52576 + If the above conditions are met, this option will aid in providing a
52577 + useful protection against local kernel exploitation of overflows
52578 + and arbitrary read/write vulnerabilities.
52579 +
52580 +config GRKERNSEC_KERN_LOCKOUT
52581 + bool "Active kernel exploit response"
52582 + default y if GRKERNSEC_CONFIG_AUTO
52583 + depends on X86 || ARM || PPC || SPARC
52584 + help
52585 + If you say Y here, when a PaX alert is triggered due to suspicious
52586 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52587 + or an OOPS occurs due to bad memory accesses, instead of just
52588 + terminating the offending process (and potentially allowing
52589 + a subsequent exploit from the same user), we will take one of two
52590 + actions:
52591 + If the user was root, we will panic the system
52592 + If the user was non-root, we will log the attempt, terminate
52593 + all processes owned by the user, then prevent them from creating
52594 + any new processes until the system is restarted
52595 + This deters repeated kernel exploitation/bruteforcing attempts
52596 + and is useful for later forensics.
52597 +
52598 +endmenu
52599 +menu "Role Based Access Control Options"
52600 +depends on GRKERNSEC
52601 +
52602 +config GRKERNSEC_RBAC_DEBUG
52603 + bool
52604 +
52605 +config GRKERNSEC_NO_RBAC
52606 + bool "Disable RBAC system"
52607 + help
52608 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52609 + preventing the RBAC system from being enabled. You should only say Y
52610 + here if you have no intention of using the RBAC system, so as to prevent
52611 + an attacker with root access from misusing the RBAC system to hide files
52612 + and processes when loadable module support and /dev/[k]mem have been
52613 + locked down.
52614 +
52615 +config GRKERNSEC_ACL_HIDEKERN
52616 + bool "Hide kernel processes"
52617 + help
52618 + If you say Y here, all kernel threads will be hidden to all
52619 + processes but those whose subject has the "view hidden processes"
52620 + flag.
52621 +
52622 +config GRKERNSEC_ACL_MAXTRIES
52623 + int "Maximum tries before password lockout"
52624 + default 3
52625 + help
52626 + This option enforces the maximum number of times a user can attempt
52627 + to authorize themselves with the grsecurity RBAC system before being
52628 + denied the ability to attempt authorization again for a specified time.
52629 + The lower the number, the harder it will be to brute-force a password.
52630 +
52631 +config GRKERNSEC_ACL_TIMEOUT
52632 + int "Time to wait after max password tries, in seconds"
52633 + default 30
52634 + help
52635 + This option specifies the time the user must wait after attempting to
52636 + authorize to the RBAC system with the maximum number of invalid
52637 + passwords. The higher the number, the harder it will be to brute-force
52638 + a password.
52639 +
52640 +endmenu
52641 +menu "Filesystem Protections"
52642 +depends on GRKERNSEC
52643 +
52644 +config GRKERNSEC_PROC
52645 + bool "Proc restrictions"
52646 + default y if GRKERNSEC_CONFIG_AUTO
52647 + help
52648 + If you say Y here, the permissions of the /proc filesystem
52649 + will be altered to enhance system security and privacy. You MUST
52650 + choose either a user only restriction or a user and group restriction.
52651 + Depending upon the option you choose, you can either restrict users to
52652 + see only the processes they themselves run, or choose a group that can
52653 + view all processes and files normally restricted to root if you choose
52654 + the "restrict to user only" option. NOTE: If you're running identd or
52655 + ntpd as a non-root user, you will have to run it as the group you
52656 + specify here.
52657 +
52658 +config GRKERNSEC_PROC_USER
52659 + bool "Restrict /proc to user only"
52660 + depends on GRKERNSEC_PROC
52661 + help
52662 + If you say Y here, non-root users will only be able to view their own
52663 + processes, and restricts them from viewing network-related information,
52664 + and viewing kernel symbol and module information.
52665 +
52666 +config GRKERNSEC_PROC_USERGROUP
52667 + bool "Allow special group"
52668 + default y if GRKERNSEC_CONFIG_AUTO
52669 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52670 + help
52671 + If you say Y here, you will be able to select a group that will be
52672 + able to view all processes and network-related information. If you've
52673 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52674 + remain hidden. This option is useful if you want to run identd as
52675 + a non-root user. The group you select may also be chosen at boot time
52676 + via "grsec_proc_gid=" on the kernel commandline.
52677 +
52678 +config GRKERNSEC_PROC_GID
52679 + int "GID for special group"
52680 + depends on GRKERNSEC_PROC_USERGROUP
52681 + default 1001
52682 +
52683 +config GRKERNSEC_PROC_ADD
52684 + bool "Additional restrictions"
52685 + default y if GRKERNSEC_CONFIG_AUTO
52686 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52687 + help
52688 + If you say Y here, additional restrictions will be placed on
52689 + /proc that keep normal users from viewing device information and
52690 + slabinfo information that could be useful for exploits.
52691 +
52692 +config GRKERNSEC_LINK
52693 + bool "Linking restrictions"
52694 + default y if GRKERNSEC_CONFIG_AUTO
52695 + help
52696 + If you say Y here, /tmp race exploits will be prevented, since users
52697 + will no longer be able to follow symlinks owned by other users in
52698 + world-writable +t directories (e.g. /tmp), unless the owner of the
52699 + symlink is the owner of the directory. users will also not be
52700 + able to hardlink to files they do not own. If the sysctl option is
52701 + enabled, a sysctl option with name "linking_restrictions" is created.
52702 +
52703 +config GRKERNSEC_SYMLINKOWN
52704 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52705 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52706 + help
52707 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52708 + that prevents it from being used as a security feature. As Apache
52709 + verifies the symlink by performing a stat() against the target of
52710 + the symlink before it is followed, an attacker can setup a symlink
52711 + to point to a same-owned file, then replace the symlink with one
52712 + that targets another user's file just after Apache "validates" the
52713 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52714 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52715 + will be in place for the group you specify. If the sysctl option
52716 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52717 + created.
52718 +
52719 +config GRKERNSEC_SYMLINKOWN_GID
52720 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52721 + depends on GRKERNSEC_SYMLINKOWN
52722 + default 1006
52723 + help
52724 + Setting this GID determines what group kernel-enforced
52725 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52726 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52727 +
52728 +config GRKERNSEC_FIFO
52729 + bool "FIFO restrictions"
52730 + default y if GRKERNSEC_CONFIG_AUTO
52731 + help
52732 + If you say Y here, users will not be able to write to FIFOs they don't
52733 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52734 + the FIFO is the same owner of the directory it's held in. If the sysctl
52735 + option is enabled, a sysctl option with name "fifo_restrictions" is
52736 + created.
52737 +
52738 +config GRKERNSEC_SYSFS_RESTRICT
52739 + bool "Sysfs/debugfs restriction"
52740 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52741 + depends on SYSFS
52742 + help
52743 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52744 + any filesystem normally mounted under it (e.g. debugfs) will be
52745 + mostly accessible only by root. These filesystems generally provide access
52746 + to hardware and debug information that isn't appropriate for unprivileged
52747 + users of the system. Sysfs and debugfs have also become a large source
52748 + of new vulnerabilities, ranging from infoleaks to local compromise.
52749 + There has been very little oversight with an eye toward security involved
52750 + in adding new exporters of information to these filesystems, so their
52751 + use is discouraged.
52752 + For reasons of compatibility, a few directories have been whitelisted
52753 + for access by non-root users:
52754 + /sys/fs/selinux
52755 + /sys/fs/fuse
52756 + /sys/devices/system/cpu
52757 +
52758 +config GRKERNSEC_ROFS
52759 + bool "Runtime read-only mount protection"
52760 + help
52761 + If you say Y here, a sysctl option with name "romount_protect" will
52762 + be created. By setting this option to 1 at runtime, filesystems
52763 + will be protected in the following ways:
52764 + * No new writable mounts will be allowed
52765 + * Existing read-only mounts won't be able to be remounted read/write
52766 + * Write operations will be denied on all block devices
52767 + This option acts independently of grsec_lock: once it is set to 1,
52768 + it cannot be turned off. Therefore, please be mindful of the resulting
52769 + behavior if this option is enabled in an init script on a read-only
52770 + filesystem. This feature is mainly intended for secure embedded systems.
52771 +
52772 +config GRKERNSEC_DEVICE_SIDECHANNEL
52773 + bool "Eliminate stat/notify-based device sidechannels"
52774 + default y if GRKERNSEC_CONFIG_AUTO
52775 + help
52776 + If you say Y here, timing analyses on block or character
52777 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52778 + will be thwarted for unprivileged users. If a process without
52779 + CAP_MKNOD stats such a device, the last access and last modify times
52780 + will match the device's create time. No access or modify events
52781 + will be triggered through inotify/dnotify/fanotify for such devices.
52782 + This feature will prevent attacks that may at a minimum
52783 + allow an attacker to determine the administrator's password length.
52784 +
52785 +config GRKERNSEC_CHROOT
52786 + bool "Chroot jail restrictions"
52787 + default y if GRKERNSEC_CONFIG_AUTO
52788 + help
52789 + If you say Y here, you will be able to choose several options that will
52790 + make breaking out of a chrooted jail much more difficult. If you
52791 + encounter no software incompatibilities with the following options, it
52792 + is recommended that you enable each one.
52793 +
52794 +config GRKERNSEC_CHROOT_MOUNT
52795 + bool "Deny mounts"
52796 + default y if GRKERNSEC_CONFIG_AUTO
52797 + depends on GRKERNSEC_CHROOT
52798 + help
52799 + If you say Y here, processes inside a chroot will not be able to
52800 + mount or remount filesystems. If the sysctl option is enabled, a
52801 + sysctl option with name "chroot_deny_mount" is created.
52802 +
52803 +config GRKERNSEC_CHROOT_DOUBLE
52804 + bool "Deny double-chroots"
52805 + default y if GRKERNSEC_CONFIG_AUTO
52806 + depends on GRKERNSEC_CHROOT
52807 + help
52808 + If you say Y here, processes inside a chroot will not be able to chroot
52809 + again outside the chroot. This is a widely used method of breaking
52810 + out of a chroot jail and should not be allowed. If the sysctl
52811 + option is enabled, a sysctl option with name
52812 + "chroot_deny_chroot" is created.
52813 +
52814 +config GRKERNSEC_CHROOT_PIVOT
52815 + bool "Deny pivot_root in chroot"
52816 + default y if GRKERNSEC_CONFIG_AUTO
52817 + depends on GRKERNSEC_CHROOT
52818 + help
52819 + If you say Y here, processes inside a chroot will not be able to use
52820 + a function called pivot_root() that was introduced in Linux 2.3.41. It
52821 + works similar to chroot in that it changes the root filesystem. This
52822 + function could be misused in a chrooted process to attempt to break out
52823 + of the chroot, and therefore should not be allowed. If the sysctl
52824 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
52825 + created.
52826 +
52827 +config GRKERNSEC_CHROOT_CHDIR
52828 + bool "Enforce chdir(\"/\") on all chroots"
52829 + default y if GRKERNSEC_CONFIG_AUTO
52830 + depends on GRKERNSEC_CHROOT
52831 + help
52832 + If you say Y here, the current working directory of all newly-chrooted
52833 + applications will be set to the the root directory of the chroot.
52834 + The man page on chroot(2) states:
52835 + Note that this call does not change the current working
52836 + directory, so that `.' can be outside the tree rooted at
52837 + `/'. In particular, the super-user can escape from a
52838 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52839 +
52840 + It is recommended that you say Y here, since it's not known to break
52841 + any software. If the sysctl option is enabled, a sysctl option with
52842 + name "chroot_enforce_chdir" is created.
52843 +
52844 +config GRKERNSEC_CHROOT_CHMOD
52845 + bool "Deny (f)chmod +s"
52846 + default y if GRKERNSEC_CONFIG_AUTO
52847 + depends on GRKERNSEC_CHROOT
52848 + help
52849 + If you say Y here, processes inside a chroot will not be able to chmod
52850 + or fchmod files to make them have suid or sgid bits. This protects
52851 + against another published method of breaking a chroot. If the sysctl
52852 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
52853 + created.
52854 +
52855 +config GRKERNSEC_CHROOT_FCHDIR
52856 + bool "Deny fchdir out of chroot"
52857 + default y if GRKERNSEC_CONFIG_AUTO
52858 + depends on GRKERNSEC_CHROOT
52859 + help
52860 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
52861 + to a file descriptor of the chrooting process that points to a directory
52862 + outside the filesystem will be stopped. If the sysctl option
52863 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52864 +
52865 +config GRKERNSEC_CHROOT_MKNOD
52866 + bool "Deny mknod"
52867 + default y if GRKERNSEC_CONFIG_AUTO
52868 + depends on GRKERNSEC_CHROOT
52869 + help
52870 + If you say Y here, processes inside a chroot will not be allowed to
52871 + mknod. The problem with using mknod inside a chroot is that it
52872 + would allow an attacker to create a device entry that is the same
52873 + as one on the physical root of your system, which could range from
52874 + anything from the console device to a device for your harddrive (which
52875 + they could then use to wipe the drive or steal data). It is recommended
52876 + that you say Y here, unless you run into software incompatibilities.
52877 + If the sysctl option is enabled, a sysctl option with name
52878 + "chroot_deny_mknod" is created.
52879 +
52880 +config GRKERNSEC_CHROOT_SHMAT
52881 + bool "Deny shmat() out of chroot"
52882 + default y if GRKERNSEC_CONFIG_AUTO
52883 + depends on GRKERNSEC_CHROOT
52884 + help
52885 + If you say Y here, processes inside a chroot will not be able to attach
52886 + to shared memory segments that were created outside of the chroot jail.
52887 + It is recommended that you say Y here. If the sysctl option is enabled,
52888 + a sysctl option with name "chroot_deny_shmat" is created.
52889 +
52890 +config GRKERNSEC_CHROOT_UNIX
52891 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
52892 + default y if GRKERNSEC_CONFIG_AUTO
52893 + depends on GRKERNSEC_CHROOT
52894 + help
52895 + If you say Y here, processes inside a chroot will not be able to
52896 + connect to abstract (meaning not belonging to a filesystem) Unix
52897 + domain sockets that were bound outside of a chroot. It is recommended
52898 + that you say Y here. If the sysctl option is enabled, a sysctl option
52899 + with name "chroot_deny_unix" is created.
52900 +
52901 +config GRKERNSEC_CHROOT_FINDTASK
52902 + bool "Protect outside processes"
52903 + default y if GRKERNSEC_CONFIG_AUTO
52904 + depends on GRKERNSEC_CHROOT
52905 + help
52906 + If you say Y here, processes inside a chroot will not be able to
52907 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52908 + getsid, or view any process outside of the chroot. If the sysctl
52909 + option is enabled, a sysctl option with name "chroot_findtask" is
52910 + created.
52911 +
52912 +config GRKERNSEC_CHROOT_NICE
52913 + bool "Restrict priority changes"
52914 + default y if GRKERNSEC_CONFIG_AUTO
52915 + depends on GRKERNSEC_CHROOT
52916 + help
52917 + If you say Y here, processes inside a chroot will not be able to raise
52918 + the priority of processes in the chroot, or alter the priority of
52919 + processes outside the chroot. This provides more security than simply
52920 + removing CAP_SYS_NICE from the process' capability set. If the
52921 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52922 + is created.
52923 +
52924 +config GRKERNSEC_CHROOT_SYSCTL
52925 + bool "Deny sysctl writes"
52926 + default y if GRKERNSEC_CONFIG_AUTO
52927 + depends on GRKERNSEC_CHROOT
52928 + help
52929 + If you say Y here, an attacker in a chroot will not be able to
52930 + write to sysctl entries, either by sysctl(2) or through a /proc
52931 + interface. It is strongly recommended that you say Y here. If the
52932 + sysctl option is enabled, a sysctl option with name
52933 + "chroot_deny_sysctl" is created.
52934 +
52935 +config GRKERNSEC_CHROOT_CAPS
52936 + bool "Capability restrictions"
52937 + default y if GRKERNSEC_CONFIG_AUTO
52938 + depends on GRKERNSEC_CHROOT
52939 + help
52940 + If you say Y here, the capabilities on all processes within a
52941 + chroot jail will be lowered to stop module insertion, raw i/o,
52942 + system and net admin tasks, rebooting the system, modifying immutable
52943 + files, modifying IPC owned by another, and changing the system time.
52944 + This is left an option because it can break some apps. Disable this
52945 + if your chrooted apps are having problems performing those kinds of
52946 + tasks. If the sysctl option is enabled, a sysctl option with
52947 + name "chroot_caps" is created.
52948 +
52949 +endmenu
52950 +menu "Kernel Auditing"
52951 +depends on GRKERNSEC
52952 +
52953 +config GRKERNSEC_AUDIT_GROUP
52954 + bool "Single group for auditing"
52955 + help
52956 + If you say Y here, the exec and chdir logging features will only operate
52957 + on a group you specify. This option is recommended if you only want to
52958 + watch certain users instead of having a large amount of logs from the
52959 + entire system. If the sysctl option is enabled, a sysctl option with
52960 + name "audit_group" is created.
52961 +
52962 +config GRKERNSEC_AUDIT_GID
52963 + int "GID for auditing"
52964 + depends on GRKERNSEC_AUDIT_GROUP
52965 + default 1007
52966 +
52967 +config GRKERNSEC_EXECLOG
52968 + bool "Exec logging"
52969 + help
52970 + If you say Y here, all execve() calls will be logged (since the
52971 + other exec*() calls are frontends to execve(), all execution
52972 + will be logged). Useful for shell-servers that like to keep track
52973 + of their users. If the sysctl option is enabled, a sysctl option with
52974 + name "exec_logging" is created.
52975 + WARNING: This option when enabled will produce a LOT of logs, especially
52976 + on an active system.
52977 +
52978 +config GRKERNSEC_RESLOG
52979 + bool "Resource logging"
52980 + default y if GRKERNSEC_CONFIG_AUTO
52981 + help
52982 + If you say Y here, all attempts to overstep resource limits will
52983 + be logged with the resource name, the requested size, and the current
52984 + limit. It is highly recommended that you say Y here. If the sysctl
52985 + option is enabled, a sysctl option with name "resource_logging" is
52986 + created. If the RBAC system is enabled, the sysctl value is ignored.
52987 +
52988 +config GRKERNSEC_CHROOT_EXECLOG
52989 + bool "Log execs within chroot"
52990 + help
52991 + If you say Y here, all executions inside a chroot jail will be logged
52992 + to syslog. This can cause a large amount of logs if certain
52993 + applications (eg. djb's daemontools) are installed on the system, and
52994 + is therefore left as an option. If the sysctl option is enabled, a
52995 + sysctl option with name "chroot_execlog" is created.
52996 +
52997 +config GRKERNSEC_AUDIT_PTRACE
52998 + bool "Ptrace logging"
52999 + help
53000 + If you say Y here, all attempts to attach to a process via ptrace
53001 + will be logged. If the sysctl option is enabled, a sysctl option
53002 + with name "audit_ptrace" is created.
53003 +
53004 +config GRKERNSEC_AUDIT_CHDIR
53005 + bool "Chdir logging"
53006 + help
53007 + If you say Y here, all chdir() calls will be logged. If the sysctl
53008 + option is enabled, a sysctl option with name "audit_chdir" is created.
53009 +
53010 +config GRKERNSEC_AUDIT_MOUNT
53011 + bool "(Un)Mount logging"
53012 + help
53013 + If you say Y here, all mounts and unmounts will be logged. If the
53014 + sysctl option is enabled, a sysctl option with name "audit_mount" is
53015 + created.
53016 +
53017 +config GRKERNSEC_SIGNAL
53018 + bool "Signal logging"
53019 + default y if GRKERNSEC_CONFIG_AUTO
53020 + help
53021 + If you say Y here, certain important signals will be logged, such as
53022 + SIGSEGV, which will as a result inform you of when a error in a program
53023 + occurred, which in some cases could mean a possible exploit attempt.
53024 + If the sysctl option is enabled, a sysctl option with name
53025 + "signal_logging" is created.
53026 +
53027 +config GRKERNSEC_FORKFAIL
53028 + bool "Fork failure logging"
53029 + help
53030 + If you say Y here, all failed fork() attempts will be logged.
53031 + This could suggest a fork bomb, or someone attempting to overstep
53032 + their process limit. If the sysctl option is enabled, a sysctl option
53033 + with name "forkfail_logging" is created.
53034 +
53035 +config GRKERNSEC_TIME
53036 + bool "Time change logging"
53037 + default y if GRKERNSEC_CONFIG_AUTO
53038 + help
53039 + If you say Y here, any changes of the system clock will be logged.
53040 + If the sysctl option is enabled, a sysctl option with name
53041 + "timechange_logging" is created.
53042 +
53043 +config GRKERNSEC_PROC_IPADDR
53044 + bool "/proc/<pid>/ipaddr support"
53045 + default y if GRKERNSEC_CONFIG_AUTO
53046 + help
53047 + If you say Y here, a new entry will be added to each /proc/<pid>
53048 + directory that contains the IP address of the person using the task.
53049 + The IP is carried across local TCP and AF_UNIX stream sockets.
53050 + This information can be useful for IDS/IPSes to perform remote response
53051 + to a local attack. The entry is readable by only the owner of the
53052 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53053 + the RBAC system), and thus does not create privacy concerns.
53054 +
53055 +config GRKERNSEC_RWXMAP_LOG
53056 + bool 'Denied RWX mmap/mprotect logging'
53057 + default y if GRKERNSEC_CONFIG_AUTO
53058 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53059 + help
53060 + If you say Y here, calls to mmap() and mprotect() with explicit
53061 + usage of PROT_WRITE and PROT_EXEC together will be logged when
53062 + denied by the PAX_MPROTECT feature. If the sysctl option is
53063 + enabled, a sysctl option with name "rwxmap_logging" is created.
53064 +
53065 +config GRKERNSEC_AUDIT_TEXTREL
53066 + bool 'ELF text relocations logging (READ HELP)'
53067 + depends on PAX_MPROTECT
53068 + help
53069 + If you say Y here, text relocations will be logged with the filename
53070 + of the offending library or binary. The purpose of the feature is
53071 + to help Linux distribution developers get rid of libraries and
53072 + binaries that need text relocations which hinder the future progress
53073 + of PaX. Only Linux distribution developers should say Y here, and
53074 + never on a production machine, as this option creates an information
53075 + leak that could aid an attacker in defeating the randomization of
53076 + a single memory region. If the sysctl option is enabled, a sysctl
53077 + option with name "audit_textrel" is created.
53078 +
53079 +endmenu
53080 +
53081 +menu "Executable Protections"
53082 +depends on GRKERNSEC
53083 +
53084 +config GRKERNSEC_DMESG
53085 + bool "Dmesg(8) restriction"
53086 + default y if GRKERNSEC_CONFIG_AUTO
53087 + help
53088 + If you say Y here, non-root users will not be able to use dmesg(8)
53089 + to view the contents of the kernel's circular log buffer.
53090 + The kernel's log buffer often contains kernel addresses and other
53091 + identifying information useful to an attacker in fingerprinting a
53092 + system for a targeted exploit.
53093 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
53094 + created.
53095 +
53096 +config GRKERNSEC_HARDEN_PTRACE
53097 + bool "Deter ptrace-based process snooping"
53098 + default y if GRKERNSEC_CONFIG_AUTO
53099 + help
53100 + If you say Y here, TTY sniffers and other malicious monitoring
53101 + programs implemented through ptrace will be defeated. If you
53102 + have been using the RBAC system, this option has already been
53103 + enabled for several years for all users, with the ability to make
53104 + fine-grained exceptions.
53105 +
53106 + This option only affects the ability of non-root users to ptrace
53107 + processes that are not a descendent of the ptracing process.
53108 + This means that strace ./binary and gdb ./binary will still work,
53109 + but attaching to arbitrary processes will not. If the sysctl
53110 + option is enabled, a sysctl option with name "harden_ptrace" is
53111 + created.
53112 +
53113 +config GRKERNSEC_PTRACE_READEXEC
53114 + bool "Require read access to ptrace sensitive binaries"
53115 + default y if GRKERNSEC_CONFIG_AUTO
53116 + help
53117 + If you say Y here, unprivileged users will not be able to ptrace unreadable
53118 + binaries. This option is useful in environments that
53119 + remove the read bits (e.g. file mode 4711) from suid binaries to
53120 + prevent infoleaking of their contents. This option adds
53121 + consistency to the use of that file mode, as the binary could normally
53122 + be read out when run without privileges while ptracing.
53123 +
53124 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
53125 + is created.
53126 +
53127 +config GRKERNSEC_SETXID
53128 + bool "Enforce consistent multithreaded privileges"
53129 + default y if GRKERNSEC_CONFIG_AUTO
53130 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
53131 + help
53132 + If you say Y here, a change from a root uid to a non-root uid
53133 + in a multithreaded application will cause the resulting uids,
53134 + gids, supplementary groups, and capabilities in that thread
53135 + to be propagated to the other threads of the process. In most
53136 + cases this is unnecessary, as glibc will emulate this behavior
53137 + on behalf of the application. Other libcs do not act in the
53138 + same way, allowing the other threads of the process to continue
53139 + running with root privileges. If the sysctl option is enabled,
53140 + a sysctl option with name "consistent_setxid" is created.
53141 +
53142 +config GRKERNSEC_TPE
53143 + bool "Trusted Path Execution (TPE)"
53144 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53145 + help
53146 + If you say Y here, you will be able to choose a gid to add to the
53147 + supplementary groups of users you want to mark as "untrusted."
53148 + These users will not be able to execute any files that are not in
53149 + root-owned directories writable only by root. If the sysctl option
53150 + is enabled, a sysctl option with name "tpe" is created.
53151 +
53152 +config GRKERNSEC_TPE_ALL
53153 + bool "Partially restrict all non-root users"
53154 + depends on GRKERNSEC_TPE
53155 + help
53156 + If you say Y here, all non-root users will be covered under
53157 + a weaker TPE restriction. This is separate from, and in addition to,
53158 + the main TPE options that you have selected elsewhere. Thus, if a
53159 + "trusted" GID is chosen, this restriction applies to even that GID.
53160 + Under this restriction, all non-root users will only be allowed to
53161 + execute files in directories they own that are not group or
53162 + world-writable, or in directories owned by root and writable only by
53163 + root. If the sysctl option is enabled, a sysctl option with name
53164 + "tpe_restrict_all" is created.
53165 +
53166 +config GRKERNSEC_TPE_INVERT
53167 + bool "Invert GID option"
53168 + depends on GRKERNSEC_TPE
53169 + help
53170 + If you say Y here, the group you specify in the TPE configuration will
53171 + decide what group TPE restrictions will be *disabled* for. This
53172 + option is useful if you want TPE restrictions to be applied to most
53173 + users on the system. If the sysctl option is enabled, a sysctl option
53174 + with name "tpe_invert" is created. Unlike other sysctl options, this
53175 + entry will default to on for backward-compatibility.
53176 +
53177 +config GRKERNSEC_TPE_GID
53178 + int
53179 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53180 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53181 +
53182 +config GRKERNSEC_TPE_UNTRUSTED_GID
53183 + int "GID for TPE-untrusted users"
53184 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53185 + default 1005
53186 + help
53187 + Setting this GID determines what group TPE restrictions will be
53188 + *enabled* for. If the sysctl option is enabled, a sysctl option
53189 + with name "tpe_gid" is created.
53190 +
53191 +config GRKERNSEC_TPE_TRUSTED_GID
53192 + int "GID for TPE-trusted users"
53193 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53194 + default 1005
53195 + help
53196 + Setting this GID determines what group TPE restrictions will be
53197 + *disabled* for. If the sysctl option is enabled, a sysctl option
53198 + with name "tpe_gid" is created.
53199 +
53200 +endmenu
53201 +menu "Network Protections"
53202 +depends on GRKERNSEC
53203 +
53204 +config GRKERNSEC_RANDNET
53205 + bool "Larger entropy pools"
53206 + default y if GRKERNSEC_CONFIG_AUTO
53207 + help
53208 + If you say Y here, the entropy pools used for many features of Linux
53209 + and grsecurity will be doubled in size. Since several grsecurity
53210 + features use additional randomness, it is recommended that you say Y
53211 + here. Saying Y here has a similar effect as modifying
53212 + /proc/sys/kernel/random/poolsize.
53213 +
53214 +config GRKERNSEC_BLACKHOLE
53215 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53216 + default y if GRKERNSEC_CONFIG_AUTO
53217 + depends on NET
53218 + help
53219 + If you say Y here, neither TCP resets nor ICMP
53220 + destination-unreachable packets will be sent in response to packets
53221 + sent to ports for which no associated listening process exists.
53222 + This feature supports both IPV4 and IPV6 and exempts the
53223 + loopback interface from blackholing. Enabling this feature
53224 + makes a host more resilient to DoS attacks and reduces network
53225 + visibility against scanners.
53226 +
53227 + The blackhole feature as-implemented is equivalent to the FreeBSD
53228 + blackhole feature, as it prevents RST responses to all packets, not
53229 + just SYNs. Under most application behavior this causes no
53230 + problems, but applications (like haproxy) may not close certain
53231 + connections in a way that cleanly terminates them on the remote
53232 + end, leaving the remote host in LAST_ACK state. Because of this
53233 + side-effect and to prevent intentional LAST_ACK DoSes, this
53234 + feature also adds automatic mitigation against such attacks.
53235 + The mitigation drastically reduces the amount of time a socket
53236 + can spend in LAST_ACK state. If you're using haproxy and not
53237 + all servers it connects to have this option enabled, consider
53238 + disabling this feature on the haproxy host.
53239 +
53240 + If the sysctl option is enabled, two sysctl options with names
53241 + "ip_blackhole" and "lastack_retries" will be created.
53242 + While "ip_blackhole" takes the standard zero/non-zero on/off
53243 + toggle, "lastack_retries" uses the same kinds of values as
53244 + "tcp_retries1" and "tcp_retries2". The default value of 4
53245 + prevents a socket from lasting more than 45 seconds in LAST_ACK
53246 + state.
53247 +
53248 +config GRKERNSEC_NO_SIMULT_CONNECT
53249 + bool "Disable TCP Simultaneous Connect"
53250 + default y if GRKERNSEC_CONFIG_AUTO
53251 + depends on NET
53252 + help
53253 + If you say Y here, a feature by Willy Tarreau will be enabled that
53254 + removes a weakness in Linux's strict implementation of TCP that
53255 + allows two clients to connect to each other without either entering
53256 + a listening state. The weakness allows an attacker to easily prevent
53257 + a client from connecting to a known server provided the source port
53258 + for the connection is guessed correctly.
53259 +
53260 + As the weakness could be used to prevent an antivirus or IPS from
53261 + fetching updates, or prevent an SSL gateway from fetching a CRL,
53262 + it should be eliminated by enabling this option. Though Linux is
53263 + one of few operating systems supporting simultaneous connect, it
53264 + has no legitimate use in practice and is rarely supported by firewalls.
53265 +
53266 +config GRKERNSEC_SOCKET
53267 + bool "Socket restrictions"
53268 + depends on NET
53269 + help
53270 + If you say Y here, you will be able to choose from several options.
53271 + If you assign a GID on your system and add it to the supplementary
53272 + groups of users you want to restrict socket access to, this patch
53273 + will perform up to three things, based on the option(s) you choose.
53274 +
53275 +config GRKERNSEC_SOCKET_ALL
53276 + bool "Deny any sockets to group"
53277 + depends on GRKERNSEC_SOCKET
53278 + help
53279 + If you say Y here, you will be able to choose a GID of whose users will
53280 + be unable to connect to other hosts from your machine or run server
53281 + applications from your machine. If the sysctl option is enabled, a
53282 + sysctl option with name "socket_all" is created.
53283 +
53284 +config GRKERNSEC_SOCKET_ALL_GID
53285 + int "GID to deny all sockets for"
53286 + depends on GRKERNSEC_SOCKET_ALL
53287 + default 1004
53288 + help
53289 + Here you can choose the GID to disable socket access for. Remember to
53290 + add the users you want socket access disabled for to the GID
53291 + specified here. If the sysctl option is enabled, a sysctl option
53292 + with name "socket_all_gid" is created.
53293 +
53294 +config GRKERNSEC_SOCKET_CLIENT
53295 + bool "Deny client sockets to group"
53296 + depends on GRKERNSEC_SOCKET
53297 + help
53298 + If you say Y here, you will be able to choose a GID of whose users will
53299 + be unable to connect to other hosts from your machine, but will be
53300 + able to run servers. If this option is enabled, all users in the group
53301 + you specify will have to use passive mode when initiating ftp transfers
53302 + from the shell on your machine. If the sysctl option is enabled, a
53303 + sysctl option with name "socket_client" is created.
53304 +
53305 +config GRKERNSEC_SOCKET_CLIENT_GID
53306 + int "GID to deny client sockets for"
53307 + depends on GRKERNSEC_SOCKET_CLIENT
53308 + default 1003
53309 + help
53310 + Here you can choose the GID to disable client socket access for.
53311 + Remember to add the users you want client socket access disabled for to
53312 + the GID specified here. If the sysctl option is enabled, a sysctl
53313 + option with name "socket_client_gid" is created.
53314 +
53315 +config GRKERNSEC_SOCKET_SERVER
53316 + bool "Deny server sockets to group"
53317 + depends on GRKERNSEC_SOCKET
53318 + help
53319 + If you say Y here, you will be able to choose a GID of whose users will
53320 + be unable to run server applications from your machine. If the sysctl
53321 + option is enabled, a sysctl option with name "socket_server" is created.
53322 +
53323 +config GRKERNSEC_SOCKET_SERVER_GID
53324 + int "GID to deny server sockets for"
53325 + depends on GRKERNSEC_SOCKET_SERVER
53326 + default 1002
53327 + help
53328 + Here you can choose the GID to disable server socket access for.
53329 + Remember to add the users you want server socket access disabled for to
53330 + the GID specified here. If the sysctl option is enabled, a sysctl
53331 + option with name "socket_server_gid" is created.
53332 +
53333 +endmenu
53334 +menu "Sysctl Support"
53335 +depends on GRKERNSEC && SYSCTL
53336 +
53337 +config GRKERNSEC_SYSCTL
53338 + bool "Sysctl support"
53339 + default y if GRKERNSEC_CONFIG_AUTO
53340 + help
53341 + If you say Y here, you will be able to change the options that
53342 + grsecurity runs with at bootup, without having to recompile your
53343 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53344 + to enable (1) or disable (0) various features. All the sysctl entries
53345 + are mutable until the "grsec_lock" entry is set to a non-zero value.
53346 + All features enabled in the kernel configuration are disabled at boot
53347 + if you do not say Y to the "Turn on features by default" option.
53348 + All options should be set at startup, and the grsec_lock entry should
53349 + be set to a non-zero value after all the options are set.
53350 + *THIS IS EXTREMELY IMPORTANT*
53351 +
53352 +config GRKERNSEC_SYSCTL_DISTRO
53353 + bool "Extra sysctl support for distro makers (READ HELP)"
53354 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53355 + help
53356 + If you say Y here, additional sysctl options will be created
53357 + for features that affect processes running as root. Therefore,
53358 + it is critical when using this option that the grsec_lock entry be
53359 + enabled after boot. Only distros with prebuilt kernel packages
53360 + with this option enabled that can ensure grsec_lock is enabled
53361 + after boot should use this option.
53362 + *Failure to set grsec_lock after boot makes all grsec features
53363 + this option covers useless*
53364 +
53365 + Currently this option creates the following sysctl entries:
53366 + "Disable Privileged I/O": "disable_priv_io"
53367 +
53368 +config GRKERNSEC_SYSCTL_ON
53369 + bool "Turn on features by default"
53370 + default y if GRKERNSEC_CONFIG_AUTO
53371 + depends on GRKERNSEC_SYSCTL
53372 + help
53373 + If you say Y here, instead of having all features enabled in the
53374 + kernel configuration disabled at boot time, the features will be
53375 + enabled at boot time. It is recommended you say Y here unless
53376 + there is some reason you would want all sysctl-tunable features to
53377 + be disabled by default. As mentioned elsewhere, it is important
53378 + to enable the grsec_lock entry once you have finished modifying
53379 + the sysctl entries.
53380 +
53381 +endmenu
53382 +menu "Logging Options"
53383 +depends on GRKERNSEC
53384 +
53385 +config GRKERNSEC_FLOODTIME
53386 + int "Seconds in between log messages (minimum)"
53387 + default 10
53388 + help
53389 + This option allows you to enforce the number of seconds between
53390 + grsecurity log messages. The default should be suitable for most
53391 + people, however, if you choose to change it, choose a value small enough
53392 + to allow informative logs to be produced, but large enough to
53393 + prevent flooding.
53394 +
53395 +config GRKERNSEC_FLOODBURST
53396 + int "Number of messages in a burst (maximum)"
53397 + default 6
53398 + help
53399 + This option allows you to choose the maximum number of messages allowed
53400 + within the flood time interval you chose in a separate option. The
53401 + default should be suitable for most people, however if you find that
53402 + many of your logs are being interpreted as flooding, you may want to
53403 + raise this value.
53404 +
53405 +endmenu
53406 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53407 new file mode 100644
53408 index 0000000..1b9afa9
53409 --- /dev/null
53410 +++ b/grsecurity/Makefile
53411 @@ -0,0 +1,38 @@
53412 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53413 +# during 2001-2009 it has been completely redesigned by Brad Spengler
53414 +# into an RBAC system
53415 +#
53416 +# All code in this directory and various hooks inserted throughout the kernel
53417 +# are copyright Brad Spengler - Open Source Security, Inc., and released
53418 +# under the GPL v2 or higher
53419 +
53420 +KBUILD_CFLAGS += -Werror
53421 +
53422 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53423 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
53424 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53425 +
53426 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53427 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53428 + gracl_learn.o grsec_log.o
53429 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53430 +
53431 +ifdef CONFIG_NET
53432 +obj-y += grsec_sock.o
53433 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53434 +endif
53435 +
53436 +ifndef CONFIG_GRKERNSEC
53437 +obj-y += grsec_disabled.o
53438 +endif
53439 +
53440 +ifdef CONFIG_GRKERNSEC_HIDESYM
53441 +extra-y := grsec_hidesym.o
53442 +$(obj)/grsec_hidesym.o:
53443 + @-chmod -f 500 /boot
53444 + @-chmod -f 500 /lib/modules
53445 + @-chmod -f 500 /lib64/modules
53446 + @-chmod -f 500 /lib32/modules
53447 + @-chmod -f 700 .
53448 + @echo ' grsec: protected kernel image paths'
53449 +endif
53450 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53451 new file mode 100644
53452 index 0000000..960766a
53453 --- /dev/null
53454 +++ b/grsecurity/gracl.c
53455 @@ -0,0 +1,4003 @@
53456 +#include <linux/kernel.h>
53457 +#include <linux/module.h>
53458 +#include <linux/sched.h>
53459 +#include <linux/mm.h>
53460 +#include <linux/file.h>
53461 +#include <linux/fs.h>
53462 +#include <linux/namei.h>
53463 +#include <linux/mount.h>
53464 +#include <linux/tty.h>
53465 +#include <linux/proc_fs.h>
53466 +#include <linux/lglock.h>
53467 +#include <linux/slab.h>
53468 +#include <linux/vmalloc.h>
53469 +#include <linux/types.h>
53470 +#include <linux/sysctl.h>
53471 +#include <linux/netdevice.h>
53472 +#include <linux/ptrace.h>
53473 +#include <linux/gracl.h>
53474 +#include <linux/gralloc.h>
53475 +#include <linux/security.h>
53476 +#include <linux/grinternal.h>
53477 +#include <linux/pid_namespace.h>
53478 +#include <linux/stop_machine.h>
53479 +#include <linux/fdtable.h>
53480 +#include <linux/percpu.h>
53481 +#include <linux/lglock.h>
53482 +#include "../fs/mount.h"
53483 +
53484 +#include <asm/uaccess.h>
53485 +#include <asm/errno.h>
53486 +#include <asm/mman.h>
53487 +
53488 +extern struct lglock vfsmount_lock;
53489 +
53490 +static struct acl_role_db acl_role_set;
53491 +static struct name_db name_set;
53492 +static struct inodev_db inodev_set;
53493 +
53494 +/* for keeping track of userspace pointers used for subjects, so we
53495 + can share references in the kernel as well
53496 +*/
53497 +
53498 +static struct path real_root;
53499 +
53500 +static struct acl_subj_map_db subj_map_set;
53501 +
53502 +static struct acl_role_label *default_role;
53503 +
53504 +static struct acl_role_label *role_list;
53505 +
53506 +static u16 acl_sp_role_value;
53507 +
53508 +extern char *gr_shared_page[4];
53509 +static DEFINE_MUTEX(gr_dev_mutex);
53510 +DEFINE_RWLOCK(gr_inode_lock);
53511 +
53512 +struct gr_arg *gr_usermode;
53513 +
53514 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
53515 +
53516 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53517 +extern void gr_clear_learn_entries(void);
53518 +
53519 +unsigned char *gr_system_salt;
53520 +unsigned char *gr_system_sum;
53521 +
53522 +static struct sprole_pw **acl_special_roles = NULL;
53523 +static __u16 num_sprole_pws = 0;
53524 +
53525 +static struct acl_role_label *kernel_role = NULL;
53526 +
53527 +static unsigned int gr_auth_attempts = 0;
53528 +static unsigned long gr_auth_expires = 0UL;
53529 +
53530 +#ifdef CONFIG_NET
53531 +extern struct vfsmount *sock_mnt;
53532 +#endif
53533 +
53534 +extern struct vfsmount *pipe_mnt;
53535 +extern struct vfsmount *shm_mnt;
53536 +#ifdef CONFIG_HUGETLBFS
53537 +extern struct vfsmount *hugetlbfs_vfsmount;
53538 +#endif
53539 +
53540 +static struct acl_object_label *fakefs_obj_rw;
53541 +static struct acl_object_label *fakefs_obj_rwx;
53542 +
53543 +extern int gr_init_uidset(void);
53544 +extern void gr_free_uidset(void);
53545 +extern void gr_remove_uid(uid_t uid);
53546 +extern int gr_find_uid(uid_t uid);
53547 +
53548 +__inline__ int
53549 +gr_acl_is_enabled(void)
53550 +{
53551 + return (gr_status & GR_READY);
53552 +}
53553 +
53554 +#ifdef CONFIG_BTRFS_FS
53555 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53556 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53557 +#endif
53558 +
53559 +static inline dev_t __get_dev(const struct dentry *dentry)
53560 +{
53561 +#ifdef CONFIG_BTRFS_FS
53562 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53563 + return get_btrfs_dev_from_inode(dentry->d_inode);
53564 + else
53565 +#endif
53566 + return dentry->d_inode->i_sb->s_dev;
53567 +}
53568 +
53569 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53570 +{
53571 + return __get_dev(dentry);
53572 +}
53573 +
53574 +static char gr_task_roletype_to_char(struct task_struct *task)
53575 +{
53576 + switch (task->role->roletype &
53577 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53578 + GR_ROLE_SPECIAL)) {
53579 + case GR_ROLE_DEFAULT:
53580 + return 'D';
53581 + case GR_ROLE_USER:
53582 + return 'U';
53583 + case GR_ROLE_GROUP:
53584 + return 'G';
53585 + case GR_ROLE_SPECIAL:
53586 + return 'S';
53587 + }
53588 +
53589 + return 'X';
53590 +}
53591 +
53592 +char gr_roletype_to_char(void)
53593 +{
53594 + return gr_task_roletype_to_char(current);
53595 +}
53596 +
53597 +__inline__ int
53598 +gr_acl_tpe_check(void)
53599 +{
53600 + if (unlikely(!(gr_status & GR_READY)))
53601 + return 0;
53602 + if (current->role->roletype & GR_ROLE_TPE)
53603 + return 1;
53604 + else
53605 + return 0;
53606 +}
53607 +
53608 +int
53609 +gr_handle_rawio(const struct inode *inode)
53610 +{
53611 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53612 + if (inode && S_ISBLK(inode->i_mode) &&
53613 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53614 + !capable(CAP_SYS_RAWIO))
53615 + return 1;
53616 +#endif
53617 + return 0;
53618 +}
53619 +
53620 +static int
53621 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53622 +{
53623 + if (likely(lena != lenb))
53624 + return 0;
53625 +
53626 + return !memcmp(a, b, lena);
53627 +}
53628 +
53629 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53630 +{
53631 + *buflen -= namelen;
53632 + if (*buflen < 0)
53633 + return -ENAMETOOLONG;
53634 + *buffer -= namelen;
53635 + memcpy(*buffer, str, namelen);
53636 + return 0;
53637 +}
53638 +
53639 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53640 +{
53641 + return prepend(buffer, buflen, name->name, name->len);
53642 +}
53643 +
53644 +static int prepend_path(const struct path *path, struct path *root,
53645 + char **buffer, int *buflen)
53646 +{
53647 + struct dentry *dentry = path->dentry;
53648 + struct vfsmount *vfsmnt = path->mnt;
53649 + struct mount *mnt = real_mount(vfsmnt);
53650 + bool slash = false;
53651 + int error = 0;
53652 +
53653 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53654 + struct dentry * parent;
53655 +
53656 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53657 + /* Global root? */
53658 + if (!mnt_has_parent(mnt)) {
53659 + goto out;
53660 + }
53661 + dentry = mnt->mnt_mountpoint;
53662 + mnt = mnt->mnt_parent;
53663 + vfsmnt = &mnt->mnt;
53664 + continue;
53665 + }
53666 + parent = dentry->d_parent;
53667 + prefetch(parent);
53668 + spin_lock(&dentry->d_lock);
53669 + error = prepend_name(buffer, buflen, &dentry->d_name);
53670 + spin_unlock(&dentry->d_lock);
53671 + if (!error)
53672 + error = prepend(buffer, buflen, "/", 1);
53673 + if (error)
53674 + break;
53675 +
53676 + slash = true;
53677 + dentry = parent;
53678 + }
53679 +
53680 +out:
53681 + if (!error && !slash)
53682 + error = prepend(buffer, buflen, "/", 1);
53683 +
53684 + return error;
53685 +}
53686 +
53687 +/* this must be called with vfsmount_lock and rename_lock held */
53688 +
53689 +static char *__our_d_path(const struct path *path, struct path *root,
53690 + char *buf, int buflen)
53691 +{
53692 + char *res = buf + buflen;
53693 + int error;
53694 +
53695 + prepend(&res, &buflen, "\0", 1);
53696 + error = prepend_path(path, root, &res, &buflen);
53697 + if (error)
53698 + return ERR_PTR(error);
53699 +
53700 + return res;
53701 +}
53702 +
53703 +static char *
53704 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53705 +{
53706 + char *retval;
53707 +
53708 + retval = __our_d_path(path, root, buf, buflen);
53709 + if (unlikely(IS_ERR(retval)))
53710 + retval = strcpy(buf, "<path too long>");
53711 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53712 + retval[1] = '\0';
53713 +
53714 + return retval;
53715 +}
53716 +
53717 +static char *
53718 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53719 + char *buf, int buflen)
53720 +{
53721 + struct path path;
53722 + char *res;
53723 +
53724 + path.dentry = (struct dentry *)dentry;
53725 + path.mnt = (struct vfsmount *)vfsmnt;
53726 +
53727 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53728 + by the RBAC system */
53729 + res = gen_full_path(&path, &real_root, buf, buflen);
53730 +
53731 + return res;
53732 +}
53733 +
53734 +static char *
53735 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53736 + char *buf, int buflen)
53737 +{
53738 + char *res;
53739 + struct path path;
53740 + struct path root;
53741 + struct task_struct *reaper = init_pid_ns.child_reaper;
53742 +
53743 + path.dentry = (struct dentry *)dentry;
53744 + path.mnt = (struct vfsmount *)vfsmnt;
53745 +
53746 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53747 + get_fs_root(reaper->fs, &root);
53748 +
53749 + write_seqlock(&rename_lock);
53750 + br_read_lock(&vfsmount_lock);
53751 + res = gen_full_path(&path, &root, buf, buflen);
53752 + br_read_unlock(&vfsmount_lock);
53753 + write_sequnlock(&rename_lock);
53754 +
53755 + path_put(&root);
53756 + return res;
53757 +}
53758 +
53759 +static char *
53760 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53761 +{
53762 + char *ret;
53763 + write_seqlock(&rename_lock);
53764 + br_read_lock(&vfsmount_lock);
53765 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53766 + PAGE_SIZE);
53767 + br_read_unlock(&vfsmount_lock);
53768 + write_sequnlock(&rename_lock);
53769 + return ret;
53770 +}
53771 +
53772 +static char *
53773 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53774 +{
53775 + char *ret;
53776 + char *buf;
53777 + int buflen;
53778 +
53779 + write_seqlock(&rename_lock);
53780 + br_read_lock(&vfsmount_lock);
53781 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53782 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53783 + buflen = (int)(ret - buf);
53784 + if (buflen >= 5)
53785 + prepend(&ret, &buflen, "/proc", 5);
53786 + else
53787 + ret = strcpy(buf, "<path too long>");
53788 + br_read_unlock(&vfsmount_lock);
53789 + write_sequnlock(&rename_lock);
53790 + return ret;
53791 +}
53792 +
53793 +char *
53794 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53795 +{
53796 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53797 + PAGE_SIZE);
53798 +}
53799 +
53800 +char *
53801 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53802 +{
53803 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53804 + PAGE_SIZE);
53805 +}
53806 +
53807 +char *
53808 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53809 +{
53810 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53811 + PAGE_SIZE);
53812 +}
53813 +
53814 +char *
53815 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53816 +{
53817 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53818 + PAGE_SIZE);
53819 +}
53820 +
53821 +char *
53822 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53823 +{
53824 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53825 + PAGE_SIZE);
53826 +}
53827 +
53828 +__inline__ __u32
53829 +to_gr_audit(const __u32 reqmode)
53830 +{
53831 + /* masks off auditable permission flags, then shifts them to create
53832 + auditing flags, and adds the special case of append auditing if
53833 + we're requesting write */
53834 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53835 +}
53836 +
53837 +struct acl_subject_label *
53838 +lookup_subject_map(const struct acl_subject_label *userp)
53839 +{
53840 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
53841 + struct subject_map *match;
53842 +
53843 + match = subj_map_set.s_hash[index];
53844 +
53845 + while (match && match->user != userp)
53846 + match = match->next;
53847 +
53848 + if (match != NULL)
53849 + return match->kernel;
53850 + else
53851 + return NULL;
53852 +}
53853 +
53854 +static void
53855 +insert_subj_map_entry(struct subject_map *subjmap)
53856 +{
53857 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53858 + struct subject_map **curr;
53859 +
53860 + subjmap->prev = NULL;
53861 +
53862 + curr = &subj_map_set.s_hash[index];
53863 + if (*curr != NULL)
53864 + (*curr)->prev = subjmap;
53865 +
53866 + subjmap->next = *curr;
53867 + *curr = subjmap;
53868 +
53869 + return;
53870 +}
53871 +
53872 +static struct acl_role_label *
53873 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53874 + const gid_t gid)
53875 +{
53876 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53877 + struct acl_role_label *match;
53878 + struct role_allowed_ip *ipp;
53879 + unsigned int x;
53880 + u32 curr_ip = task->signal->curr_ip;
53881 +
53882 + task->signal->saved_ip = curr_ip;
53883 +
53884 + match = acl_role_set.r_hash[index];
53885 +
53886 + while (match) {
53887 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53888 + for (x = 0; x < match->domain_child_num; x++) {
53889 + if (match->domain_children[x] == uid)
53890 + goto found;
53891 + }
53892 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
53893 + break;
53894 + match = match->next;
53895 + }
53896 +found:
53897 + if (match == NULL) {
53898 + try_group:
53899 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
53900 + match = acl_role_set.r_hash[index];
53901 +
53902 + while (match) {
53903 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
53904 + for (x = 0; x < match->domain_child_num; x++) {
53905 + if (match->domain_children[x] == gid)
53906 + goto found2;
53907 + }
53908 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
53909 + break;
53910 + match = match->next;
53911 + }
53912 +found2:
53913 + if (match == NULL)
53914 + match = default_role;
53915 + if (match->allowed_ips == NULL)
53916 + return match;
53917 + else {
53918 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53919 + if (likely
53920 + ((ntohl(curr_ip) & ipp->netmask) ==
53921 + (ntohl(ipp->addr) & ipp->netmask)))
53922 + return match;
53923 + }
53924 + match = default_role;
53925 + }
53926 + } else if (match->allowed_ips == NULL) {
53927 + return match;
53928 + } else {
53929 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53930 + if (likely
53931 + ((ntohl(curr_ip) & ipp->netmask) ==
53932 + (ntohl(ipp->addr) & ipp->netmask)))
53933 + return match;
53934 + }
53935 + goto try_group;
53936 + }
53937 +
53938 + return match;
53939 +}
53940 +
53941 +struct acl_subject_label *
53942 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
53943 + const struct acl_role_label *role)
53944 +{
53945 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53946 + struct acl_subject_label *match;
53947 +
53948 + match = role->subj_hash[index];
53949 +
53950 + while (match && (match->inode != ino || match->device != dev ||
53951 + (match->mode & GR_DELETED))) {
53952 + match = match->next;
53953 + }
53954 +
53955 + if (match && !(match->mode & GR_DELETED))
53956 + return match;
53957 + else
53958 + return NULL;
53959 +}
53960 +
53961 +struct acl_subject_label *
53962 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
53963 + const struct acl_role_label *role)
53964 +{
53965 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53966 + struct acl_subject_label *match;
53967 +
53968 + match = role->subj_hash[index];
53969 +
53970 + while (match && (match->inode != ino || match->device != dev ||
53971 + !(match->mode & GR_DELETED))) {
53972 + match = match->next;
53973 + }
53974 +
53975 + if (match && (match->mode & GR_DELETED))
53976 + return match;
53977 + else
53978 + return NULL;
53979 +}
53980 +
53981 +static struct acl_object_label *
53982 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
53983 + const struct acl_subject_label *subj)
53984 +{
53985 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53986 + struct acl_object_label *match;
53987 +
53988 + match = subj->obj_hash[index];
53989 +
53990 + while (match && (match->inode != ino || match->device != dev ||
53991 + (match->mode & GR_DELETED))) {
53992 + match = match->next;
53993 + }
53994 +
53995 + if (match && !(match->mode & GR_DELETED))
53996 + return match;
53997 + else
53998 + return NULL;
53999 +}
54000 +
54001 +static struct acl_object_label *
54002 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54003 + const struct acl_subject_label *subj)
54004 +{
54005 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54006 + struct acl_object_label *match;
54007 +
54008 + match = subj->obj_hash[index];
54009 +
54010 + while (match && (match->inode != ino || match->device != dev ||
54011 + !(match->mode & GR_DELETED))) {
54012 + match = match->next;
54013 + }
54014 +
54015 + if (match && (match->mode & GR_DELETED))
54016 + return match;
54017 +
54018 + match = subj->obj_hash[index];
54019 +
54020 + while (match && (match->inode != ino || match->device != dev ||
54021 + (match->mode & GR_DELETED))) {
54022 + match = match->next;
54023 + }
54024 +
54025 + if (match && !(match->mode & GR_DELETED))
54026 + return match;
54027 + else
54028 + return NULL;
54029 +}
54030 +
54031 +static struct name_entry *
54032 +lookup_name_entry(const char *name)
54033 +{
54034 + unsigned int len = strlen(name);
54035 + unsigned int key = full_name_hash(name, len);
54036 + unsigned int index = key % name_set.n_size;
54037 + struct name_entry *match;
54038 +
54039 + match = name_set.n_hash[index];
54040 +
54041 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54042 + match = match->next;
54043 +
54044 + return match;
54045 +}
54046 +
54047 +static struct name_entry *
54048 +lookup_name_entry_create(const char *name)
54049 +{
54050 + unsigned int len = strlen(name);
54051 + unsigned int key = full_name_hash(name, len);
54052 + unsigned int index = key % name_set.n_size;
54053 + struct name_entry *match;
54054 +
54055 + match = name_set.n_hash[index];
54056 +
54057 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54058 + !match->deleted))
54059 + match = match->next;
54060 +
54061 + if (match && match->deleted)
54062 + return match;
54063 +
54064 + match = name_set.n_hash[index];
54065 +
54066 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54067 + match->deleted))
54068 + match = match->next;
54069 +
54070 + if (match && !match->deleted)
54071 + return match;
54072 + else
54073 + return NULL;
54074 +}
54075 +
54076 +static struct inodev_entry *
54077 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
54078 +{
54079 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54080 + struct inodev_entry *match;
54081 +
54082 + match = inodev_set.i_hash[index];
54083 +
54084 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54085 + match = match->next;
54086 +
54087 + return match;
54088 +}
54089 +
54090 +static void
54091 +insert_inodev_entry(struct inodev_entry *entry)
54092 +{
54093 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54094 + inodev_set.i_size);
54095 + struct inodev_entry **curr;
54096 +
54097 + entry->prev = NULL;
54098 +
54099 + curr = &inodev_set.i_hash[index];
54100 + if (*curr != NULL)
54101 + (*curr)->prev = entry;
54102 +
54103 + entry->next = *curr;
54104 + *curr = entry;
54105 +
54106 + return;
54107 +}
54108 +
54109 +static void
54110 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
54111 +{
54112 + unsigned int index =
54113 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
54114 + struct acl_role_label **curr;
54115 + struct acl_role_label *tmp, *tmp2;
54116 +
54117 + curr = &acl_role_set.r_hash[index];
54118 +
54119 + /* simple case, slot is empty, just set it to our role */
54120 + if (*curr == NULL) {
54121 + *curr = role;
54122 + } else {
54123 + /* example:
54124 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
54125 + 2 -> 3
54126 + */
54127 + /* first check to see if we can already be reached via this slot */
54128 + tmp = *curr;
54129 + while (tmp && tmp != role)
54130 + tmp = tmp->next;
54131 + if (tmp == role) {
54132 + /* we don't need to add ourselves to this slot's chain */
54133 + return;
54134 + }
54135 + /* we need to add ourselves to this chain, two cases */
54136 + if (role->next == NULL) {
54137 + /* simple case, append the current chain to our role */
54138 + role->next = *curr;
54139 + *curr = role;
54140 + } else {
54141 + /* 1 -> 2 -> 3 -> 4
54142 + 2 -> 3 -> 4
54143 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54144 + */
54145 + /* trickier case: walk our role's chain until we find
54146 + the role for the start of the current slot's chain */
54147 + tmp = role;
54148 + tmp2 = *curr;
54149 + while (tmp->next && tmp->next != tmp2)
54150 + tmp = tmp->next;
54151 + if (tmp->next == tmp2) {
54152 + /* from example above, we found 3, so just
54153 + replace this slot's chain with ours */
54154 + *curr = role;
54155 + } else {
54156 + /* we didn't find a subset of our role's chain
54157 + in the current slot's chain, so append their
54158 + chain to ours, and set us as the first role in
54159 + the slot's chain
54160 +
54161 + we could fold this case with the case above,
54162 + but making it explicit for clarity
54163 + */
54164 + tmp->next = tmp2;
54165 + *curr = role;
54166 + }
54167 + }
54168 + }
54169 +
54170 + return;
54171 +}
54172 +
54173 +static void
54174 +insert_acl_role_label(struct acl_role_label *role)
54175 +{
54176 + int i;
54177 +
54178 + if (role_list == NULL) {
54179 + role_list = role;
54180 + role->prev = NULL;
54181 + } else {
54182 + role->prev = role_list;
54183 + role_list = role;
54184 + }
54185 +
54186 + /* used for hash chains */
54187 + role->next = NULL;
54188 +
54189 + if (role->roletype & GR_ROLE_DOMAIN) {
54190 + for (i = 0; i < role->domain_child_num; i++)
54191 + __insert_acl_role_label(role, role->domain_children[i]);
54192 + } else
54193 + __insert_acl_role_label(role, role->uidgid);
54194 +}
54195 +
54196 +static int
54197 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54198 +{
54199 + struct name_entry **curr, *nentry;
54200 + struct inodev_entry *ientry;
54201 + unsigned int len = strlen(name);
54202 + unsigned int key = full_name_hash(name, len);
54203 + unsigned int index = key % name_set.n_size;
54204 +
54205 + curr = &name_set.n_hash[index];
54206 +
54207 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54208 + curr = &((*curr)->next);
54209 +
54210 + if (*curr != NULL)
54211 + return 1;
54212 +
54213 + nentry = acl_alloc(sizeof (struct name_entry));
54214 + if (nentry == NULL)
54215 + return 0;
54216 + ientry = acl_alloc(sizeof (struct inodev_entry));
54217 + if (ientry == NULL)
54218 + return 0;
54219 + ientry->nentry = nentry;
54220 +
54221 + nentry->key = key;
54222 + nentry->name = name;
54223 + nentry->inode = inode;
54224 + nentry->device = device;
54225 + nentry->len = len;
54226 + nentry->deleted = deleted;
54227 +
54228 + nentry->prev = NULL;
54229 + curr = &name_set.n_hash[index];
54230 + if (*curr != NULL)
54231 + (*curr)->prev = nentry;
54232 + nentry->next = *curr;
54233 + *curr = nentry;
54234 +
54235 + /* insert us into the table searchable by inode/dev */
54236 + insert_inodev_entry(ientry);
54237 +
54238 + return 1;
54239 +}
54240 +
54241 +static void
54242 +insert_acl_obj_label(struct acl_object_label *obj,
54243 + struct acl_subject_label *subj)
54244 +{
54245 + unsigned int index =
54246 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54247 + struct acl_object_label **curr;
54248 +
54249 +
54250 + obj->prev = NULL;
54251 +
54252 + curr = &subj->obj_hash[index];
54253 + if (*curr != NULL)
54254 + (*curr)->prev = obj;
54255 +
54256 + obj->next = *curr;
54257 + *curr = obj;
54258 +
54259 + return;
54260 +}
54261 +
54262 +static void
54263 +insert_acl_subj_label(struct acl_subject_label *obj,
54264 + struct acl_role_label *role)
54265 +{
54266 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54267 + struct acl_subject_label **curr;
54268 +
54269 + obj->prev = NULL;
54270 +
54271 + curr = &role->subj_hash[index];
54272 + if (*curr != NULL)
54273 + (*curr)->prev = obj;
54274 +
54275 + obj->next = *curr;
54276 + *curr = obj;
54277 +
54278 + return;
54279 +}
54280 +
54281 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54282 +
54283 +static void *
54284 +create_table(__u32 * len, int elementsize)
54285 +{
54286 + unsigned int table_sizes[] = {
54287 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54288 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54289 + 4194301, 8388593, 16777213, 33554393, 67108859
54290 + };
54291 + void *newtable = NULL;
54292 + unsigned int pwr = 0;
54293 +
54294 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54295 + table_sizes[pwr] <= *len)
54296 + pwr++;
54297 +
54298 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54299 + return newtable;
54300 +
54301 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54302 + newtable =
54303 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54304 + else
54305 + newtable = vmalloc(table_sizes[pwr] * elementsize);
54306 +
54307 + *len = table_sizes[pwr];
54308 +
54309 + return newtable;
54310 +}
54311 +
54312 +static int
54313 +init_variables(const struct gr_arg *arg)
54314 +{
54315 + struct task_struct *reaper = init_pid_ns.child_reaper;
54316 + unsigned int stacksize;
54317 +
54318 + subj_map_set.s_size = arg->role_db.num_subjects;
54319 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54320 + name_set.n_size = arg->role_db.num_objects;
54321 + inodev_set.i_size = arg->role_db.num_objects;
54322 +
54323 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
54324 + !name_set.n_size || !inodev_set.i_size)
54325 + return 1;
54326 +
54327 + if (!gr_init_uidset())
54328 + return 1;
54329 +
54330 + /* set up the stack that holds allocation info */
54331 +
54332 + stacksize = arg->role_db.num_pointers + 5;
54333 +
54334 + if (!acl_alloc_stack_init(stacksize))
54335 + return 1;
54336 +
54337 + /* grab reference for the real root dentry and vfsmount */
54338 + get_fs_root(reaper->fs, &real_root);
54339 +
54340 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54341 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54342 +#endif
54343 +
54344 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54345 + if (fakefs_obj_rw == NULL)
54346 + return 1;
54347 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54348 +
54349 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54350 + if (fakefs_obj_rwx == NULL)
54351 + return 1;
54352 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54353 +
54354 + subj_map_set.s_hash =
54355 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54356 + acl_role_set.r_hash =
54357 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54358 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54359 + inodev_set.i_hash =
54360 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54361 +
54362 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54363 + !name_set.n_hash || !inodev_set.i_hash)
54364 + return 1;
54365 +
54366 + memset(subj_map_set.s_hash, 0,
54367 + sizeof(struct subject_map *) * subj_map_set.s_size);
54368 + memset(acl_role_set.r_hash, 0,
54369 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
54370 + memset(name_set.n_hash, 0,
54371 + sizeof (struct name_entry *) * name_set.n_size);
54372 + memset(inodev_set.i_hash, 0,
54373 + sizeof (struct inodev_entry *) * inodev_set.i_size);
54374 +
54375 + return 0;
54376 +}
54377 +
54378 +/* free information not needed after startup
54379 + currently contains user->kernel pointer mappings for subjects
54380 +*/
54381 +
54382 +static void
54383 +free_init_variables(void)
54384 +{
54385 + __u32 i;
54386 +
54387 + if (subj_map_set.s_hash) {
54388 + for (i = 0; i < subj_map_set.s_size; i++) {
54389 + if (subj_map_set.s_hash[i]) {
54390 + kfree(subj_map_set.s_hash[i]);
54391 + subj_map_set.s_hash[i] = NULL;
54392 + }
54393 + }
54394 +
54395 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54396 + PAGE_SIZE)
54397 + kfree(subj_map_set.s_hash);
54398 + else
54399 + vfree(subj_map_set.s_hash);
54400 + }
54401 +
54402 + return;
54403 +}
54404 +
54405 +static void
54406 +free_variables(void)
54407 +{
54408 + struct acl_subject_label *s;
54409 + struct acl_role_label *r;
54410 + struct task_struct *task, *task2;
54411 + unsigned int x;
54412 +
54413 + gr_clear_learn_entries();
54414 +
54415 + read_lock(&tasklist_lock);
54416 + do_each_thread(task2, task) {
54417 + task->acl_sp_role = 0;
54418 + task->acl_role_id = 0;
54419 + task->acl = NULL;
54420 + task->role = NULL;
54421 + } while_each_thread(task2, task);
54422 + read_unlock(&tasklist_lock);
54423 +
54424 + /* release the reference to the real root dentry and vfsmount */
54425 + path_put(&real_root);
54426 + memset(&real_root, 0, sizeof(real_root));
54427 +
54428 + /* free all object hash tables */
54429 +
54430 + FOR_EACH_ROLE_START(r)
54431 + if (r->subj_hash == NULL)
54432 + goto next_role;
54433 + FOR_EACH_SUBJECT_START(r, s, x)
54434 + if (s->obj_hash == NULL)
54435 + break;
54436 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54437 + kfree(s->obj_hash);
54438 + else
54439 + vfree(s->obj_hash);
54440 + FOR_EACH_SUBJECT_END(s, x)
54441 + FOR_EACH_NESTED_SUBJECT_START(r, s)
54442 + if (s->obj_hash == NULL)
54443 + break;
54444 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54445 + kfree(s->obj_hash);
54446 + else
54447 + vfree(s->obj_hash);
54448 + FOR_EACH_NESTED_SUBJECT_END(s)
54449 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54450 + kfree(r->subj_hash);
54451 + else
54452 + vfree(r->subj_hash);
54453 + r->subj_hash = NULL;
54454 +next_role:
54455 + FOR_EACH_ROLE_END(r)
54456 +
54457 + acl_free_all();
54458 +
54459 + if (acl_role_set.r_hash) {
54460 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54461 + PAGE_SIZE)
54462 + kfree(acl_role_set.r_hash);
54463 + else
54464 + vfree(acl_role_set.r_hash);
54465 + }
54466 + if (name_set.n_hash) {
54467 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
54468 + PAGE_SIZE)
54469 + kfree(name_set.n_hash);
54470 + else
54471 + vfree(name_set.n_hash);
54472 + }
54473 +
54474 + if (inodev_set.i_hash) {
54475 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54476 + PAGE_SIZE)
54477 + kfree(inodev_set.i_hash);
54478 + else
54479 + vfree(inodev_set.i_hash);
54480 + }
54481 +
54482 + gr_free_uidset();
54483 +
54484 + memset(&name_set, 0, sizeof (struct name_db));
54485 + memset(&inodev_set, 0, sizeof (struct inodev_db));
54486 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54487 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54488 +
54489 + default_role = NULL;
54490 + kernel_role = NULL;
54491 + role_list = NULL;
54492 +
54493 + return;
54494 +}
54495 +
54496 +static __u32
54497 +count_user_objs(struct acl_object_label *userp)
54498 +{
54499 + struct acl_object_label o_tmp;
54500 + __u32 num = 0;
54501 +
54502 + while (userp) {
54503 + if (copy_from_user(&o_tmp, userp,
54504 + sizeof (struct acl_object_label)))
54505 + break;
54506 +
54507 + userp = o_tmp.prev;
54508 + num++;
54509 + }
54510 +
54511 + return num;
54512 +}
54513 +
54514 +static struct acl_subject_label *
54515 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54516 +
54517 +static int
54518 +copy_user_glob(struct acl_object_label *obj)
54519 +{
54520 + struct acl_object_label *g_tmp, **guser;
54521 + unsigned int len;
54522 + char *tmp;
54523 +
54524 + if (obj->globbed == NULL)
54525 + return 0;
54526 +
54527 + guser = &obj->globbed;
54528 + while (*guser) {
54529 + g_tmp = (struct acl_object_label *)
54530 + acl_alloc(sizeof (struct acl_object_label));
54531 + if (g_tmp == NULL)
54532 + return -ENOMEM;
54533 +
54534 + if (copy_from_user(g_tmp, *guser,
54535 + sizeof (struct acl_object_label)))
54536 + return -EFAULT;
54537 +
54538 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54539 +
54540 + if (!len || len >= PATH_MAX)
54541 + return -EINVAL;
54542 +
54543 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54544 + return -ENOMEM;
54545 +
54546 + if (copy_from_user(tmp, g_tmp->filename, len))
54547 + return -EFAULT;
54548 + tmp[len-1] = '\0';
54549 + g_tmp->filename = tmp;
54550 +
54551 + *guser = g_tmp;
54552 + guser = &(g_tmp->next);
54553 + }
54554 +
54555 + return 0;
54556 +}
54557 +
54558 +static int
54559 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54560 + struct acl_role_label *role)
54561 +{
54562 + struct acl_object_label *o_tmp;
54563 + unsigned int len;
54564 + int ret;
54565 + char *tmp;
54566 +
54567 + while (userp) {
54568 + if ((o_tmp = (struct acl_object_label *)
54569 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54570 + return -ENOMEM;
54571 +
54572 + if (copy_from_user(o_tmp, userp,
54573 + sizeof (struct acl_object_label)))
54574 + return -EFAULT;
54575 +
54576 + userp = o_tmp->prev;
54577 +
54578 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54579 +
54580 + if (!len || len >= PATH_MAX)
54581 + return -EINVAL;
54582 +
54583 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54584 + return -ENOMEM;
54585 +
54586 + if (copy_from_user(tmp, o_tmp->filename, len))
54587 + return -EFAULT;
54588 + tmp[len-1] = '\0';
54589 + o_tmp->filename = tmp;
54590 +
54591 + insert_acl_obj_label(o_tmp, subj);
54592 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54593 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54594 + return -ENOMEM;
54595 +
54596 + ret = copy_user_glob(o_tmp);
54597 + if (ret)
54598 + return ret;
54599 +
54600 + if (o_tmp->nested) {
54601 + int already_copied;
54602 +
54603 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54604 + if (IS_ERR(o_tmp->nested))
54605 + return PTR_ERR(o_tmp->nested);
54606 +
54607 + /* insert into nested subject list if we haven't copied this one yet
54608 + to prevent duplicate entries */
54609 + if (!already_copied) {
54610 + o_tmp->nested->next = role->hash->first;
54611 + role->hash->first = o_tmp->nested;
54612 + }
54613 + }
54614 + }
54615 +
54616 + return 0;
54617 +}
54618 +
54619 +static __u32
54620 +count_user_subjs(struct acl_subject_label *userp)
54621 +{
54622 + struct acl_subject_label s_tmp;
54623 + __u32 num = 0;
54624 +
54625 + while (userp) {
54626 + if (copy_from_user(&s_tmp, userp,
54627 + sizeof (struct acl_subject_label)))
54628 + break;
54629 +
54630 + userp = s_tmp.prev;
54631 + }
54632 +
54633 + return num;
54634 +}
54635 +
54636 +static int
54637 +copy_user_allowedips(struct acl_role_label *rolep)
54638 +{
54639 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54640 +
54641 + ruserip = rolep->allowed_ips;
54642 +
54643 + while (ruserip) {
54644 + rlast = rtmp;
54645 +
54646 + if ((rtmp = (struct role_allowed_ip *)
54647 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54648 + return -ENOMEM;
54649 +
54650 + if (copy_from_user(rtmp, ruserip,
54651 + sizeof (struct role_allowed_ip)))
54652 + return -EFAULT;
54653 +
54654 + ruserip = rtmp->prev;
54655 +
54656 + if (!rlast) {
54657 + rtmp->prev = NULL;
54658 + rolep->allowed_ips = rtmp;
54659 + } else {
54660 + rlast->next = rtmp;
54661 + rtmp->prev = rlast;
54662 + }
54663 +
54664 + if (!ruserip)
54665 + rtmp->next = NULL;
54666 + }
54667 +
54668 + return 0;
54669 +}
54670 +
54671 +static int
54672 +copy_user_transitions(struct acl_role_label *rolep)
54673 +{
54674 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54675 +
54676 + unsigned int len;
54677 + char *tmp;
54678 +
54679 + rusertp = rolep->transitions;
54680 +
54681 + while (rusertp) {
54682 + rlast = rtmp;
54683 +
54684 + if ((rtmp = (struct role_transition *)
54685 + acl_alloc(sizeof (struct role_transition))) == NULL)
54686 + return -ENOMEM;
54687 +
54688 + if (copy_from_user(rtmp, rusertp,
54689 + sizeof (struct role_transition)))
54690 + return -EFAULT;
54691 +
54692 + rusertp = rtmp->prev;
54693 +
54694 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54695 +
54696 + if (!len || len >= GR_SPROLE_LEN)
54697 + return -EINVAL;
54698 +
54699 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54700 + return -ENOMEM;
54701 +
54702 + if (copy_from_user(tmp, rtmp->rolename, len))
54703 + return -EFAULT;
54704 + tmp[len-1] = '\0';
54705 + rtmp->rolename = tmp;
54706 +
54707 + if (!rlast) {
54708 + rtmp->prev = NULL;
54709 + rolep->transitions = rtmp;
54710 + } else {
54711 + rlast->next = rtmp;
54712 + rtmp->prev = rlast;
54713 + }
54714 +
54715 + if (!rusertp)
54716 + rtmp->next = NULL;
54717 + }
54718 +
54719 + return 0;
54720 +}
54721 +
54722 +static struct acl_subject_label *
54723 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54724 +{
54725 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54726 + unsigned int len;
54727 + char *tmp;
54728 + __u32 num_objs;
54729 + struct acl_ip_label **i_tmp, *i_utmp2;
54730 + struct gr_hash_struct ghash;
54731 + struct subject_map *subjmap;
54732 + unsigned int i_num;
54733 + int err;
54734 +
54735 + if (already_copied != NULL)
54736 + *already_copied = 0;
54737 +
54738 + s_tmp = lookup_subject_map(userp);
54739 +
54740 + /* we've already copied this subject into the kernel, just return
54741 + the reference to it, and don't copy it over again
54742 + */
54743 + if (s_tmp) {
54744 + if (already_copied != NULL)
54745 + *already_copied = 1;
54746 + return(s_tmp);
54747 + }
54748 +
54749 + if ((s_tmp = (struct acl_subject_label *)
54750 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54751 + return ERR_PTR(-ENOMEM);
54752 +
54753 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54754 + if (subjmap == NULL)
54755 + return ERR_PTR(-ENOMEM);
54756 +
54757 + subjmap->user = userp;
54758 + subjmap->kernel = s_tmp;
54759 + insert_subj_map_entry(subjmap);
54760 +
54761 + if (copy_from_user(s_tmp, userp,
54762 + sizeof (struct acl_subject_label)))
54763 + return ERR_PTR(-EFAULT);
54764 +
54765 + len = strnlen_user(s_tmp->filename, PATH_MAX);
54766 +
54767 + if (!len || len >= PATH_MAX)
54768 + return ERR_PTR(-EINVAL);
54769 +
54770 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54771 + return ERR_PTR(-ENOMEM);
54772 +
54773 + if (copy_from_user(tmp, s_tmp->filename, len))
54774 + return ERR_PTR(-EFAULT);
54775 + tmp[len-1] = '\0';
54776 + s_tmp->filename = tmp;
54777 +
54778 + if (!strcmp(s_tmp->filename, "/"))
54779 + role->root_label = s_tmp;
54780 +
54781 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54782 + return ERR_PTR(-EFAULT);
54783 +
54784 + /* copy user and group transition tables */
54785 +
54786 + if (s_tmp->user_trans_num) {
54787 + uid_t *uidlist;
54788 +
54789 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54790 + if (uidlist == NULL)
54791 + return ERR_PTR(-ENOMEM);
54792 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54793 + return ERR_PTR(-EFAULT);
54794 +
54795 + s_tmp->user_transitions = uidlist;
54796 + }
54797 +
54798 + if (s_tmp->group_trans_num) {
54799 + gid_t *gidlist;
54800 +
54801 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54802 + if (gidlist == NULL)
54803 + return ERR_PTR(-ENOMEM);
54804 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54805 + return ERR_PTR(-EFAULT);
54806 +
54807 + s_tmp->group_transitions = gidlist;
54808 + }
54809 +
54810 + /* set up object hash table */
54811 + num_objs = count_user_objs(ghash.first);
54812 +
54813 + s_tmp->obj_hash_size = num_objs;
54814 + s_tmp->obj_hash =
54815 + (struct acl_object_label **)
54816 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54817 +
54818 + if (!s_tmp->obj_hash)
54819 + return ERR_PTR(-ENOMEM);
54820 +
54821 + memset(s_tmp->obj_hash, 0,
54822 + s_tmp->obj_hash_size *
54823 + sizeof (struct acl_object_label *));
54824 +
54825 + /* add in objects */
54826 + err = copy_user_objs(ghash.first, s_tmp, role);
54827 +
54828 + if (err)
54829 + return ERR_PTR(err);
54830 +
54831 + /* set pointer for parent subject */
54832 + if (s_tmp->parent_subject) {
54833 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54834 +
54835 + if (IS_ERR(s_tmp2))
54836 + return s_tmp2;
54837 +
54838 + s_tmp->parent_subject = s_tmp2;
54839 + }
54840 +
54841 + /* add in ip acls */
54842 +
54843 + if (!s_tmp->ip_num) {
54844 + s_tmp->ips = NULL;
54845 + goto insert;
54846 + }
54847 +
54848 + i_tmp =
54849 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54850 + sizeof (struct acl_ip_label *));
54851 +
54852 + if (!i_tmp)
54853 + return ERR_PTR(-ENOMEM);
54854 +
54855 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54856 + *(i_tmp + i_num) =
54857 + (struct acl_ip_label *)
54858 + acl_alloc(sizeof (struct acl_ip_label));
54859 + if (!*(i_tmp + i_num))
54860 + return ERR_PTR(-ENOMEM);
54861 +
54862 + if (copy_from_user
54863 + (&i_utmp2, s_tmp->ips + i_num,
54864 + sizeof (struct acl_ip_label *)))
54865 + return ERR_PTR(-EFAULT);
54866 +
54867 + if (copy_from_user
54868 + (*(i_tmp + i_num), i_utmp2,
54869 + sizeof (struct acl_ip_label)))
54870 + return ERR_PTR(-EFAULT);
54871 +
54872 + if ((*(i_tmp + i_num))->iface == NULL)
54873 + continue;
54874 +
54875 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54876 + if (!len || len >= IFNAMSIZ)
54877 + return ERR_PTR(-EINVAL);
54878 + tmp = acl_alloc(len);
54879 + if (tmp == NULL)
54880 + return ERR_PTR(-ENOMEM);
54881 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54882 + return ERR_PTR(-EFAULT);
54883 + (*(i_tmp + i_num))->iface = tmp;
54884 + }
54885 +
54886 + s_tmp->ips = i_tmp;
54887 +
54888 +insert:
54889 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
54890 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
54891 + return ERR_PTR(-ENOMEM);
54892 +
54893 + return s_tmp;
54894 +}
54895 +
54896 +static int
54897 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
54898 +{
54899 + struct acl_subject_label s_pre;
54900 + struct acl_subject_label * ret;
54901 + int err;
54902 +
54903 + while (userp) {
54904 + if (copy_from_user(&s_pre, userp,
54905 + sizeof (struct acl_subject_label)))
54906 + return -EFAULT;
54907 +
54908 + ret = do_copy_user_subj(userp, role, NULL);
54909 +
54910 + err = PTR_ERR(ret);
54911 + if (IS_ERR(ret))
54912 + return err;
54913 +
54914 + insert_acl_subj_label(ret, role);
54915 +
54916 + userp = s_pre.prev;
54917 + }
54918 +
54919 + return 0;
54920 +}
54921 +
54922 +static int
54923 +copy_user_acl(struct gr_arg *arg)
54924 +{
54925 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
54926 + struct acl_subject_label *subj_list;
54927 + struct sprole_pw *sptmp;
54928 + struct gr_hash_struct *ghash;
54929 + uid_t *domainlist;
54930 + unsigned int r_num;
54931 + unsigned int len;
54932 + char *tmp;
54933 + int err = 0;
54934 + __u16 i;
54935 + __u32 num_subjs;
54936 +
54937 + /* we need a default and kernel role */
54938 + if (arg->role_db.num_roles < 2)
54939 + return -EINVAL;
54940 +
54941 + /* copy special role authentication info from userspace */
54942 +
54943 + num_sprole_pws = arg->num_sprole_pws;
54944 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
54945 +
54946 + if (!acl_special_roles && num_sprole_pws)
54947 + return -ENOMEM;
54948 +
54949 + for (i = 0; i < num_sprole_pws; i++) {
54950 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
54951 + if (!sptmp)
54952 + return -ENOMEM;
54953 + if (copy_from_user(sptmp, arg->sprole_pws + i,
54954 + sizeof (struct sprole_pw)))
54955 + return -EFAULT;
54956 +
54957 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
54958 +
54959 + if (!len || len >= GR_SPROLE_LEN)
54960 + return -EINVAL;
54961 +
54962 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54963 + return -ENOMEM;
54964 +
54965 + if (copy_from_user(tmp, sptmp->rolename, len))
54966 + return -EFAULT;
54967 +
54968 + tmp[len-1] = '\0';
54969 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54970 + printk(KERN_ALERT "Copying special role %s\n", tmp);
54971 +#endif
54972 + sptmp->rolename = tmp;
54973 + acl_special_roles[i] = sptmp;
54974 + }
54975 +
54976 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
54977 +
54978 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
54979 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
54980 +
54981 + if (!r_tmp)
54982 + return -ENOMEM;
54983 +
54984 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
54985 + sizeof (struct acl_role_label *)))
54986 + return -EFAULT;
54987 +
54988 + if (copy_from_user(r_tmp, r_utmp2,
54989 + sizeof (struct acl_role_label)))
54990 + return -EFAULT;
54991 +
54992 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
54993 +
54994 + if (!len || len >= PATH_MAX)
54995 + return -EINVAL;
54996 +
54997 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54998 + return -ENOMEM;
54999 +
55000 + if (copy_from_user(tmp, r_tmp->rolename, len))
55001 + return -EFAULT;
55002 +
55003 + tmp[len-1] = '\0';
55004 + r_tmp->rolename = tmp;
55005 +
55006 + if (!strcmp(r_tmp->rolename, "default")
55007 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55008 + default_role = r_tmp;
55009 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55010 + kernel_role = r_tmp;
55011 + }
55012 +
55013 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55014 + return -ENOMEM;
55015 +
55016 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55017 + return -EFAULT;
55018 +
55019 + r_tmp->hash = ghash;
55020 +
55021 + num_subjs = count_user_subjs(r_tmp->hash->first);
55022 +
55023 + r_tmp->subj_hash_size = num_subjs;
55024 + r_tmp->subj_hash =
55025 + (struct acl_subject_label **)
55026 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55027 +
55028 + if (!r_tmp->subj_hash)
55029 + return -ENOMEM;
55030 +
55031 + err = copy_user_allowedips(r_tmp);
55032 + if (err)
55033 + return err;
55034 +
55035 + /* copy domain info */
55036 + if (r_tmp->domain_children != NULL) {
55037 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55038 + if (domainlist == NULL)
55039 + return -ENOMEM;
55040 +
55041 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55042 + return -EFAULT;
55043 +
55044 + r_tmp->domain_children = domainlist;
55045 + }
55046 +
55047 + err = copy_user_transitions(r_tmp);
55048 + if (err)
55049 + return err;
55050 +
55051 + memset(r_tmp->subj_hash, 0,
55052 + r_tmp->subj_hash_size *
55053 + sizeof (struct acl_subject_label *));
55054 +
55055 + /* acquire the list of subjects, then NULL out
55056 + the list prior to parsing the subjects for this role,
55057 + as during this parsing the list is replaced with a list
55058 + of *nested* subjects for the role
55059 + */
55060 + subj_list = r_tmp->hash->first;
55061 +
55062 + /* set nested subject list to null */
55063 + r_tmp->hash->first = NULL;
55064 +
55065 + err = copy_user_subjs(subj_list, r_tmp);
55066 +
55067 + if (err)
55068 + return err;
55069 +
55070 + insert_acl_role_label(r_tmp);
55071 + }
55072 +
55073 + if (default_role == NULL || kernel_role == NULL)
55074 + return -EINVAL;
55075 +
55076 + return err;
55077 +}
55078 +
55079 +static int
55080 +gracl_init(struct gr_arg *args)
55081 +{
55082 + int error = 0;
55083 +
55084 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55085 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55086 +
55087 + if (init_variables(args)) {
55088 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55089 + error = -ENOMEM;
55090 + free_variables();
55091 + goto out;
55092 + }
55093 +
55094 + error = copy_user_acl(args);
55095 + free_init_variables();
55096 + if (error) {
55097 + free_variables();
55098 + goto out;
55099 + }
55100 +
55101 + if ((error = gr_set_acls(0))) {
55102 + free_variables();
55103 + goto out;
55104 + }
55105 +
55106 + pax_open_kernel();
55107 + gr_status |= GR_READY;
55108 + pax_close_kernel();
55109 +
55110 + out:
55111 + return error;
55112 +}
55113 +
55114 +/* derived from glibc fnmatch() 0: match, 1: no match*/
55115 +
55116 +static int
55117 +glob_match(const char *p, const char *n)
55118 +{
55119 + char c;
55120 +
55121 + while ((c = *p++) != '\0') {
55122 + switch (c) {
55123 + case '?':
55124 + if (*n == '\0')
55125 + return 1;
55126 + else if (*n == '/')
55127 + return 1;
55128 + break;
55129 + case '\\':
55130 + if (*n != c)
55131 + return 1;
55132 + break;
55133 + case '*':
55134 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
55135 + if (*n == '/')
55136 + return 1;
55137 + else if (c == '?') {
55138 + if (*n == '\0')
55139 + return 1;
55140 + else
55141 + ++n;
55142 + }
55143 + }
55144 + if (c == '\0') {
55145 + return 0;
55146 + } else {
55147 + const char *endp;
55148 +
55149 + if ((endp = strchr(n, '/')) == NULL)
55150 + endp = n + strlen(n);
55151 +
55152 + if (c == '[') {
55153 + for (--p; n < endp; ++n)
55154 + if (!glob_match(p, n))
55155 + return 0;
55156 + } else if (c == '/') {
55157 + while (*n != '\0' && *n != '/')
55158 + ++n;
55159 + if (*n == '/' && !glob_match(p, n + 1))
55160 + return 0;
55161 + } else {
55162 + for (--p; n < endp; ++n)
55163 + if (*n == c && !glob_match(p, n))
55164 + return 0;
55165 + }
55166 +
55167 + return 1;
55168 + }
55169 + case '[':
55170 + {
55171 + int not;
55172 + char cold;
55173 +
55174 + if (*n == '\0' || *n == '/')
55175 + return 1;
55176 +
55177 + not = (*p == '!' || *p == '^');
55178 + if (not)
55179 + ++p;
55180 +
55181 + c = *p++;
55182 + for (;;) {
55183 + unsigned char fn = (unsigned char)*n;
55184 +
55185 + if (c == '\0')
55186 + return 1;
55187 + else {
55188 + if (c == fn)
55189 + goto matched;
55190 + cold = c;
55191 + c = *p++;
55192 +
55193 + if (c == '-' && *p != ']') {
55194 + unsigned char cend = *p++;
55195 +
55196 + if (cend == '\0')
55197 + return 1;
55198 +
55199 + if (cold <= fn && fn <= cend)
55200 + goto matched;
55201 +
55202 + c = *p++;
55203 + }
55204 + }
55205 +
55206 + if (c == ']')
55207 + break;
55208 + }
55209 + if (!not)
55210 + return 1;
55211 + break;
55212 + matched:
55213 + while (c != ']') {
55214 + if (c == '\0')
55215 + return 1;
55216 +
55217 + c = *p++;
55218 + }
55219 + if (not)
55220 + return 1;
55221 + }
55222 + break;
55223 + default:
55224 + if (c != *n)
55225 + return 1;
55226 + }
55227 +
55228 + ++n;
55229 + }
55230 +
55231 + if (*n == '\0')
55232 + return 0;
55233 +
55234 + if (*n == '/')
55235 + return 0;
55236 +
55237 + return 1;
55238 +}
55239 +
55240 +static struct acl_object_label *
55241 +chk_glob_label(struct acl_object_label *globbed,
55242 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55243 +{
55244 + struct acl_object_label *tmp;
55245 +
55246 + if (*path == NULL)
55247 + *path = gr_to_filename_nolock(dentry, mnt);
55248 +
55249 + tmp = globbed;
55250 +
55251 + while (tmp) {
55252 + if (!glob_match(tmp->filename, *path))
55253 + return tmp;
55254 + tmp = tmp->next;
55255 + }
55256 +
55257 + return NULL;
55258 +}
55259 +
55260 +static struct acl_object_label *
55261 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55262 + const ino_t curr_ino, const dev_t curr_dev,
55263 + const struct acl_subject_label *subj, char **path, const int checkglob)
55264 +{
55265 + struct acl_subject_label *tmpsubj;
55266 + struct acl_object_label *retval;
55267 + struct acl_object_label *retval2;
55268 +
55269 + tmpsubj = (struct acl_subject_label *) subj;
55270 + read_lock(&gr_inode_lock);
55271 + do {
55272 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55273 + if (retval) {
55274 + if (checkglob && retval->globbed) {
55275 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55276 + if (retval2)
55277 + retval = retval2;
55278 + }
55279 + break;
55280 + }
55281 + } while ((tmpsubj = tmpsubj->parent_subject));
55282 + read_unlock(&gr_inode_lock);
55283 +
55284 + return retval;
55285 +}
55286 +
55287 +static __inline__ struct acl_object_label *
55288 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55289 + struct dentry *curr_dentry,
55290 + const struct acl_subject_label *subj, char **path, const int checkglob)
55291 +{
55292 + int newglob = checkglob;
55293 + ino_t inode;
55294 + dev_t device;
55295 +
55296 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55297 + as we don't want a / * rule to match instead of the / object
55298 + don't do this for create lookups that call this function though, since they're looking up
55299 + on the parent and thus need globbing checks on all paths
55300 + */
55301 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55302 + newglob = GR_NO_GLOB;
55303 +
55304 + spin_lock(&curr_dentry->d_lock);
55305 + inode = curr_dentry->d_inode->i_ino;
55306 + device = __get_dev(curr_dentry);
55307 + spin_unlock(&curr_dentry->d_lock);
55308 +
55309 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55310 +}
55311 +
55312 +static struct acl_object_label *
55313 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55314 + const struct acl_subject_label *subj, char *path, const int checkglob)
55315 +{
55316 + struct dentry *dentry = (struct dentry *) l_dentry;
55317 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55318 + struct mount *real_mnt = real_mount(mnt);
55319 + struct acl_object_label *retval;
55320 + struct dentry *parent;
55321 +
55322 + write_seqlock(&rename_lock);
55323 + br_read_lock(&vfsmount_lock);
55324 +
55325 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55326 +#ifdef CONFIG_NET
55327 + mnt == sock_mnt ||
55328 +#endif
55329 +#ifdef CONFIG_HUGETLBFS
55330 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55331 +#endif
55332 + /* ignore Eric Biederman */
55333 + IS_PRIVATE(l_dentry->d_inode))) {
55334 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55335 + goto out;
55336 + }
55337 +
55338 + for (;;) {
55339 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55340 + break;
55341 +
55342 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55343 + if (!mnt_has_parent(real_mnt))
55344 + break;
55345 +
55346 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55347 + if (retval != NULL)
55348 + goto out;
55349 +
55350 + dentry = real_mnt->mnt_mountpoint;
55351 + real_mnt = real_mnt->mnt_parent;
55352 + mnt = &real_mnt->mnt;
55353 + continue;
55354 + }
55355 +
55356 + parent = dentry->d_parent;
55357 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55358 + if (retval != NULL)
55359 + goto out;
55360 +
55361 + dentry = parent;
55362 + }
55363 +
55364 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55365 +
55366 + /* real_root is pinned so we don't have to hold a reference */
55367 + if (retval == NULL)
55368 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55369 +out:
55370 + br_read_unlock(&vfsmount_lock);
55371 + write_sequnlock(&rename_lock);
55372 +
55373 + BUG_ON(retval == NULL);
55374 +
55375 + return retval;
55376 +}
55377 +
55378 +static __inline__ struct acl_object_label *
55379 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55380 + const struct acl_subject_label *subj)
55381 +{
55382 + char *path = NULL;
55383 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55384 +}
55385 +
55386 +static __inline__ struct acl_object_label *
55387 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55388 + const struct acl_subject_label *subj)
55389 +{
55390 + char *path = NULL;
55391 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55392 +}
55393 +
55394 +static __inline__ struct acl_object_label *
55395 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55396 + const struct acl_subject_label *subj, char *path)
55397 +{
55398 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55399 +}
55400 +
55401 +static struct acl_subject_label *
55402 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55403 + const struct acl_role_label *role)
55404 +{
55405 + struct dentry *dentry = (struct dentry *) l_dentry;
55406 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55407 + struct mount *real_mnt = real_mount(mnt);
55408 + struct acl_subject_label *retval;
55409 + struct dentry *parent;
55410 +
55411 + write_seqlock(&rename_lock);
55412 + br_read_lock(&vfsmount_lock);
55413 +
55414 + for (;;) {
55415 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55416 + break;
55417 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55418 + if (!mnt_has_parent(real_mnt))
55419 + break;
55420 +
55421 + spin_lock(&dentry->d_lock);
55422 + read_lock(&gr_inode_lock);
55423 + retval =
55424 + lookup_acl_subj_label(dentry->d_inode->i_ino,
55425 + __get_dev(dentry), role);
55426 + read_unlock(&gr_inode_lock);
55427 + spin_unlock(&dentry->d_lock);
55428 + if (retval != NULL)
55429 + goto out;
55430 +
55431 + dentry = real_mnt->mnt_mountpoint;
55432 + real_mnt = real_mnt->mnt_parent;
55433 + mnt = &real_mnt->mnt;
55434 + continue;
55435 + }
55436 +
55437 + spin_lock(&dentry->d_lock);
55438 + read_lock(&gr_inode_lock);
55439 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55440 + __get_dev(dentry), role);
55441 + read_unlock(&gr_inode_lock);
55442 + parent = dentry->d_parent;
55443 + spin_unlock(&dentry->d_lock);
55444 +
55445 + if (retval != NULL)
55446 + goto out;
55447 +
55448 + dentry = parent;
55449 + }
55450 +
55451 + spin_lock(&dentry->d_lock);
55452 + read_lock(&gr_inode_lock);
55453 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55454 + __get_dev(dentry), role);
55455 + read_unlock(&gr_inode_lock);
55456 + spin_unlock(&dentry->d_lock);
55457 +
55458 + if (unlikely(retval == NULL)) {
55459 + /* real_root is pinned, we don't need to hold a reference */
55460 + read_lock(&gr_inode_lock);
55461 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55462 + __get_dev(real_root.dentry), role);
55463 + read_unlock(&gr_inode_lock);
55464 + }
55465 +out:
55466 + br_read_unlock(&vfsmount_lock);
55467 + write_sequnlock(&rename_lock);
55468 +
55469 + BUG_ON(retval == NULL);
55470 +
55471 + return retval;
55472 +}
55473 +
55474 +static void
55475 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55476 +{
55477 + struct task_struct *task = current;
55478 + const struct cred *cred = current_cred();
55479 +
55480 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55481 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55482 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55483 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55484 +
55485 + return;
55486 +}
55487 +
55488 +static void
55489 +gr_log_learn_id_change(const char type, const unsigned int real,
55490 + const unsigned int effective, const unsigned int fs)
55491 +{
55492 + struct task_struct *task = current;
55493 + const struct cred *cred = current_cred();
55494 +
55495 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55496 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55497 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55498 + type, real, effective, fs, &task->signal->saved_ip);
55499 +
55500 + return;
55501 +}
55502 +
55503 +__u32
55504 +gr_search_file(const struct dentry * dentry, const __u32 mode,
55505 + const struct vfsmount * mnt)
55506 +{
55507 + __u32 retval = mode;
55508 + struct acl_subject_label *curracl;
55509 + struct acl_object_label *currobj;
55510 +
55511 + if (unlikely(!(gr_status & GR_READY)))
55512 + return (mode & ~GR_AUDITS);
55513 +
55514 + curracl = current->acl;
55515 +
55516 + currobj = chk_obj_label(dentry, mnt, curracl);
55517 + retval = currobj->mode & mode;
55518 +
55519 + /* if we're opening a specified transfer file for writing
55520 + (e.g. /dev/initctl), then transfer our role to init
55521 + */
55522 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55523 + current->role->roletype & GR_ROLE_PERSIST)) {
55524 + struct task_struct *task = init_pid_ns.child_reaper;
55525 +
55526 + if (task->role != current->role) {
55527 + task->acl_sp_role = 0;
55528 + task->acl_role_id = current->acl_role_id;
55529 + task->role = current->role;
55530 + rcu_read_lock();
55531 + read_lock(&grsec_exec_file_lock);
55532 + gr_apply_subject_to_task(task);
55533 + read_unlock(&grsec_exec_file_lock);
55534 + rcu_read_unlock();
55535 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55536 + }
55537 + }
55538 +
55539 + if (unlikely
55540 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55541 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55542 + __u32 new_mode = mode;
55543 +
55544 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55545 +
55546 + retval = new_mode;
55547 +
55548 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55549 + new_mode |= GR_INHERIT;
55550 +
55551 + if (!(mode & GR_NOLEARN))
55552 + gr_log_learn(dentry, mnt, new_mode);
55553 + }
55554 +
55555 + return retval;
55556 +}
55557 +
55558 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55559 + const struct dentry *parent,
55560 + const struct vfsmount *mnt)
55561 +{
55562 + struct name_entry *match;
55563 + struct acl_object_label *matchpo;
55564 + struct acl_subject_label *curracl;
55565 + char *path;
55566 +
55567 + if (unlikely(!(gr_status & GR_READY)))
55568 + return NULL;
55569 +
55570 + preempt_disable();
55571 + path = gr_to_filename_rbac(new_dentry, mnt);
55572 + match = lookup_name_entry_create(path);
55573 +
55574 + curracl = current->acl;
55575 +
55576 + if (match) {
55577 + read_lock(&gr_inode_lock);
55578 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55579 + read_unlock(&gr_inode_lock);
55580 +
55581 + if (matchpo) {
55582 + preempt_enable();
55583 + return matchpo;
55584 + }
55585 + }
55586 +
55587 + // lookup parent
55588 +
55589 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55590 +
55591 + preempt_enable();
55592 + return matchpo;
55593 +}
55594 +
55595 +__u32
55596 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55597 + const struct vfsmount * mnt, const __u32 mode)
55598 +{
55599 + struct acl_object_label *matchpo;
55600 + __u32 retval;
55601 +
55602 + if (unlikely(!(gr_status & GR_READY)))
55603 + return (mode & ~GR_AUDITS);
55604 +
55605 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55606 +
55607 + retval = matchpo->mode & mode;
55608 +
55609 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55610 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55611 + __u32 new_mode = mode;
55612 +
55613 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55614 +
55615 + gr_log_learn(new_dentry, mnt, new_mode);
55616 + return new_mode;
55617 + }
55618 +
55619 + return retval;
55620 +}
55621 +
55622 +__u32
55623 +gr_check_link(const struct dentry * new_dentry,
55624 + const struct dentry * parent_dentry,
55625 + const struct vfsmount * parent_mnt,
55626 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55627 +{
55628 + struct acl_object_label *obj;
55629 + __u32 oldmode, newmode;
55630 + __u32 needmode;
55631 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55632 + GR_DELETE | GR_INHERIT;
55633 +
55634 + if (unlikely(!(gr_status & GR_READY)))
55635 + return (GR_CREATE | GR_LINK);
55636 +
55637 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55638 + oldmode = obj->mode;
55639 +
55640 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55641 + newmode = obj->mode;
55642 +
55643 + needmode = newmode & checkmodes;
55644 +
55645 + // old name for hardlink must have at least the permissions of the new name
55646 + if ((oldmode & needmode) != needmode)
55647 + goto bad;
55648 +
55649 + // if old name had restrictions/auditing, make sure the new name does as well
55650 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55651 +
55652 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55653 + if (is_privileged_binary(old_dentry))
55654 + needmode |= GR_SETID;
55655 +
55656 + if ((newmode & needmode) != needmode)
55657 + goto bad;
55658 +
55659 + // enforce minimum permissions
55660 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55661 + return newmode;
55662 +bad:
55663 + needmode = oldmode;
55664 + if (is_privileged_binary(old_dentry))
55665 + needmode |= GR_SETID;
55666 +
55667 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55668 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55669 + return (GR_CREATE | GR_LINK);
55670 + } else if (newmode & GR_SUPPRESS)
55671 + return GR_SUPPRESS;
55672 + else
55673 + return 0;
55674 +}
55675 +
55676 +int
55677 +gr_check_hidden_task(const struct task_struct *task)
55678 +{
55679 + if (unlikely(!(gr_status & GR_READY)))
55680 + return 0;
55681 +
55682 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55683 + return 1;
55684 +
55685 + return 0;
55686 +}
55687 +
55688 +int
55689 +gr_check_protected_task(const struct task_struct *task)
55690 +{
55691 + if (unlikely(!(gr_status & GR_READY) || !task))
55692 + return 0;
55693 +
55694 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55695 + task->acl != current->acl)
55696 + return 1;
55697 +
55698 + return 0;
55699 +}
55700 +
55701 +int
55702 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55703 +{
55704 + struct task_struct *p;
55705 + int ret = 0;
55706 +
55707 + if (unlikely(!(gr_status & GR_READY) || !pid))
55708 + return ret;
55709 +
55710 + read_lock(&tasklist_lock);
55711 + do_each_pid_task(pid, type, p) {
55712 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55713 + p->acl != current->acl) {
55714 + ret = 1;
55715 + goto out;
55716 + }
55717 + } while_each_pid_task(pid, type, p);
55718 +out:
55719 + read_unlock(&tasklist_lock);
55720 +
55721 + return ret;
55722 +}
55723 +
55724 +void
55725 +gr_copy_label(struct task_struct *tsk)
55726 +{
55727 + tsk->signal->used_accept = 0;
55728 + tsk->acl_sp_role = 0;
55729 + tsk->acl_role_id = current->acl_role_id;
55730 + tsk->acl = current->acl;
55731 + tsk->role = current->role;
55732 + tsk->signal->curr_ip = current->signal->curr_ip;
55733 + tsk->signal->saved_ip = current->signal->saved_ip;
55734 + if (current->exec_file)
55735 + get_file(current->exec_file);
55736 + tsk->exec_file = current->exec_file;
55737 + tsk->is_writable = current->is_writable;
55738 + if (unlikely(current->signal->used_accept)) {
55739 + current->signal->curr_ip = 0;
55740 + current->signal->saved_ip = 0;
55741 + }
55742 +
55743 + return;
55744 +}
55745 +
55746 +static void
55747 +gr_set_proc_res(struct task_struct *task)
55748 +{
55749 + struct acl_subject_label *proc;
55750 + unsigned short i;
55751 +
55752 + proc = task->acl;
55753 +
55754 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55755 + return;
55756 +
55757 + for (i = 0; i < RLIM_NLIMITS; i++) {
55758 + if (!(proc->resmask & (1 << i)))
55759 + continue;
55760 +
55761 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55762 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55763 + }
55764 +
55765 + return;
55766 +}
55767 +
55768 +extern int __gr_process_user_ban(struct user_struct *user);
55769 +
55770 +int
55771 +gr_check_user_change(int real, int effective, int fs)
55772 +{
55773 + unsigned int i;
55774 + __u16 num;
55775 + uid_t *uidlist;
55776 + int curuid;
55777 + int realok = 0;
55778 + int effectiveok = 0;
55779 + int fsok = 0;
55780 +
55781 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55782 + struct user_struct *user;
55783 +
55784 + if (real == -1)
55785 + goto skipit;
55786 +
55787 + user = find_user(real);
55788 + if (user == NULL)
55789 + goto skipit;
55790 +
55791 + if (__gr_process_user_ban(user)) {
55792 + /* for find_user */
55793 + free_uid(user);
55794 + return 1;
55795 + }
55796 +
55797 + /* for find_user */
55798 + free_uid(user);
55799 +
55800 +skipit:
55801 +#endif
55802 +
55803 + if (unlikely(!(gr_status & GR_READY)))
55804 + return 0;
55805 +
55806 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55807 + gr_log_learn_id_change('u', real, effective, fs);
55808 +
55809 + num = current->acl->user_trans_num;
55810 + uidlist = current->acl->user_transitions;
55811 +
55812 + if (uidlist == NULL)
55813 + return 0;
55814 +
55815 + if (real == -1)
55816 + realok = 1;
55817 + if (effective == -1)
55818 + effectiveok = 1;
55819 + if (fs == -1)
55820 + fsok = 1;
55821 +
55822 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
55823 + for (i = 0; i < num; i++) {
55824 + curuid = (int)uidlist[i];
55825 + if (real == curuid)
55826 + realok = 1;
55827 + if (effective == curuid)
55828 + effectiveok = 1;
55829 + if (fs == curuid)
55830 + fsok = 1;
55831 + }
55832 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
55833 + for (i = 0; i < num; i++) {
55834 + curuid = (int)uidlist[i];
55835 + if (real == curuid)
55836 + break;
55837 + if (effective == curuid)
55838 + break;
55839 + if (fs == curuid)
55840 + break;
55841 + }
55842 + /* not in deny list */
55843 + if (i == num) {
55844 + realok = 1;
55845 + effectiveok = 1;
55846 + fsok = 1;
55847 + }
55848 + }
55849 +
55850 + if (realok && effectiveok && fsok)
55851 + return 0;
55852 + else {
55853 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55854 + return 1;
55855 + }
55856 +}
55857 +
55858 +int
55859 +gr_check_group_change(int real, int effective, int fs)
55860 +{
55861 + unsigned int i;
55862 + __u16 num;
55863 + gid_t *gidlist;
55864 + int curgid;
55865 + int realok = 0;
55866 + int effectiveok = 0;
55867 + int fsok = 0;
55868 +
55869 + if (unlikely(!(gr_status & GR_READY)))
55870 + return 0;
55871 +
55872 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55873 + gr_log_learn_id_change('g', real, effective, fs);
55874 +
55875 + num = current->acl->group_trans_num;
55876 + gidlist = current->acl->group_transitions;
55877 +
55878 + if (gidlist == NULL)
55879 + return 0;
55880 +
55881 + if (real == -1)
55882 + realok = 1;
55883 + if (effective == -1)
55884 + effectiveok = 1;
55885 + if (fs == -1)
55886 + fsok = 1;
55887 +
55888 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
55889 + for (i = 0; i < num; i++) {
55890 + curgid = (int)gidlist[i];
55891 + if (real == curgid)
55892 + realok = 1;
55893 + if (effective == curgid)
55894 + effectiveok = 1;
55895 + if (fs == curgid)
55896 + fsok = 1;
55897 + }
55898 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
55899 + for (i = 0; i < num; i++) {
55900 + curgid = (int)gidlist[i];
55901 + if (real == curgid)
55902 + break;
55903 + if (effective == curgid)
55904 + break;
55905 + if (fs == curgid)
55906 + break;
55907 + }
55908 + /* not in deny list */
55909 + if (i == num) {
55910 + realok = 1;
55911 + effectiveok = 1;
55912 + fsok = 1;
55913 + }
55914 + }
55915 +
55916 + if (realok && effectiveok && fsok)
55917 + return 0;
55918 + else {
55919 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55920 + return 1;
55921 + }
55922 +}
55923 +
55924 +extern int gr_acl_is_capable(const int cap);
55925 +
55926 +void
55927 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
55928 +{
55929 + struct acl_role_label *role = task->role;
55930 + struct acl_subject_label *subj = NULL;
55931 + struct acl_object_label *obj;
55932 + struct file *filp;
55933 +
55934 + if (unlikely(!(gr_status & GR_READY)))
55935 + return;
55936 +
55937 + filp = task->exec_file;
55938 +
55939 + /* kernel process, we'll give them the kernel role */
55940 + if (unlikely(!filp)) {
55941 + task->role = kernel_role;
55942 + task->acl = kernel_role->root_label;
55943 + return;
55944 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
55945 + role = lookup_acl_role_label(task, uid, gid);
55946 +
55947 + /* don't change the role if we're not a privileged process */
55948 + if (role && task->role != role &&
55949 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
55950 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
55951 + return;
55952 +
55953 + /* perform subject lookup in possibly new role
55954 + we can use this result below in the case where role == task->role
55955 + */
55956 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
55957 +
55958 + /* if we changed uid/gid, but result in the same role
55959 + and are using inheritance, don't lose the inherited subject
55960 + if current subject is other than what normal lookup
55961 + would result in, we arrived via inheritance, don't
55962 + lose subject
55963 + */
55964 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
55965 + (subj == task->acl)))
55966 + task->acl = subj;
55967 +
55968 + task->role = role;
55969 +
55970 + task->is_writable = 0;
55971 +
55972 + /* ignore additional mmap checks for processes that are writable
55973 + by the default ACL */
55974 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55975 + if (unlikely(obj->mode & GR_WRITE))
55976 + task->is_writable = 1;
55977 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55978 + if (unlikely(obj->mode & GR_WRITE))
55979 + task->is_writable = 1;
55980 +
55981 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55982 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55983 +#endif
55984 +
55985 + gr_set_proc_res(task);
55986 +
55987 + return;
55988 +}
55989 +
55990 +int
55991 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55992 + const int unsafe_flags)
55993 +{
55994 + struct task_struct *task = current;
55995 + struct acl_subject_label *newacl;
55996 + struct acl_object_label *obj;
55997 + __u32 retmode;
55998 +
55999 + if (unlikely(!(gr_status & GR_READY)))
56000 + return 0;
56001 +
56002 + newacl = chk_subj_label(dentry, mnt, task->role);
56003 +
56004 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56005 + did an exec
56006 + */
56007 + rcu_read_lock();
56008 + read_lock(&tasklist_lock);
56009 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56010 + (task->parent->acl->mode & GR_POVERRIDE))) {
56011 + read_unlock(&tasklist_lock);
56012 + rcu_read_unlock();
56013 + goto skip_check;
56014 + }
56015 + read_unlock(&tasklist_lock);
56016 + rcu_read_unlock();
56017 +
56018 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56019 + !(task->role->roletype & GR_ROLE_GOD) &&
56020 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56021 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56022 + if (unsafe_flags & LSM_UNSAFE_SHARE)
56023 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56024 + else
56025 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56026 + return -EACCES;
56027 + }
56028 +
56029 +skip_check:
56030 +
56031 + obj = chk_obj_label(dentry, mnt, task->acl);
56032 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56033 +
56034 + if (!(task->acl->mode & GR_INHERITLEARN) &&
56035 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56036 + if (obj->nested)
56037 + task->acl = obj->nested;
56038 + else
56039 + task->acl = newacl;
56040 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56041 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56042 +
56043 + task->is_writable = 0;
56044 +
56045 + /* ignore additional mmap checks for processes that are writable
56046 + by the default ACL */
56047 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
56048 + if (unlikely(obj->mode & GR_WRITE))
56049 + task->is_writable = 1;
56050 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
56051 + if (unlikely(obj->mode & GR_WRITE))
56052 + task->is_writable = 1;
56053 +
56054 + gr_set_proc_res(task);
56055 +
56056 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56057 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56058 +#endif
56059 + return 0;
56060 +}
56061 +
56062 +/* always called with valid inodev ptr */
56063 +static void
56064 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56065 +{
56066 + struct acl_object_label *matchpo;
56067 + struct acl_subject_label *matchps;
56068 + struct acl_subject_label *subj;
56069 + struct acl_role_label *role;
56070 + unsigned int x;
56071 +
56072 + FOR_EACH_ROLE_START(role)
56073 + FOR_EACH_SUBJECT_START(role, subj, x)
56074 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56075 + matchpo->mode |= GR_DELETED;
56076 + FOR_EACH_SUBJECT_END(subj,x)
56077 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56078 + /* nested subjects aren't in the role's subj_hash table */
56079 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56080 + matchpo->mode |= GR_DELETED;
56081 + FOR_EACH_NESTED_SUBJECT_END(subj)
56082 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56083 + matchps->mode |= GR_DELETED;
56084 + FOR_EACH_ROLE_END(role)
56085 +
56086 + inodev->nentry->deleted = 1;
56087 +
56088 + return;
56089 +}
56090 +
56091 +void
56092 +gr_handle_delete(const ino_t ino, const dev_t dev)
56093 +{
56094 + struct inodev_entry *inodev;
56095 +
56096 + if (unlikely(!(gr_status & GR_READY)))
56097 + return;
56098 +
56099 + write_lock(&gr_inode_lock);
56100 + inodev = lookup_inodev_entry(ino, dev);
56101 + if (inodev != NULL)
56102 + do_handle_delete(inodev, ino, dev);
56103 + write_unlock(&gr_inode_lock);
56104 +
56105 + return;
56106 +}
56107 +
56108 +static void
56109 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
56110 + const ino_t newinode, const dev_t newdevice,
56111 + struct acl_subject_label *subj)
56112 +{
56113 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
56114 + struct acl_object_label *match;
56115 +
56116 + match = subj->obj_hash[index];
56117 +
56118 + while (match && (match->inode != oldinode ||
56119 + match->device != olddevice ||
56120 + !(match->mode & GR_DELETED)))
56121 + match = match->next;
56122 +
56123 + if (match && (match->inode == oldinode)
56124 + && (match->device == olddevice)
56125 + && (match->mode & GR_DELETED)) {
56126 + if (match->prev == NULL) {
56127 + subj->obj_hash[index] = match->next;
56128 + if (match->next != NULL)
56129 + match->next->prev = NULL;
56130 + } else {
56131 + match->prev->next = match->next;
56132 + if (match->next != NULL)
56133 + match->next->prev = match->prev;
56134 + }
56135 + match->prev = NULL;
56136 + match->next = NULL;
56137 + match->inode = newinode;
56138 + match->device = newdevice;
56139 + match->mode &= ~GR_DELETED;
56140 +
56141 + insert_acl_obj_label(match, subj);
56142 + }
56143 +
56144 + return;
56145 +}
56146 +
56147 +static void
56148 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56149 + const ino_t newinode, const dev_t newdevice,
56150 + struct acl_role_label *role)
56151 +{
56152 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56153 + struct acl_subject_label *match;
56154 +
56155 + match = role->subj_hash[index];
56156 +
56157 + while (match && (match->inode != oldinode ||
56158 + match->device != olddevice ||
56159 + !(match->mode & GR_DELETED)))
56160 + match = match->next;
56161 +
56162 + if (match && (match->inode == oldinode)
56163 + && (match->device == olddevice)
56164 + && (match->mode & GR_DELETED)) {
56165 + if (match->prev == NULL) {
56166 + role->subj_hash[index] = match->next;
56167 + if (match->next != NULL)
56168 + match->next->prev = NULL;
56169 + } else {
56170 + match->prev->next = match->next;
56171 + if (match->next != NULL)
56172 + match->next->prev = match->prev;
56173 + }
56174 + match->prev = NULL;
56175 + match->next = NULL;
56176 + match->inode = newinode;
56177 + match->device = newdevice;
56178 + match->mode &= ~GR_DELETED;
56179 +
56180 + insert_acl_subj_label(match, role);
56181 + }
56182 +
56183 + return;
56184 +}
56185 +
56186 +static void
56187 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56188 + const ino_t newinode, const dev_t newdevice)
56189 +{
56190 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56191 + struct inodev_entry *match;
56192 +
56193 + match = inodev_set.i_hash[index];
56194 +
56195 + while (match && (match->nentry->inode != oldinode ||
56196 + match->nentry->device != olddevice || !match->nentry->deleted))
56197 + match = match->next;
56198 +
56199 + if (match && (match->nentry->inode == oldinode)
56200 + && (match->nentry->device == olddevice) &&
56201 + match->nentry->deleted) {
56202 + if (match->prev == NULL) {
56203 + inodev_set.i_hash[index] = match->next;
56204 + if (match->next != NULL)
56205 + match->next->prev = NULL;
56206 + } else {
56207 + match->prev->next = match->next;
56208 + if (match->next != NULL)
56209 + match->next->prev = match->prev;
56210 + }
56211 + match->prev = NULL;
56212 + match->next = NULL;
56213 + match->nentry->inode = newinode;
56214 + match->nentry->device = newdevice;
56215 + match->nentry->deleted = 0;
56216 +
56217 + insert_inodev_entry(match);
56218 + }
56219 +
56220 + return;
56221 +}
56222 +
56223 +static void
56224 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56225 +{
56226 + struct acl_subject_label *subj;
56227 + struct acl_role_label *role;
56228 + unsigned int x;
56229 +
56230 + FOR_EACH_ROLE_START(role)
56231 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56232 +
56233 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56234 + if ((subj->inode == ino) && (subj->device == dev)) {
56235 + subj->inode = ino;
56236 + subj->device = dev;
56237 + }
56238 + /* nested subjects aren't in the role's subj_hash table */
56239 + update_acl_obj_label(matchn->inode, matchn->device,
56240 + ino, dev, subj);
56241 + FOR_EACH_NESTED_SUBJECT_END(subj)
56242 + FOR_EACH_SUBJECT_START(role, subj, x)
56243 + update_acl_obj_label(matchn->inode, matchn->device,
56244 + ino, dev, subj);
56245 + FOR_EACH_SUBJECT_END(subj,x)
56246 + FOR_EACH_ROLE_END(role)
56247 +
56248 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56249 +
56250 + return;
56251 +}
56252 +
56253 +static void
56254 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56255 + const struct vfsmount *mnt)
56256 +{
56257 + ino_t ino = dentry->d_inode->i_ino;
56258 + dev_t dev = __get_dev(dentry);
56259 +
56260 + __do_handle_create(matchn, ino, dev);
56261 +
56262 + return;
56263 +}
56264 +
56265 +void
56266 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56267 +{
56268 + struct name_entry *matchn;
56269 +
56270 + if (unlikely(!(gr_status & GR_READY)))
56271 + return;
56272 +
56273 + preempt_disable();
56274 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56275 +
56276 + if (unlikely((unsigned long)matchn)) {
56277 + write_lock(&gr_inode_lock);
56278 + do_handle_create(matchn, dentry, mnt);
56279 + write_unlock(&gr_inode_lock);
56280 + }
56281 + preempt_enable();
56282 +
56283 + return;
56284 +}
56285 +
56286 +void
56287 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56288 +{
56289 + struct name_entry *matchn;
56290 +
56291 + if (unlikely(!(gr_status & GR_READY)))
56292 + return;
56293 +
56294 + preempt_disable();
56295 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56296 +
56297 + if (unlikely((unsigned long)matchn)) {
56298 + write_lock(&gr_inode_lock);
56299 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56300 + write_unlock(&gr_inode_lock);
56301 + }
56302 + preempt_enable();
56303 +
56304 + return;
56305 +}
56306 +
56307 +void
56308 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56309 + struct dentry *old_dentry,
56310 + struct dentry *new_dentry,
56311 + struct vfsmount *mnt, const __u8 replace)
56312 +{
56313 + struct name_entry *matchn;
56314 + struct inodev_entry *inodev;
56315 + struct inode *inode = new_dentry->d_inode;
56316 + ino_t old_ino = old_dentry->d_inode->i_ino;
56317 + dev_t old_dev = __get_dev(old_dentry);
56318 +
56319 + /* vfs_rename swaps the name and parent link for old_dentry and
56320 + new_dentry
56321 + at this point, old_dentry has the new name, parent link, and inode
56322 + for the renamed file
56323 + if a file is being replaced by a rename, new_dentry has the inode
56324 + and name for the replaced file
56325 + */
56326 +
56327 + if (unlikely(!(gr_status & GR_READY)))
56328 + return;
56329 +
56330 + preempt_disable();
56331 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56332 +
56333 + /* we wouldn't have to check d_inode if it weren't for
56334 + NFS silly-renaming
56335 + */
56336 +
56337 + write_lock(&gr_inode_lock);
56338 + if (unlikely(replace && inode)) {
56339 + ino_t new_ino = inode->i_ino;
56340 + dev_t new_dev = __get_dev(new_dentry);
56341 +
56342 + inodev = lookup_inodev_entry(new_ino, new_dev);
56343 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56344 + do_handle_delete(inodev, new_ino, new_dev);
56345 + }
56346 +
56347 + inodev = lookup_inodev_entry(old_ino, old_dev);
56348 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56349 + do_handle_delete(inodev, old_ino, old_dev);
56350 +
56351 + if (unlikely((unsigned long)matchn))
56352 + do_handle_create(matchn, old_dentry, mnt);
56353 +
56354 + write_unlock(&gr_inode_lock);
56355 + preempt_enable();
56356 +
56357 + return;
56358 +}
56359 +
56360 +static int
56361 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56362 + unsigned char **sum)
56363 +{
56364 + struct acl_role_label *r;
56365 + struct role_allowed_ip *ipp;
56366 + struct role_transition *trans;
56367 + unsigned int i;
56368 + int found = 0;
56369 + u32 curr_ip = current->signal->curr_ip;
56370 +
56371 + current->signal->saved_ip = curr_ip;
56372 +
56373 + /* check transition table */
56374 +
56375 + for (trans = current->role->transitions; trans; trans = trans->next) {
56376 + if (!strcmp(rolename, trans->rolename)) {
56377 + found = 1;
56378 + break;
56379 + }
56380 + }
56381 +
56382 + if (!found)
56383 + return 0;
56384 +
56385 + /* handle special roles that do not require authentication
56386 + and check ip */
56387 +
56388 + FOR_EACH_ROLE_START(r)
56389 + if (!strcmp(rolename, r->rolename) &&
56390 + (r->roletype & GR_ROLE_SPECIAL)) {
56391 + found = 0;
56392 + if (r->allowed_ips != NULL) {
56393 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56394 + if ((ntohl(curr_ip) & ipp->netmask) ==
56395 + (ntohl(ipp->addr) & ipp->netmask))
56396 + found = 1;
56397 + }
56398 + } else
56399 + found = 2;
56400 + if (!found)
56401 + return 0;
56402 +
56403 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56404 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56405 + *salt = NULL;
56406 + *sum = NULL;
56407 + return 1;
56408 + }
56409 + }
56410 + FOR_EACH_ROLE_END(r)
56411 +
56412 + for (i = 0; i < num_sprole_pws; i++) {
56413 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56414 + *salt = acl_special_roles[i]->salt;
56415 + *sum = acl_special_roles[i]->sum;
56416 + return 1;
56417 + }
56418 + }
56419 +
56420 + return 0;
56421 +}
56422 +
56423 +static void
56424 +assign_special_role(char *rolename)
56425 +{
56426 + struct acl_object_label *obj;
56427 + struct acl_role_label *r;
56428 + struct acl_role_label *assigned = NULL;
56429 + struct task_struct *tsk;
56430 + struct file *filp;
56431 +
56432 + FOR_EACH_ROLE_START(r)
56433 + if (!strcmp(rolename, r->rolename) &&
56434 + (r->roletype & GR_ROLE_SPECIAL)) {
56435 + assigned = r;
56436 + break;
56437 + }
56438 + FOR_EACH_ROLE_END(r)
56439 +
56440 + if (!assigned)
56441 + return;
56442 +
56443 + read_lock(&tasklist_lock);
56444 + read_lock(&grsec_exec_file_lock);
56445 +
56446 + tsk = current->real_parent;
56447 + if (tsk == NULL)
56448 + goto out_unlock;
56449 +
56450 + filp = tsk->exec_file;
56451 + if (filp == NULL)
56452 + goto out_unlock;
56453 +
56454 + tsk->is_writable = 0;
56455 +
56456 + tsk->acl_sp_role = 1;
56457 + tsk->acl_role_id = ++acl_sp_role_value;
56458 + tsk->role = assigned;
56459 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56460 +
56461 + /* ignore additional mmap checks for processes that are writable
56462 + by the default ACL */
56463 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56464 + if (unlikely(obj->mode & GR_WRITE))
56465 + tsk->is_writable = 1;
56466 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56467 + if (unlikely(obj->mode & GR_WRITE))
56468 + tsk->is_writable = 1;
56469 +
56470 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56471 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56472 +#endif
56473 +
56474 +out_unlock:
56475 + read_unlock(&grsec_exec_file_lock);
56476 + read_unlock(&tasklist_lock);
56477 + return;
56478 +}
56479 +
56480 +int gr_check_secure_terminal(struct task_struct *task)
56481 +{
56482 + struct task_struct *p, *p2, *p3;
56483 + struct files_struct *files;
56484 + struct fdtable *fdt;
56485 + struct file *our_file = NULL, *file;
56486 + int i;
56487 +
56488 + if (task->signal->tty == NULL)
56489 + return 1;
56490 +
56491 + files = get_files_struct(task);
56492 + if (files != NULL) {
56493 + rcu_read_lock();
56494 + fdt = files_fdtable(files);
56495 + for (i=0; i < fdt->max_fds; i++) {
56496 + file = fcheck_files(files, i);
56497 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56498 + get_file(file);
56499 + our_file = file;
56500 + }
56501 + }
56502 + rcu_read_unlock();
56503 + put_files_struct(files);
56504 + }
56505 +
56506 + if (our_file == NULL)
56507 + return 1;
56508 +
56509 + read_lock(&tasklist_lock);
56510 + do_each_thread(p2, p) {
56511 + files = get_files_struct(p);
56512 + if (files == NULL ||
56513 + (p->signal && p->signal->tty == task->signal->tty)) {
56514 + if (files != NULL)
56515 + put_files_struct(files);
56516 + continue;
56517 + }
56518 + rcu_read_lock();
56519 + fdt = files_fdtable(files);
56520 + for (i=0; i < fdt->max_fds; i++) {
56521 + file = fcheck_files(files, i);
56522 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56523 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56524 + p3 = task;
56525 + while (p3->pid > 0) {
56526 + if (p3 == p)
56527 + break;
56528 + p3 = p3->real_parent;
56529 + }
56530 + if (p3 == p)
56531 + break;
56532 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56533 + gr_handle_alertkill(p);
56534 + rcu_read_unlock();
56535 + put_files_struct(files);
56536 + read_unlock(&tasklist_lock);
56537 + fput(our_file);
56538 + return 0;
56539 + }
56540 + }
56541 + rcu_read_unlock();
56542 + put_files_struct(files);
56543 + } while_each_thread(p2, p);
56544 + read_unlock(&tasklist_lock);
56545 +
56546 + fput(our_file);
56547 + return 1;
56548 +}
56549 +
56550 +static int gr_rbac_disable(void *unused)
56551 +{
56552 + pax_open_kernel();
56553 + gr_status &= ~GR_READY;
56554 + pax_close_kernel();
56555 +
56556 + return 0;
56557 +}
56558 +
56559 +ssize_t
56560 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56561 +{
56562 + struct gr_arg_wrapper uwrap;
56563 + unsigned char *sprole_salt = NULL;
56564 + unsigned char *sprole_sum = NULL;
56565 + int error = sizeof (struct gr_arg_wrapper);
56566 + int error2 = 0;
56567 +
56568 + mutex_lock(&gr_dev_mutex);
56569 +
56570 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56571 + error = -EPERM;
56572 + goto out;
56573 + }
56574 +
56575 + if (count != sizeof (struct gr_arg_wrapper)) {
56576 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56577 + error = -EINVAL;
56578 + goto out;
56579 + }
56580 +
56581 +
56582 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56583 + gr_auth_expires = 0;
56584 + gr_auth_attempts = 0;
56585 + }
56586 +
56587 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56588 + error = -EFAULT;
56589 + goto out;
56590 + }
56591 +
56592 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56593 + error = -EINVAL;
56594 + goto out;
56595 + }
56596 +
56597 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56598 + error = -EFAULT;
56599 + goto out;
56600 + }
56601 +
56602 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56603 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56604 + time_after(gr_auth_expires, get_seconds())) {
56605 + error = -EBUSY;
56606 + goto out;
56607 + }
56608 +
56609 + /* if non-root trying to do anything other than use a special role,
56610 + do not attempt authentication, do not count towards authentication
56611 + locking
56612 + */
56613 +
56614 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56615 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56616 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56617 + error = -EPERM;
56618 + goto out;
56619 + }
56620 +
56621 + /* ensure pw and special role name are null terminated */
56622 +
56623 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56624 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56625 +
56626 + /* Okay.
56627 + * We have our enough of the argument structure..(we have yet
56628 + * to copy_from_user the tables themselves) . Copy the tables
56629 + * only if we need them, i.e. for loading operations. */
56630 +
56631 + switch (gr_usermode->mode) {
56632 + case GR_STATUS:
56633 + if (gr_status & GR_READY) {
56634 + error = 1;
56635 + if (!gr_check_secure_terminal(current))
56636 + error = 3;
56637 + } else
56638 + error = 2;
56639 + goto out;
56640 + case GR_SHUTDOWN:
56641 + if ((gr_status & GR_READY)
56642 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56643 + stop_machine(gr_rbac_disable, NULL, NULL);
56644 + free_variables();
56645 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56646 + memset(gr_system_salt, 0, GR_SALT_LEN);
56647 + memset(gr_system_sum, 0, GR_SHA_LEN);
56648 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56649 + } else if (gr_status & GR_READY) {
56650 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56651 + error = -EPERM;
56652 + } else {
56653 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56654 + error = -EAGAIN;
56655 + }
56656 + break;
56657 + case GR_ENABLE:
56658 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56659 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56660 + else {
56661 + if (gr_status & GR_READY)
56662 + error = -EAGAIN;
56663 + else
56664 + error = error2;
56665 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56666 + }
56667 + break;
56668 + case GR_RELOAD:
56669 + if (!(gr_status & GR_READY)) {
56670 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56671 + error = -EAGAIN;
56672 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56673 + stop_machine(gr_rbac_disable, NULL, NULL);
56674 + free_variables();
56675 + error2 = gracl_init(gr_usermode);
56676 + if (!error2)
56677 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56678 + else {
56679 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56680 + error = error2;
56681 + }
56682 + } else {
56683 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56684 + error = -EPERM;
56685 + }
56686 + break;
56687 + case GR_SEGVMOD:
56688 + if (unlikely(!(gr_status & GR_READY))) {
56689 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56690 + error = -EAGAIN;
56691 + break;
56692 + }
56693 +
56694 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56695 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56696 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56697 + struct acl_subject_label *segvacl;
56698 + segvacl =
56699 + lookup_acl_subj_label(gr_usermode->segv_inode,
56700 + gr_usermode->segv_device,
56701 + current->role);
56702 + if (segvacl) {
56703 + segvacl->crashes = 0;
56704 + segvacl->expires = 0;
56705 + }
56706 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56707 + gr_remove_uid(gr_usermode->segv_uid);
56708 + }
56709 + } else {
56710 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56711 + error = -EPERM;
56712 + }
56713 + break;
56714 + case GR_SPROLE:
56715 + case GR_SPROLEPAM:
56716 + if (unlikely(!(gr_status & GR_READY))) {
56717 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56718 + error = -EAGAIN;
56719 + break;
56720 + }
56721 +
56722 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56723 + current->role->expires = 0;
56724 + current->role->auth_attempts = 0;
56725 + }
56726 +
56727 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56728 + time_after(current->role->expires, get_seconds())) {
56729 + error = -EBUSY;
56730 + goto out;
56731 + }
56732 +
56733 + if (lookup_special_role_auth
56734 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56735 + && ((!sprole_salt && !sprole_sum)
56736 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56737 + char *p = "";
56738 + assign_special_role(gr_usermode->sp_role);
56739 + read_lock(&tasklist_lock);
56740 + if (current->real_parent)
56741 + p = current->real_parent->role->rolename;
56742 + read_unlock(&tasklist_lock);
56743 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56744 + p, acl_sp_role_value);
56745 + } else {
56746 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56747 + error = -EPERM;
56748 + if(!(current->role->auth_attempts++))
56749 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56750 +
56751 + goto out;
56752 + }
56753 + break;
56754 + case GR_UNSPROLE:
56755 + if (unlikely(!(gr_status & GR_READY))) {
56756 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56757 + error = -EAGAIN;
56758 + break;
56759 + }
56760 +
56761 + if (current->role->roletype & GR_ROLE_SPECIAL) {
56762 + char *p = "";
56763 + int i = 0;
56764 +
56765 + read_lock(&tasklist_lock);
56766 + if (current->real_parent) {
56767 + p = current->real_parent->role->rolename;
56768 + i = current->real_parent->acl_role_id;
56769 + }
56770 + read_unlock(&tasklist_lock);
56771 +
56772 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56773 + gr_set_acls(1);
56774 + } else {
56775 + error = -EPERM;
56776 + goto out;
56777 + }
56778 + break;
56779 + default:
56780 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56781 + error = -EINVAL;
56782 + break;
56783 + }
56784 +
56785 + if (error != -EPERM)
56786 + goto out;
56787 +
56788 + if(!(gr_auth_attempts++))
56789 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56790 +
56791 + out:
56792 + mutex_unlock(&gr_dev_mutex);
56793 + return error;
56794 +}
56795 +
56796 +/* must be called with
56797 + rcu_read_lock();
56798 + read_lock(&tasklist_lock);
56799 + read_lock(&grsec_exec_file_lock);
56800 +*/
56801 +int gr_apply_subject_to_task(struct task_struct *task)
56802 +{
56803 + struct acl_object_label *obj;
56804 + char *tmpname;
56805 + struct acl_subject_label *tmpsubj;
56806 + struct file *filp;
56807 + struct name_entry *nmatch;
56808 +
56809 + filp = task->exec_file;
56810 + if (filp == NULL)
56811 + return 0;
56812 +
56813 + /* the following is to apply the correct subject
56814 + on binaries running when the RBAC system
56815 + is enabled, when the binaries have been
56816 + replaced or deleted since their execution
56817 + -----
56818 + when the RBAC system starts, the inode/dev
56819 + from exec_file will be one the RBAC system
56820 + is unaware of. It only knows the inode/dev
56821 + of the present file on disk, or the absence
56822 + of it.
56823 + */
56824 + preempt_disable();
56825 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56826 +
56827 + nmatch = lookup_name_entry(tmpname);
56828 + preempt_enable();
56829 + tmpsubj = NULL;
56830 + if (nmatch) {
56831 + if (nmatch->deleted)
56832 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56833 + else
56834 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56835 + if (tmpsubj != NULL)
56836 + task->acl = tmpsubj;
56837 + }
56838 + if (tmpsubj == NULL)
56839 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56840 + task->role);
56841 + if (task->acl) {
56842 + task->is_writable = 0;
56843 + /* ignore additional mmap checks for processes that are writable
56844 + by the default ACL */
56845 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56846 + if (unlikely(obj->mode & GR_WRITE))
56847 + task->is_writable = 1;
56848 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56849 + if (unlikely(obj->mode & GR_WRITE))
56850 + task->is_writable = 1;
56851 +
56852 + gr_set_proc_res(task);
56853 +
56854 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56855 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56856 +#endif
56857 + } else {
56858 + return 1;
56859 + }
56860 +
56861 + return 0;
56862 +}
56863 +
56864 +int
56865 +gr_set_acls(const int type)
56866 +{
56867 + struct task_struct *task, *task2;
56868 + struct acl_role_label *role = current->role;
56869 + __u16 acl_role_id = current->acl_role_id;
56870 + const struct cred *cred;
56871 + int ret;
56872 +
56873 + rcu_read_lock();
56874 + read_lock(&tasklist_lock);
56875 + read_lock(&grsec_exec_file_lock);
56876 + do_each_thread(task2, task) {
56877 + /* check to see if we're called from the exit handler,
56878 + if so, only replace ACLs that have inherited the admin
56879 + ACL */
56880 +
56881 + if (type && (task->role != role ||
56882 + task->acl_role_id != acl_role_id))
56883 + continue;
56884 +
56885 + task->acl_role_id = 0;
56886 + task->acl_sp_role = 0;
56887 +
56888 + if (task->exec_file) {
56889 + cred = __task_cred(task);
56890 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
56891 + ret = gr_apply_subject_to_task(task);
56892 + if (ret) {
56893 + read_unlock(&grsec_exec_file_lock);
56894 + read_unlock(&tasklist_lock);
56895 + rcu_read_unlock();
56896 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
56897 + return ret;
56898 + }
56899 + } else {
56900 + // it's a kernel process
56901 + task->role = kernel_role;
56902 + task->acl = kernel_role->root_label;
56903 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
56904 + task->acl->mode &= ~GR_PROCFIND;
56905 +#endif
56906 + }
56907 + } while_each_thread(task2, task);
56908 + read_unlock(&grsec_exec_file_lock);
56909 + read_unlock(&tasklist_lock);
56910 + rcu_read_unlock();
56911 +
56912 + return 0;
56913 +}
56914 +
56915 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
56916 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
56917 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
56918 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
56919 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
56920 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
56921 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
56922 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
56923 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
56924 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
56925 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
56926 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
56927 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
56928 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
56929 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
56930 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
56931 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
56932 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
56933 +};
56934 +
56935 +void
56936 +gr_learn_resource(const struct task_struct *task,
56937 + const int res, const unsigned long wanted, const int gt)
56938 +{
56939 + struct acl_subject_label *acl;
56940 + const struct cred *cred;
56941 +
56942 + if (unlikely((gr_status & GR_READY) &&
56943 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
56944 + goto skip_reslog;
56945 +
56946 + gr_log_resource(task, res, wanted, gt);
56947 +skip_reslog:
56948 +
56949 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
56950 + return;
56951 +
56952 + acl = task->acl;
56953 +
56954 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
56955 + !(acl->resmask & (1 << (unsigned short) res))))
56956 + return;
56957 +
56958 + if (wanted >= acl->res[res].rlim_cur) {
56959 + unsigned long res_add;
56960 +
56961 + res_add = wanted + res_learn_bumps[res];
56962 +
56963 + acl->res[res].rlim_cur = res_add;
56964 +
56965 + if (wanted > acl->res[res].rlim_max)
56966 + acl->res[res].rlim_max = res_add;
56967 +
56968 + /* only log the subject filename, since resource logging is supported for
56969 + single-subject learning only */
56970 + rcu_read_lock();
56971 + cred = __task_cred(task);
56972 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56973 + task->role->roletype, cred->uid, cred->gid, acl->filename,
56974 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
56975 + "", (unsigned long) res, &task->signal->saved_ip);
56976 + rcu_read_unlock();
56977 + }
56978 +
56979 + return;
56980 +}
56981 +EXPORT_SYMBOL(gr_learn_resource);
56982 +#endif
56983 +
56984 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
56985 +void
56986 +pax_set_initial_flags(struct linux_binprm *bprm)
56987 +{
56988 + struct task_struct *task = current;
56989 + struct acl_subject_label *proc;
56990 + unsigned long flags;
56991 +
56992 + if (unlikely(!(gr_status & GR_READY)))
56993 + return;
56994 +
56995 + flags = pax_get_flags(task);
56996 +
56997 + proc = task->acl;
56998 +
56999 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57000 + flags &= ~MF_PAX_PAGEEXEC;
57001 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57002 + flags &= ~MF_PAX_SEGMEXEC;
57003 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57004 + flags &= ~MF_PAX_RANDMMAP;
57005 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57006 + flags &= ~MF_PAX_EMUTRAMP;
57007 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57008 + flags &= ~MF_PAX_MPROTECT;
57009 +
57010 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57011 + flags |= MF_PAX_PAGEEXEC;
57012 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57013 + flags |= MF_PAX_SEGMEXEC;
57014 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57015 + flags |= MF_PAX_RANDMMAP;
57016 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57017 + flags |= MF_PAX_EMUTRAMP;
57018 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57019 + flags |= MF_PAX_MPROTECT;
57020 +
57021 + pax_set_flags(task, flags);
57022 +
57023 + return;
57024 +}
57025 +#endif
57026 +
57027 +int
57028 +gr_handle_proc_ptrace(struct task_struct *task)
57029 +{
57030 + struct file *filp;
57031 + struct task_struct *tmp = task;
57032 + struct task_struct *curtemp = current;
57033 + __u32 retmode;
57034 +
57035 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57036 + if (unlikely(!(gr_status & GR_READY)))
57037 + return 0;
57038 +#endif
57039 +
57040 + read_lock(&tasklist_lock);
57041 + read_lock(&grsec_exec_file_lock);
57042 + filp = task->exec_file;
57043 +
57044 + while (tmp->pid > 0) {
57045 + if (tmp == curtemp)
57046 + break;
57047 + tmp = tmp->real_parent;
57048 + }
57049 +
57050 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57051 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57052 + read_unlock(&grsec_exec_file_lock);
57053 + read_unlock(&tasklist_lock);
57054 + return 1;
57055 + }
57056 +
57057 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57058 + if (!(gr_status & GR_READY)) {
57059 + read_unlock(&grsec_exec_file_lock);
57060 + read_unlock(&tasklist_lock);
57061 + return 0;
57062 + }
57063 +#endif
57064 +
57065 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57066 + read_unlock(&grsec_exec_file_lock);
57067 + read_unlock(&tasklist_lock);
57068 +
57069 + if (retmode & GR_NOPTRACE)
57070 + return 1;
57071 +
57072 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57073 + && (current->acl != task->acl || (current->acl != current->role->root_label
57074 + && current->pid != task->pid)))
57075 + return 1;
57076 +
57077 + return 0;
57078 +}
57079 +
57080 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57081 +{
57082 + if (unlikely(!(gr_status & GR_READY)))
57083 + return;
57084 +
57085 + if (!(current->role->roletype & GR_ROLE_GOD))
57086 + return;
57087 +
57088 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
57089 + p->role->rolename, gr_task_roletype_to_char(p),
57090 + p->acl->filename);
57091 +}
57092 +
57093 +int
57094 +gr_handle_ptrace(struct task_struct *task, const long request)
57095 +{
57096 + struct task_struct *tmp = task;
57097 + struct task_struct *curtemp = current;
57098 + __u32 retmode;
57099 +
57100 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57101 + if (unlikely(!(gr_status & GR_READY)))
57102 + return 0;
57103 +#endif
57104 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57105 + read_lock(&tasklist_lock);
57106 + while (tmp->pid > 0) {
57107 + if (tmp == curtemp)
57108 + break;
57109 + tmp = tmp->real_parent;
57110 + }
57111 +
57112 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57113 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57114 + read_unlock(&tasklist_lock);
57115 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57116 + return 1;
57117 + }
57118 + read_unlock(&tasklist_lock);
57119 + }
57120 +
57121 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57122 + if (!(gr_status & GR_READY))
57123 + return 0;
57124 +#endif
57125 +
57126 + read_lock(&grsec_exec_file_lock);
57127 + if (unlikely(!task->exec_file)) {
57128 + read_unlock(&grsec_exec_file_lock);
57129 + return 0;
57130 + }
57131 +
57132 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57133 + read_unlock(&grsec_exec_file_lock);
57134 +
57135 + if (retmode & GR_NOPTRACE) {
57136 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57137 + return 1;
57138 + }
57139 +
57140 + if (retmode & GR_PTRACERD) {
57141 + switch (request) {
57142 + case PTRACE_SEIZE:
57143 + case PTRACE_POKETEXT:
57144 + case PTRACE_POKEDATA:
57145 + case PTRACE_POKEUSR:
57146 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57147 + case PTRACE_SETREGS:
57148 + case PTRACE_SETFPREGS:
57149 +#endif
57150 +#ifdef CONFIG_X86
57151 + case PTRACE_SETFPXREGS:
57152 +#endif
57153 +#ifdef CONFIG_ALTIVEC
57154 + case PTRACE_SETVRREGS:
57155 +#endif
57156 + return 1;
57157 + default:
57158 + return 0;
57159 + }
57160 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
57161 + !(current->role->roletype & GR_ROLE_GOD) &&
57162 + (current->acl != task->acl)) {
57163 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57164 + return 1;
57165 + }
57166 +
57167 + return 0;
57168 +}
57169 +
57170 +static int is_writable_mmap(const struct file *filp)
57171 +{
57172 + struct task_struct *task = current;
57173 + struct acl_object_label *obj, *obj2;
57174 +
57175 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57176 + !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))) {
57177 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57178 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57179 + task->role->root_label);
57180 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57181 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57182 + return 1;
57183 + }
57184 + }
57185 + return 0;
57186 +}
57187 +
57188 +int
57189 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57190 +{
57191 + __u32 mode;
57192 +
57193 + if (unlikely(!file || !(prot & PROT_EXEC)))
57194 + return 1;
57195 +
57196 + if (is_writable_mmap(file))
57197 + return 0;
57198 +
57199 + mode =
57200 + gr_search_file(file->f_path.dentry,
57201 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57202 + file->f_path.mnt);
57203 +
57204 + if (!gr_tpe_allow(file))
57205 + return 0;
57206 +
57207 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57208 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57209 + return 0;
57210 + } else if (unlikely(!(mode & GR_EXEC))) {
57211 + return 0;
57212 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57213 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57214 + return 1;
57215 + }
57216 +
57217 + return 1;
57218 +}
57219 +
57220 +int
57221 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57222 +{
57223 + __u32 mode;
57224 +
57225 + if (unlikely(!file || !(prot & PROT_EXEC)))
57226 + return 1;
57227 +
57228 + if (is_writable_mmap(file))
57229 + return 0;
57230 +
57231 + mode =
57232 + gr_search_file(file->f_path.dentry,
57233 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57234 + file->f_path.mnt);
57235 +
57236 + if (!gr_tpe_allow(file))
57237 + return 0;
57238 +
57239 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57240 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57241 + return 0;
57242 + } else if (unlikely(!(mode & GR_EXEC))) {
57243 + return 0;
57244 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57245 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57246 + return 1;
57247 + }
57248 +
57249 + return 1;
57250 +}
57251 +
57252 +void
57253 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57254 +{
57255 + unsigned long runtime;
57256 + unsigned long cputime;
57257 + unsigned int wday, cday;
57258 + __u8 whr, chr;
57259 + __u8 wmin, cmin;
57260 + __u8 wsec, csec;
57261 + struct timespec timeval;
57262 +
57263 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57264 + !(task->acl->mode & GR_PROCACCT)))
57265 + return;
57266 +
57267 + do_posix_clock_monotonic_gettime(&timeval);
57268 + runtime = timeval.tv_sec - task->start_time.tv_sec;
57269 + wday = runtime / (3600 * 24);
57270 + runtime -= wday * (3600 * 24);
57271 + whr = runtime / 3600;
57272 + runtime -= whr * 3600;
57273 + wmin = runtime / 60;
57274 + runtime -= wmin * 60;
57275 + wsec = runtime;
57276 +
57277 + cputime = (task->utime + task->stime) / HZ;
57278 + cday = cputime / (3600 * 24);
57279 + cputime -= cday * (3600 * 24);
57280 + chr = cputime / 3600;
57281 + cputime -= chr * 3600;
57282 + cmin = cputime / 60;
57283 + cputime -= cmin * 60;
57284 + csec = cputime;
57285 +
57286 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57287 +
57288 + return;
57289 +}
57290 +
57291 +void gr_set_kernel_label(struct task_struct *task)
57292 +{
57293 + if (gr_status & GR_READY) {
57294 + task->role = kernel_role;
57295 + task->acl = kernel_role->root_label;
57296 + }
57297 + return;
57298 +}
57299 +
57300 +#ifdef CONFIG_TASKSTATS
57301 +int gr_is_taskstats_denied(int pid)
57302 +{
57303 + struct task_struct *task;
57304 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57305 + const struct cred *cred;
57306 +#endif
57307 + int ret = 0;
57308 +
57309 + /* restrict taskstats viewing to un-chrooted root users
57310 + who have the 'view' subject flag if the RBAC system is enabled
57311 + */
57312 +
57313 + rcu_read_lock();
57314 + read_lock(&tasklist_lock);
57315 + task = find_task_by_vpid(pid);
57316 + if (task) {
57317 +#ifdef CONFIG_GRKERNSEC_CHROOT
57318 + if (proc_is_chrooted(task))
57319 + ret = -EACCES;
57320 +#endif
57321 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57322 + cred = __task_cred(task);
57323 +#ifdef CONFIG_GRKERNSEC_PROC_USER
57324 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57325 + ret = -EACCES;
57326 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57327 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57328 + ret = -EACCES;
57329 +#endif
57330 +#endif
57331 + if (gr_status & GR_READY) {
57332 + if (!(task->acl->mode & GR_VIEW))
57333 + ret = -EACCES;
57334 + }
57335 + } else
57336 + ret = -ENOENT;
57337 +
57338 + read_unlock(&tasklist_lock);
57339 + rcu_read_unlock();
57340 +
57341 + return ret;
57342 +}
57343 +#endif
57344 +
57345 +/* AUXV entries are filled via a descendant of search_binary_handler
57346 + after we've already applied the subject for the target
57347 +*/
57348 +int gr_acl_enable_at_secure(void)
57349 +{
57350 + if (unlikely(!(gr_status & GR_READY)))
57351 + return 0;
57352 +
57353 + if (current->acl->mode & GR_ATSECURE)
57354 + return 1;
57355 +
57356 + return 0;
57357 +}
57358 +
57359 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57360 +{
57361 + struct task_struct *task = current;
57362 + struct dentry *dentry = file->f_path.dentry;
57363 + struct vfsmount *mnt = file->f_path.mnt;
57364 + struct acl_object_label *obj, *tmp;
57365 + struct acl_subject_label *subj;
57366 + unsigned int bufsize;
57367 + int is_not_root;
57368 + char *path;
57369 + dev_t dev = __get_dev(dentry);
57370 +
57371 + if (unlikely(!(gr_status & GR_READY)))
57372 + return 1;
57373 +
57374 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57375 + return 1;
57376 +
57377 + /* ignore Eric Biederman */
57378 + if (IS_PRIVATE(dentry->d_inode))
57379 + return 1;
57380 +
57381 + subj = task->acl;
57382 + read_lock(&gr_inode_lock);
57383 + do {
57384 + obj = lookup_acl_obj_label(ino, dev, subj);
57385 + if (obj != NULL) {
57386 + read_unlock(&gr_inode_lock);
57387 + return (obj->mode & GR_FIND) ? 1 : 0;
57388 + }
57389 + } while ((subj = subj->parent_subject));
57390 + read_unlock(&gr_inode_lock);
57391 +
57392 + /* this is purely an optimization since we're looking for an object
57393 + for the directory we're doing a readdir on
57394 + if it's possible for any globbed object to match the entry we're
57395 + filling into the directory, then the object we find here will be
57396 + an anchor point with attached globbed objects
57397 + */
57398 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57399 + if (obj->globbed == NULL)
57400 + return (obj->mode & GR_FIND) ? 1 : 0;
57401 +
57402 + is_not_root = ((obj->filename[0] == '/') &&
57403 + (obj->filename[1] == '\0')) ? 0 : 1;
57404 + bufsize = PAGE_SIZE - namelen - is_not_root;
57405 +
57406 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
57407 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57408 + return 1;
57409 +
57410 + preempt_disable();
57411 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57412 + bufsize);
57413 +
57414 + bufsize = strlen(path);
57415 +
57416 + /* if base is "/", don't append an additional slash */
57417 + if (is_not_root)
57418 + *(path + bufsize) = '/';
57419 + memcpy(path + bufsize + is_not_root, name, namelen);
57420 + *(path + bufsize + namelen + is_not_root) = '\0';
57421 +
57422 + tmp = obj->globbed;
57423 + while (tmp) {
57424 + if (!glob_match(tmp->filename, path)) {
57425 + preempt_enable();
57426 + return (tmp->mode & GR_FIND) ? 1 : 0;
57427 + }
57428 + tmp = tmp->next;
57429 + }
57430 + preempt_enable();
57431 + return (obj->mode & GR_FIND) ? 1 : 0;
57432 +}
57433 +
57434 +void gr_put_exec_file(struct task_struct *task)
57435 +{
57436 + struct file *filp;
57437 +
57438 + write_lock(&grsec_exec_file_lock);
57439 + filp = task->exec_file;
57440 + task->exec_file = NULL;
57441 + write_unlock(&grsec_exec_file_lock);
57442 +
57443 + if (filp)
57444 + fput(filp);
57445 +
57446 + return;
57447 +}
57448 +
57449 +
57450 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57451 +EXPORT_SYMBOL(gr_acl_is_enabled);
57452 +#endif
57453 +EXPORT_SYMBOL(gr_set_kernel_label);
57454 +#ifdef CONFIG_SECURITY
57455 +EXPORT_SYMBOL(gr_check_user_change);
57456 +EXPORT_SYMBOL(gr_check_group_change);
57457 +#endif
57458 +
57459 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57460 new file mode 100644
57461 index 0000000..34fefda
57462 --- /dev/null
57463 +++ b/grsecurity/gracl_alloc.c
57464 @@ -0,0 +1,105 @@
57465 +#include <linux/kernel.h>
57466 +#include <linux/mm.h>
57467 +#include <linux/slab.h>
57468 +#include <linux/vmalloc.h>
57469 +#include <linux/gracl.h>
57470 +#include <linux/grsecurity.h>
57471 +
57472 +static unsigned long alloc_stack_next = 1;
57473 +static unsigned long alloc_stack_size = 1;
57474 +static void **alloc_stack;
57475 +
57476 +static __inline__ int
57477 +alloc_pop(void)
57478 +{
57479 + if (alloc_stack_next == 1)
57480 + return 0;
57481 +
57482 + kfree(alloc_stack[alloc_stack_next - 2]);
57483 +
57484 + alloc_stack_next--;
57485 +
57486 + return 1;
57487 +}
57488 +
57489 +static __inline__ int
57490 +alloc_push(void *buf)
57491 +{
57492 + if (alloc_stack_next >= alloc_stack_size)
57493 + return 1;
57494 +
57495 + alloc_stack[alloc_stack_next - 1] = buf;
57496 +
57497 + alloc_stack_next++;
57498 +
57499 + return 0;
57500 +}
57501 +
57502 +void *
57503 +acl_alloc(unsigned long len)
57504 +{
57505 + void *ret = NULL;
57506 +
57507 + if (!len || len > PAGE_SIZE)
57508 + goto out;
57509 +
57510 + ret = kmalloc(len, GFP_KERNEL);
57511 +
57512 + if (ret) {
57513 + if (alloc_push(ret)) {
57514 + kfree(ret);
57515 + ret = NULL;
57516 + }
57517 + }
57518 +
57519 +out:
57520 + return ret;
57521 +}
57522 +
57523 +void *
57524 +acl_alloc_num(unsigned long num, unsigned long len)
57525 +{
57526 + if (!len || (num > (PAGE_SIZE / len)))
57527 + return NULL;
57528 +
57529 + return acl_alloc(num * len);
57530 +}
57531 +
57532 +void
57533 +acl_free_all(void)
57534 +{
57535 + if (gr_acl_is_enabled() || !alloc_stack)
57536 + return;
57537 +
57538 + while (alloc_pop()) ;
57539 +
57540 + if (alloc_stack) {
57541 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57542 + kfree(alloc_stack);
57543 + else
57544 + vfree(alloc_stack);
57545 + }
57546 +
57547 + alloc_stack = NULL;
57548 + alloc_stack_size = 1;
57549 + alloc_stack_next = 1;
57550 +
57551 + return;
57552 +}
57553 +
57554 +int
57555 +acl_alloc_stack_init(unsigned long size)
57556 +{
57557 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57558 + alloc_stack =
57559 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57560 + else
57561 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57562 +
57563 + alloc_stack_size = size;
57564 +
57565 + if (!alloc_stack)
57566 + return 0;
57567 + else
57568 + return 1;
57569 +}
57570 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57571 new file mode 100644
57572 index 0000000..6d21049
57573 --- /dev/null
57574 +++ b/grsecurity/gracl_cap.c
57575 @@ -0,0 +1,110 @@
57576 +#include <linux/kernel.h>
57577 +#include <linux/module.h>
57578 +#include <linux/sched.h>
57579 +#include <linux/gracl.h>
57580 +#include <linux/grsecurity.h>
57581 +#include <linux/grinternal.h>
57582 +
57583 +extern const char *captab_log[];
57584 +extern int captab_log_entries;
57585 +
57586 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57587 +{
57588 + struct acl_subject_label *curracl;
57589 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57590 + kernel_cap_t cap_audit = __cap_empty_set;
57591 +
57592 + if (!gr_acl_is_enabled())
57593 + return 1;
57594 +
57595 + curracl = task->acl;
57596 +
57597 + cap_drop = curracl->cap_lower;
57598 + cap_mask = curracl->cap_mask;
57599 + cap_audit = curracl->cap_invert_audit;
57600 +
57601 + while ((curracl = curracl->parent_subject)) {
57602 + /* if the cap isn't specified in the current computed mask but is specified in the
57603 + current level subject, and is lowered in the current level subject, then add
57604 + it to the set of dropped capabilities
57605 + otherwise, add the current level subject's mask to the current computed mask
57606 + */
57607 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57608 + cap_raise(cap_mask, cap);
57609 + if (cap_raised(curracl->cap_lower, cap))
57610 + cap_raise(cap_drop, cap);
57611 + if (cap_raised(curracl->cap_invert_audit, cap))
57612 + cap_raise(cap_audit, cap);
57613 + }
57614 + }
57615 +
57616 + if (!cap_raised(cap_drop, cap)) {
57617 + if (cap_raised(cap_audit, cap))
57618 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57619 + return 1;
57620 + }
57621 +
57622 + curracl = task->acl;
57623 +
57624 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57625 + && cap_raised(cred->cap_effective, cap)) {
57626 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57627 + task->role->roletype, cred->uid,
57628 + cred->gid, task->exec_file ?
57629 + gr_to_filename(task->exec_file->f_path.dentry,
57630 + task->exec_file->f_path.mnt) : curracl->filename,
57631 + curracl->filename, 0UL,
57632 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57633 + return 1;
57634 + }
57635 +
57636 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57637 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57638 +
57639 + return 0;
57640 +}
57641 +
57642 +int
57643 +gr_acl_is_capable(const int cap)
57644 +{
57645 + return gr_task_acl_is_capable(current, current_cred(), cap);
57646 +}
57647 +
57648 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57649 +{
57650 + struct acl_subject_label *curracl;
57651 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57652 +
57653 + if (!gr_acl_is_enabled())
57654 + return 1;
57655 +
57656 + curracl = task->acl;
57657 +
57658 + cap_drop = curracl->cap_lower;
57659 + cap_mask = curracl->cap_mask;
57660 +
57661 + while ((curracl = curracl->parent_subject)) {
57662 + /* if the cap isn't specified in the current computed mask but is specified in the
57663 + current level subject, and is lowered in the current level subject, then add
57664 + it to the set of dropped capabilities
57665 + otherwise, add the current level subject's mask to the current computed mask
57666 + */
57667 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57668 + cap_raise(cap_mask, cap);
57669 + if (cap_raised(curracl->cap_lower, cap))
57670 + cap_raise(cap_drop, cap);
57671 + }
57672 + }
57673 +
57674 + if (!cap_raised(cap_drop, cap))
57675 + return 1;
57676 +
57677 + return 0;
57678 +}
57679 +
57680 +int
57681 +gr_acl_is_capable_nolog(const int cap)
57682 +{
57683 + return gr_task_acl_is_capable_nolog(current, cap);
57684 +}
57685 +
57686 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57687 new file mode 100644
57688 index 0000000..a340c17
57689 --- /dev/null
57690 +++ b/grsecurity/gracl_fs.c
57691 @@ -0,0 +1,431 @@
57692 +#include <linux/kernel.h>
57693 +#include <linux/sched.h>
57694 +#include <linux/types.h>
57695 +#include <linux/fs.h>
57696 +#include <linux/file.h>
57697 +#include <linux/stat.h>
57698 +#include <linux/grsecurity.h>
57699 +#include <linux/grinternal.h>
57700 +#include <linux/gracl.h>
57701 +
57702 +umode_t
57703 +gr_acl_umask(void)
57704 +{
57705 + if (unlikely(!gr_acl_is_enabled()))
57706 + return 0;
57707 +
57708 + return current->role->umask;
57709 +}
57710 +
57711 +__u32
57712 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57713 + const struct vfsmount * mnt)
57714 +{
57715 + __u32 mode;
57716 +
57717 + if (unlikely(!dentry->d_inode))
57718 + return GR_FIND;
57719 +
57720 + mode =
57721 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57722 +
57723 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57724 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57725 + return mode;
57726 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57727 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57728 + return 0;
57729 + } else if (unlikely(!(mode & GR_FIND)))
57730 + return 0;
57731 +
57732 + return GR_FIND;
57733 +}
57734 +
57735 +__u32
57736 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57737 + int acc_mode)
57738 +{
57739 + __u32 reqmode = GR_FIND;
57740 + __u32 mode;
57741 +
57742 + if (unlikely(!dentry->d_inode))
57743 + return reqmode;
57744 +
57745 + if (acc_mode & MAY_APPEND)
57746 + reqmode |= GR_APPEND;
57747 + else if (acc_mode & MAY_WRITE)
57748 + reqmode |= GR_WRITE;
57749 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57750 + reqmode |= GR_READ;
57751 +
57752 + mode =
57753 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57754 + mnt);
57755 +
57756 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57757 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57758 + reqmode & GR_READ ? " reading" : "",
57759 + reqmode & GR_WRITE ? " writing" : reqmode &
57760 + GR_APPEND ? " appending" : "");
57761 + return reqmode;
57762 + } else
57763 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57764 + {
57765 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57766 + reqmode & GR_READ ? " reading" : "",
57767 + reqmode & GR_WRITE ? " writing" : reqmode &
57768 + GR_APPEND ? " appending" : "");
57769 + return 0;
57770 + } else if (unlikely((mode & reqmode) != reqmode))
57771 + return 0;
57772 +
57773 + return reqmode;
57774 +}
57775 +
57776 +__u32
57777 +gr_acl_handle_creat(const struct dentry * dentry,
57778 + const struct dentry * p_dentry,
57779 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57780 + const int imode)
57781 +{
57782 + __u32 reqmode = GR_WRITE | GR_CREATE;
57783 + __u32 mode;
57784 +
57785 + if (acc_mode & MAY_APPEND)
57786 + reqmode |= GR_APPEND;
57787 + // if a directory was required or the directory already exists, then
57788 + // don't count this open as a read
57789 + if ((acc_mode & MAY_READ) &&
57790 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57791 + reqmode |= GR_READ;
57792 + if ((open_flags & O_CREAT) &&
57793 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57794 + reqmode |= GR_SETID;
57795 +
57796 + mode =
57797 + gr_check_create(dentry, p_dentry, p_mnt,
57798 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57799 +
57800 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57801 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57802 + reqmode & GR_READ ? " reading" : "",
57803 + reqmode & GR_WRITE ? " writing" : reqmode &
57804 + GR_APPEND ? " appending" : "");
57805 + return reqmode;
57806 + } else
57807 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57808 + {
57809 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57810 + reqmode & GR_READ ? " reading" : "",
57811 + reqmode & GR_WRITE ? " writing" : reqmode &
57812 + GR_APPEND ? " appending" : "");
57813 + return 0;
57814 + } else if (unlikely((mode & reqmode) != reqmode))
57815 + return 0;
57816 +
57817 + return reqmode;
57818 +}
57819 +
57820 +__u32
57821 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57822 + const int fmode)
57823 +{
57824 + __u32 mode, reqmode = GR_FIND;
57825 +
57826 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57827 + reqmode |= GR_EXEC;
57828 + if (fmode & S_IWOTH)
57829 + reqmode |= GR_WRITE;
57830 + if (fmode & S_IROTH)
57831 + reqmode |= GR_READ;
57832 +
57833 + mode =
57834 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57835 + mnt);
57836 +
57837 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57838 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57839 + reqmode & GR_READ ? " reading" : "",
57840 + reqmode & GR_WRITE ? " writing" : "",
57841 + reqmode & GR_EXEC ? " executing" : "");
57842 + return reqmode;
57843 + } else
57844 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57845 + {
57846 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57847 + reqmode & GR_READ ? " reading" : "",
57848 + reqmode & GR_WRITE ? " writing" : "",
57849 + reqmode & GR_EXEC ? " executing" : "");
57850 + return 0;
57851 + } else if (unlikely((mode & reqmode) != reqmode))
57852 + return 0;
57853 +
57854 + return reqmode;
57855 +}
57856 +
57857 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57858 +{
57859 + __u32 mode;
57860 +
57861 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57862 +
57863 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57864 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57865 + return mode;
57866 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57867 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57868 + return 0;
57869 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
57870 + return 0;
57871 +
57872 + return (reqmode);
57873 +}
57874 +
57875 +__u32
57876 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57877 +{
57878 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57879 +}
57880 +
57881 +__u32
57882 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57883 +{
57884 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57885 +}
57886 +
57887 +__u32
57888 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
57889 +{
57890 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
57891 +}
57892 +
57893 +__u32
57894 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
57895 +{
57896 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
57897 +}
57898 +
57899 +__u32
57900 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
57901 + umode_t *modeptr)
57902 +{
57903 + umode_t mode;
57904 +
57905 + *modeptr &= ~gr_acl_umask();
57906 + mode = *modeptr;
57907 +
57908 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
57909 + return 1;
57910 +
57911 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
57912 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
57913 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
57914 + GR_CHMOD_ACL_MSG);
57915 + } else {
57916 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
57917 + }
57918 +}
57919 +
57920 +__u32
57921 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
57922 +{
57923 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
57924 +}
57925 +
57926 +__u32
57927 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
57928 +{
57929 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
57930 +}
57931 +
57932 +__u32
57933 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
57934 +{
57935 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
57936 +}
57937 +
57938 +__u32
57939 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
57940 +{
57941 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
57942 + GR_UNIXCONNECT_ACL_MSG);
57943 +}
57944 +
57945 +/* hardlinks require at minimum create and link permission,
57946 + any additional privilege required is based on the
57947 + privilege of the file being linked to
57948 +*/
57949 +__u32
57950 +gr_acl_handle_link(const struct dentry * new_dentry,
57951 + const struct dentry * parent_dentry,
57952 + const struct vfsmount * parent_mnt,
57953 + const struct dentry * old_dentry,
57954 + const struct vfsmount * old_mnt, const struct filename *to)
57955 +{
57956 + __u32 mode;
57957 + __u32 needmode = GR_CREATE | GR_LINK;
57958 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
57959 +
57960 + mode =
57961 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
57962 + old_mnt);
57963 +
57964 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
57965 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57966 + return mode;
57967 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57968 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57969 + return 0;
57970 + } else if (unlikely((mode & needmode) != needmode))
57971 + return 0;
57972 +
57973 + return 1;
57974 +}
57975 +
57976 +__u32
57977 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57978 + const struct dentry * parent_dentry,
57979 + const struct vfsmount * parent_mnt, const struct filename *from)
57980 +{
57981 + __u32 needmode = GR_WRITE | GR_CREATE;
57982 + __u32 mode;
57983 +
57984 + mode =
57985 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
57986 + GR_CREATE | GR_AUDIT_CREATE |
57987 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
57988 +
57989 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
57990 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57991 + return mode;
57992 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57993 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57994 + return 0;
57995 + } else if (unlikely((mode & needmode) != needmode))
57996 + return 0;
57997 +
57998 + return (GR_WRITE | GR_CREATE);
57999 +}
58000 +
58001 +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)
58002 +{
58003 + __u32 mode;
58004 +
58005 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58006 +
58007 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58008 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58009 + return mode;
58010 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58011 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58012 + return 0;
58013 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58014 + return 0;
58015 +
58016 + return (reqmode);
58017 +}
58018 +
58019 +__u32
58020 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58021 + const struct dentry * parent_dentry,
58022 + const struct vfsmount * parent_mnt,
58023 + const int mode)
58024 +{
58025 + __u32 reqmode = GR_WRITE | GR_CREATE;
58026 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58027 + reqmode |= GR_SETID;
58028 +
58029 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58030 + reqmode, GR_MKNOD_ACL_MSG);
58031 +}
58032 +
58033 +__u32
58034 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
58035 + const struct dentry *parent_dentry,
58036 + const struct vfsmount *parent_mnt)
58037 +{
58038 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58039 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58040 +}
58041 +
58042 +#define RENAME_CHECK_SUCCESS(old, new) \
58043 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58044 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58045 +
58046 +int
58047 +gr_acl_handle_rename(struct dentry *new_dentry,
58048 + struct dentry *parent_dentry,
58049 + const struct vfsmount *parent_mnt,
58050 + struct dentry *old_dentry,
58051 + struct inode *old_parent_inode,
58052 + struct vfsmount *old_mnt, const struct filename *newname)
58053 +{
58054 + __u32 comp1, comp2;
58055 + int error = 0;
58056 +
58057 + if (unlikely(!gr_acl_is_enabled()))
58058 + return 0;
58059 +
58060 + if (!new_dentry->d_inode) {
58061 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58062 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58063 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58064 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58065 + GR_DELETE | GR_AUDIT_DELETE |
58066 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58067 + GR_SUPPRESS, old_mnt);
58068 + } else {
58069 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58070 + GR_CREATE | GR_DELETE |
58071 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58072 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58073 + GR_SUPPRESS, parent_mnt);
58074 + comp2 =
58075 + gr_search_file(old_dentry,
58076 + GR_READ | GR_WRITE | GR_AUDIT_READ |
58077 + GR_DELETE | GR_AUDIT_DELETE |
58078 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58079 + }
58080 +
58081 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58082 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58083 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58084 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
58085 + && !(comp2 & GR_SUPPRESS)) {
58086 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58087 + error = -EACCES;
58088 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
58089 + error = -EACCES;
58090 +
58091 + return error;
58092 +}
58093 +
58094 +void
58095 +gr_acl_handle_exit(void)
58096 +{
58097 + u16 id;
58098 + char *rolename;
58099 +
58100 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58101 + !(current->role->roletype & GR_ROLE_PERSIST))) {
58102 + id = current->acl_role_id;
58103 + rolename = current->role->rolename;
58104 + gr_set_acls(1);
58105 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58106 + }
58107 +
58108 + gr_put_exec_file(current);
58109 + return;
58110 +}
58111 +
58112 +int
58113 +gr_acl_handle_procpidmem(const struct task_struct *task)
58114 +{
58115 + if (unlikely(!gr_acl_is_enabled()))
58116 + return 0;
58117 +
58118 + if (task != current && task->acl->mode & GR_PROTPROCFD)
58119 + return -EACCES;
58120 +
58121 + return 0;
58122 +}
58123 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58124 new file mode 100644
58125 index 0000000..58800a7
58126 --- /dev/null
58127 +++ b/grsecurity/gracl_ip.c
58128 @@ -0,0 +1,384 @@
58129 +#include <linux/kernel.h>
58130 +#include <asm/uaccess.h>
58131 +#include <asm/errno.h>
58132 +#include <net/sock.h>
58133 +#include <linux/file.h>
58134 +#include <linux/fs.h>
58135 +#include <linux/net.h>
58136 +#include <linux/in.h>
58137 +#include <linux/skbuff.h>
58138 +#include <linux/ip.h>
58139 +#include <linux/udp.h>
58140 +#include <linux/types.h>
58141 +#include <linux/sched.h>
58142 +#include <linux/netdevice.h>
58143 +#include <linux/inetdevice.h>
58144 +#include <linux/gracl.h>
58145 +#include <linux/grsecurity.h>
58146 +#include <linux/grinternal.h>
58147 +
58148 +#define GR_BIND 0x01
58149 +#define GR_CONNECT 0x02
58150 +#define GR_INVERT 0x04
58151 +#define GR_BINDOVERRIDE 0x08
58152 +#define GR_CONNECTOVERRIDE 0x10
58153 +#define GR_SOCK_FAMILY 0x20
58154 +
58155 +static const char * gr_protocols[IPPROTO_MAX] = {
58156 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58157 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58158 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58159 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58160 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58161 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58162 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58163 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58164 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58165 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58166 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58167 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58168 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58169 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58170 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58171 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58172 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58173 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58174 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58175 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58176 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58177 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58178 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58179 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58180 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58181 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58182 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58183 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58184 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58185 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58186 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58187 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58188 + };
58189 +
58190 +static const char * gr_socktypes[SOCK_MAX] = {
58191 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58192 + "unknown:7", "unknown:8", "unknown:9", "packet"
58193 + };
58194 +
58195 +static const char * gr_sockfamilies[AF_MAX+1] = {
58196 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58197 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58198 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58199 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58200 + };
58201 +
58202 +const char *
58203 +gr_proto_to_name(unsigned char proto)
58204 +{
58205 + return gr_protocols[proto];
58206 +}
58207 +
58208 +const char *
58209 +gr_socktype_to_name(unsigned char type)
58210 +{
58211 + return gr_socktypes[type];
58212 +}
58213 +
58214 +const char *
58215 +gr_sockfamily_to_name(unsigned char family)
58216 +{
58217 + return gr_sockfamilies[family];
58218 +}
58219 +
58220 +int
58221 +gr_search_socket(const int domain, const int type, const int protocol)
58222 +{
58223 + struct acl_subject_label *curr;
58224 + const struct cred *cred = current_cred();
58225 +
58226 + if (unlikely(!gr_acl_is_enabled()))
58227 + goto exit;
58228 +
58229 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
58230 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58231 + goto exit; // let the kernel handle it
58232 +
58233 + curr = current->acl;
58234 +
58235 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58236 + /* the family is allowed, if this is PF_INET allow it only if
58237 + the extra sock type/protocol checks pass */
58238 + if (domain == PF_INET)
58239 + goto inet_check;
58240 + goto exit;
58241 + } else {
58242 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58243 + __u32 fakeip = 0;
58244 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58245 + current->role->roletype, cred->uid,
58246 + cred->gid, current->exec_file ?
58247 + gr_to_filename(current->exec_file->f_path.dentry,
58248 + current->exec_file->f_path.mnt) :
58249 + curr->filename, curr->filename,
58250 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58251 + &current->signal->saved_ip);
58252 + goto exit;
58253 + }
58254 + goto exit_fail;
58255 + }
58256 +
58257 +inet_check:
58258 + /* the rest of this checking is for IPv4 only */
58259 + if (!curr->ips)
58260 + goto exit;
58261 +
58262 + if ((curr->ip_type & (1 << type)) &&
58263 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58264 + goto exit;
58265 +
58266 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58267 + /* we don't place acls on raw sockets , and sometimes
58268 + dgram/ip sockets are opened for ioctl and not
58269 + bind/connect, so we'll fake a bind learn log */
58270 + if (type == SOCK_RAW || type == SOCK_PACKET) {
58271 + __u32 fakeip = 0;
58272 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58273 + current->role->roletype, cred->uid,
58274 + cred->gid, current->exec_file ?
58275 + gr_to_filename(current->exec_file->f_path.dentry,
58276 + current->exec_file->f_path.mnt) :
58277 + curr->filename, curr->filename,
58278 + &fakeip, 0, type,
58279 + protocol, GR_CONNECT, &current->signal->saved_ip);
58280 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58281 + __u32 fakeip = 0;
58282 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58283 + current->role->roletype, cred->uid,
58284 + cred->gid, current->exec_file ?
58285 + gr_to_filename(current->exec_file->f_path.dentry,
58286 + current->exec_file->f_path.mnt) :
58287 + curr->filename, curr->filename,
58288 + &fakeip, 0, type,
58289 + protocol, GR_BIND, &current->signal->saved_ip);
58290 + }
58291 + /* we'll log when they use connect or bind */
58292 + goto exit;
58293 + }
58294 +
58295 +exit_fail:
58296 + if (domain == PF_INET)
58297 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58298 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
58299 + else
58300 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58301 + gr_socktype_to_name(type), protocol);
58302 +
58303 + return 0;
58304 +exit:
58305 + return 1;
58306 +}
58307 +
58308 +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)
58309 +{
58310 + if ((ip->mode & mode) &&
58311 + (ip_port >= ip->low) &&
58312 + (ip_port <= ip->high) &&
58313 + ((ntohl(ip_addr) & our_netmask) ==
58314 + (ntohl(our_addr) & our_netmask))
58315 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58316 + && (ip->type & (1 << type))) {
58317 + if (ip->mode & GR_INVERT)
58318 + return 2; // specifically denied
58319 + else
58320 + return 1; // allowed
58321 + }
58322 +
58323 + return 0; // not specifically allowed, may continue parsing
58324 +}
58325 +
58326 +static int
58327 +gr_search_connectbind(const int full_mode, struct sock *sk,
58328 + struct sockaddr_in *addr, const int type)
58329 +{
58330 + char iface[IFNAMSIZ] = {0};
58331 + struct acl_subject_label *curr;
58332 + struct acl_ip_label *ip;
58333 + struct inet_sock *isk;
58334 + struct net_device *dev;
58335 + struct in_device *idev;
58336 + unsigned long i;
58337 + int ret;
58338 + int mode = full_mode & (GR_BIND | GR_CONNECT);
58339 + __u32 ip_addr = 0;
58340 + __u32 our_addr;
58341 + __u32 our_netmask;
58342 + char *p;
58343 + __u16 ip_port = 0;
58344 + const struct cred *cred = current_cred();
58345 +
58346 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58347 + return 0;
58348 +
58349 + curr = current->acl;
58350 + isk = inet_sk(sk);
58351 +
58352 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58353 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58354 + addr->sin_addr.s_addr = curr->inaddr_any_override;
58355 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58356 + struct sockaddr_in saddr;
58357 + int err;
58358 +
58359 + saddr.sin_family = AF_INET;
58360 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
58361 + saddr.sin_port = isk->inet_sport;
58362 +
58363 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58364 + if (err)
58365 + return err;
58366 +
58367 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58368 + if (err)
58369 + return err;
58370 + }
58371 +
58372 + if (!curr->ips)
58373 + return 0;
58374 +
58375 + ip_addr = addr->sin_addr.s_addr;
58376 + ip_port = ntohs(addr->sin_port);
58377 +
58378 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58379 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58380 + current->role->roletype, cred->uid,
58381 + cred->gid, current->exec_file ?
58382 + gr_to_filename(current->exec_file->f_path.dentry,
58383 + current->exec_file->f_path.mnt) :
58384 + curr->filename, curr->filename,
58385 + &ip_addr, ip_port, type,
58386 + sk->sk_protocol, mode, &current->signal->saved_ip);
58387 + return 0;
58388 + }
58389 +
58390 + for (i = 0; i < curr->ip_num; i++) {
58391 + ip = *(curr->ips + i);
58392 + if (ip->iface != NULL) {
58393 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
58394 + p = strchr(iface, ':');
58395 + if (p != NULL)
58396 + *p = '\0';
58397 + dev = dev_get_by_name(sock_net(sk), iface);
58398 + if (dev == NULL)
58399 + continue;
58400 + idev = in_dev_get(dev);
58401 + if (idev == NULL) {
58402 + dev_put(dev);
58403 + continue;
58404 + }
58405 + rcu_read_lock();
58406 + for_ifa(idev) {
58407 + if (!strcmp(ip->iface, ifa->ifa_label)) {
58408 + our_addr = ifa->ifa_address;
58409 + our_netmask = 0xffffffff;
58410 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58411 + if (ret == 1) {
58412 + rcu_read_unlock();
58413 + in_dev_put(idev);
58414 + dev_put(dev);
58415 + return 0;
58416 + } else if (ret == 2) {
58417 + rcu_read_unlock();
58418 + in_dev_put(idev);
58419 + dev_put(dev);
58420 + goto denied;
58421 + }
58422 + }
58423 + } endfor_ifa(idev);
58424 + rcu_read_unlock();
58425 + in_dev_put(idev);
58426 + dev_put(dev);
58427 + } else {
58428 + our_addr = ip->addr;
58429 + our_netmask = ip->netmask;
58430 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58431 + if (ret == 1)
58432 + return 0;
58433 + else if (ret == 2)
58434 + goto denied;
58435 + }
58436 + }
58437 +
58438 +denied:
58439 + if (mode == GR_BIND)
58440 + 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));
58441 + else if (mode == GR_CONNECT)
58442 + 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));
58443 +
58444 + return -EACCES;
58445 +}
58446 +
58447 +int
58448 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58449 +{
58450 + /* always allow disconnection of dgram sockets with connect */
58451 + if (addr->sin_family == AF_UNSPEC)
58452 + return 0;
58453 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58454 +}
58455 +
58456 +int
58457 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58458 +{
58459 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58460 +}
58461 +
58462 +int gr_search_listen(struct socket *sock)
58463 +{
58464 + struct sock *sk = sock->sk;
58465 + struct sockaddr_in addr;
58466 +
58467 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58468 + addr.sin_port = inet_sk(sk)->inet_sport;
58469 +
58470 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58471 +}
58472 +
58473 +int gr_search_accept(struct socket *sock)
58474 +{
58475 + struct sock *sk = sock->sk;
58476 + struct sockaddr_in addr;
58477 +
58478 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58479 + addr.sin_port = inet_sk(sk)->inet_sport;
58480 +
58481 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58482 +}
58483 +
58484 +int
58485 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58486 +{
58487 + if (addr)
58488 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58489 + else {
58490 + struct sockaddr_in sin;
58491 + const struct inet_sock *inet = inet_sk(sk);
58492 +
58493 + sin.sin_addr.s_addr = inet->inet_daddr;
58494 + sin.sin_port = inet->inet_dport;
58495 +
58496 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58497 + }
58498 +}
58499 +
58500 +int
58501 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58502 +{
58503 + struct sockaddr_in sin;
58504 +
58505 + if (unlikely(skb->len < sizeof (struct udphdr)))
58506 + return 0; // skip this packet
58507 +
58508 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58509 + sin.sin_port = udp_hdr(skb)->source;
58510 +
58511 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58512 +}
58513 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58514 new file mode 100644
58515 index 0000000..25f54ef
58516 --- /dev/null
58517 +++ b/grsecurity/gracl_learn.c
58518 @@ -0,0 +1,207 @@
58519 +#include <linux/kernel.h>
58520 +#include <linux/mm.h>
58521 +#include <linux/sched.h>
58522 +#include <linux/poll.h>
58523 +#include <linux/string.h>
58524 +#include <linux/file.h>
58525 +#include <linux/types.h>
58526 +#include <linux/vmalloc.h>
58527 +#include <linux/grinternal.h>
58528 +
58529 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58530 + size_t count, loff_t *ppos);
58531 +extern int gr_acl_is_enabled(void);
58532 +
58533 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58534 +static int gr_learn_attached;
58535 +
58536 +/* use a 512k buffer */
58537 +#define LEARN_BUFFER_SIZE (512 * 1024)
58538 +
58539 +static DEFINE_SPINLOCK(gr_learn_lock);
58540 +static DEFINE_MUTEX(gr_learn_user_mutex);
58541 +
58542 +/* we need to maintain two buffers, so that the kernel context of grlearn
58543 + uses a semaphore around the userspace copying, and the other kernel contexts
58544 + use a spinlock when copying into the buffer, since they cannot sleep
58545 +*/
58546 +static char *learn_buffer;
58547 +static char *learn_buffer_user;
58548 +static int learn_buffer_len;
58549 +static int learn_buffer_user_len;
58550 +
58551 +static ssize_t
58552 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58553 +{
58554 + DECLARE_WAITQUEUE(wait, current);
58555 + ssize_t retval = 0;
58556 +
58557 + add_wait_queue(&learn_wait, &wait);
58558 + set_current_state(TASK_INTERRUPTIBLE);
58559 + do {
58560 + mutex_lock(&gr_learn_user_mutex);
58561 + spin_lock(&gr_learn_lock);
58562 + if (learn_buffer_len)
58563 + break;
58564 + spin_unlock(&gr_learn_lock);
58565 + mutex_unlock(&gr_learn_user_mutex);
58566 + if (file->f_flags & O_NONBLOCK) {
58567 + retval = -EAGAIN;
58568 + goto out;
58569 + }
58570 + if (signal_pending(current)) {
58571 + retval = -ERESTARTSYS;
58572 + goto out;
58573 + }
58574 +
58575 + schedule();
58576 + } while (1);
58577 +
58578 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58579 + learn_buffer_user_len = learn_buffer_len;
58580 + retval = learn_buffer_len;
58581 + learn_buffer_len = 0;
58582 +
58583 + spin_unlock(&gr_learn_lock);
58584 +
58585 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58586 + retval = -EFAULT;
58587 +
58588 + mutex_unlock(&gr_learn_user_mutex);
58589 +out:
58590 + set_current_state(TASK_RUNNING);
58591 + remove_wait_queue(&learn_wait, &wait);
58592 + return retval;
58593 +}
58594 +
58595 +static unsigned int
58596 +poll_learn(struct file * file, poll_table * wait)
58597 +{
58598 + poll_wait(file, &learn_wait, wait);
58599 +
58600 + if (learn_buffer_len)
58601 + return (POLLIN | POLLRDNORM);
58602 +
58603 + return 0;
58604 +}
58605 +
58606 +void
58607 +gr_clear_learn_entries(void)
58608 +{
58609 + char *tmp;
58610 +
58611 + mutex_lock(&gr_learn_user_mutex);
58612 + spin_lock(&gr_learn_lock);
58613 + tmp = learn_buffer;
58614 + learn_buffer = NULL;
58615 + spin_unlock(&gr_learn_lock);
58616 + if (tmp)
58617 + vfree(tmp);
58618 + if (learn_buffer_user != NULL) {
58619 + vfree(learn_buffer_user);
58620 + learn_buffer_user = NULL;
58621 + }
58622 + learn_buffer_len = 0;
58623 + mutex_unlock(&gr_learn_user_mutex);
58624 +
58625 + return;
58626 +}
58627 +
58628 +void
58629 +gr_add_learn_entry(const char *fmt, ...)
58630 +{
58631 + va_list args;
58632 + unsigned int len;
58633 +
58634 + if (!gr_learn_attached)
58635 + return;
58636 +
58637 + spin_lock(&gr_learn_lock);
58638 +
58639 + /* leave a gap at the end so we know when it's "full" but don't have to
58640 + compute the exact length of the string we're trying to append
58641 + */
58642 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58643 + spin_unlock(&gr_learn_lock);
58644 + wake_up_interruptible(&learn_wait);
58645 + return;
58646 + }
58647 + if (learn_buffer == NULL) {
58648 + spin_unlock(&gr_learn_lock);
58649 + return;
58650 + }
58651 +
58652 + va_start(args, fmt);
58653 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58654 + va_end(args);
58655 +
58656 + learn_buffer_len += len + 1;
58657 +
58658 + spin_unlock(&gr_learn_lock);
58659 + wake_up_interruptible(&learn_wait);
58660 +
58661 + return;
58662 +}
58663 +
58664 +static int
58665 +open_learn(struct inode *inode, struct file *file)
58666 +{
58667 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58668 + return -EBUSY;
58669 + if (file->f_mode & FMODE_READ) {
58670 + int retval = 0;
58671 + mutex_lock(&gr_learn_user_mutex);
58672 + if (learn_buffer == NULL)
58673 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58674 + if (learn_buffer_user == NULL)
58675 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58676 + if (learn_buffer == NULL) {
58677 + retval = -ENOMEM;
58678 + goto out_error;
58679 + }
58680 + if (learn_buffer_user == NULL) {
58681 + retval = -ENOMEM;
58682 + goto out_error;
58683 + }
58684 + learn_buffer_len = 0;
58685 + learn_buffer_user_len = 0;
58686 + gr_learn_attached = 1;
58687 +out_error:
58688 + mutex_unlock(&gr_learn_user_mutex);
58689 + return retval;
58690 + }
58691 + return 0;
58692 +}
58693 +
58694 +static int
58695 +close_learn(struct inode *inode, struct file *file)
58696 +{
58697 + if (file->f_mode & FMODE_READ) {
58698 + char *tmp = NULL;
58699 + mutex_lock(&gr_learn_user_mutex);
58700 + spin_lock(&gr_learn_lock);
58701 + tmp = learn_buffer;
58702 + learn_buffer = NULL;
58703 + spin_unlock(&gr_learn_lock);
58704 + if (tmp)
58705 + vfree(tmp);
58706 + if (learn_buffer_user != NULL) {
58707 + vfree(learn_buffer_user);
58708 + learn_buffer_user = NULL;
58709 + }
58710 + learn_buffer_len = 0;
58711 + learn_buffer_user_len = 0;
58712 + gr_learn_attached = 0;
58713 + mutex_unlock(&gr_learn_user_mutex);
58714 + }
58715 +
58716 + return 0;
58717 +}
58718 +
58719 +const struct file_operations grsec_fops = {
58720 + .read = read_learn,
58721 + .write = write_grsec_handler,
58722 + .open = open_learn,
58723 + .release = close_learn,
58724 + .poll = poll_learn,
58725 +};
58726 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58727 new file mode 100644
58728 index 0000000..39645c9
58729 --- /dev/null
58730 +++ b/grsecurity/gracl_res.c
58731 @@ -0,0 +1,68 @@
58732 +#include <linux/kernel.h>
58733 +#include <linux/sched.h>
58734 +#include <linux/gracl.h>
58735 +#include <linux/grinternal.h>
58736 +
58737 +static const char *restab_log[] = {
58738 + [RLIMIT_CPU] = "RLIMIT_CPU",
58739 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58740 + [RLIMIT_DATA] = "RLIMIT_DATA",
58741 + [RLIMIT_STACK] = "RLIMIT_STACK",
58742 + [RLIMIT_CORE] = "RLIMIT_CORE",
58743 + [RLIMIT_RSS] = "RLIMIT_RSS",
58744 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58745 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58746 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58747 + [RLIMIT_AS] = "RLIMIT_AS",
58748 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58749 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58750 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58751 + [RLIMIT_NICE] = "RLIMIT_NICE",
58752 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58753 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58754 + [GR_CRASH_RES] = "RLIMIT_CRASH"
58755 +};
58756 +
58757 +void
58758 +gr_log_resource(const struct task_struct *task,
58759 + const int res, const unsigned long wanted, const int gt)
58760 +{
58761 + const struct cred *cred;
58762 + unsigned long rlim;
58763 +
58764 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
58765 + return;
58766 +
58767 + // not yet supported resource
58768 + if (unlikely(!restab_log[res]))
58769 + return;
58770 +
58771 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58772 + rlim = task_rlimit_max(task, res);
58773 + else
58774 + rlim = task_rlimit(task, res);
58775 +
58776 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58777 + return;
58778 +
58779 + rcu_read_lock();
58780 + cred = __task_cred(task);
58781 +
58782 + if (res == RLIMIT_NPROC &&
58783 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58784 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58785 + goto out_rcu_unlock;
58786 + else if (res == RLIMIT_MEMLOCK &&
58787 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58788 + goto out_rcu_unlock;
58789 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58790 + goto out_rcu_unlock;
58791 + rcu_read_unlock();
58792 +
58793 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58794 +
58795 + return;
58796 +out_rcu_unlock:
58797 + rcu_read_unlock();
58798 + return;
58799 +}
58800 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58801 new file mode 100644
58802 index 0000000..25197e9
58803 --- /dev/null
58804 +++ b/grsecurity/gracl_segv.c
58805 @@ -0,0 +1,299 @@
58806 +#include <linux/kernel.h>
58807 +#include <linux/mm.h>
58808 +#include <asm/uaccess.h>
58809 +#include <asm/errno.h>
58810 +#include <asm/mman.h>
58811 +#include <net/sock.h>
58812 +#include <linux/file.h>
58813 +#include <linux/fs.h>
58814 +#include <linux/net.h>
58815 +#include <linux/in.h>
58816 +#include <linux/slab.h>
58817 +#include <linux/types.h>
58818 +#include <linux/sched.h>
58819 +#include <linux/timer.h>
58820 +#include <linux/gracl.h>
58821 +#include <linux/grsecurity.h>
58822 +#include <linux/grinternal.h>
58823 +
58824 +static struct crash_uid *uid_set;
58825 +static unsigned short uid_used;
58826 +static DEFINE_SPINLOCK(gr_uid_lock);
58827 +extern rwlock_t gr_inode_lock;
58828 +extern struct acl_subject_label *
58829 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58830 + struct acl_role_label *role);
58831 +
58832 +#ifdef CONFIG_BTRFS_FS
58833 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58834 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58835 +#endif
58836 +
58837 +static inline dev_t __get_dev(const struct dentry *dentry)
58838 +{
58839 +#ifdef CONFIG_BTRFS_FS
58840 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58841 + return get_btrfs_dev_from_inode(dentry->d_inode);
58842 + else
58843 +#endif
58844 + return dentry->d_inode->i_sb->s_dev;
58845 +}
58846 +
58847 +int
58848 +gr_init_uidset(void)
58849 +{
58850 + uid_set =
58851 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58852 + uid_used = 0;
58853 +
58854 + return uid_set ? 1 : 0;
58855 +}
58856 +
58857 +void
58858 +gr_free_uidset(void)
58859 +{
58860 + if (uid_set)
58861 + kfree(uid_set);
58862 +
58863 + return;
58864 +}
58865 +
58866 +int
58867 +gr_find_uid(const uid_t uid)
58868 +{
58869 + struct crash_uid *tmp = uid_set;
58870 + uid_t buid;
58871 + int low = 0, high = uid_used - 1, mid;
58872 +
58873 + while (high >= low) {
58874 + mid = (low + high) >> 1;
58875 + buid = tmp[mid].uid;
58876 + if (buid == uid)
58877 + return mid;
58878 + if (buid > uid)
58879 + high = mid - 1;
58880 + if (buid < uid)
58881 + low = mid + 1;
58882 + }
58883 +
58884 + return -1;
58885 +}
58886 +
58887 +static __inline__ void
58888 +gr_insertsort(void)
58889 +{
58890 + unsigned short i, j;
58891 + struct crash_uid index;
58892 +
58893 + for (i = 1; i < uid_used; i++) {
58894 + index = uid_set[i];
58895 + j = i;
58896 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
58897 + uid_set[j] = uid_set[j - 1];
58898 + j--;
58899 + }
58900 + uid_set[j] = index;
58901 + }
58902 +
58903 + return;
58904 +}
58905 +
58906 +static __inline__ void
58907 +gr_insert_uid(const uid_t uid, const unsigned long expires)
58908 +{
58909 + int loc;
58910 +
58911 + if (uid_used == GR_UIDTABLE_MAX)
58912 + return;
58913 +
58914 + loc = gr_find_uid(uid);
58915 +
58916 + if (loc >= 0) {
58917 + uid_set[loc].expires = expires;
58918 + return;
58919 + }
58920 +
58921 + uid_set[uid_used].uid = uid;
58922 + uid_set[uid_used].expires = expires;
58923 + uid_used++;
58924 +
58925 + gr_insertsort();
58926 +
58927 + return;
58928 +}
58929 +
58930 +void
58931 +gr_remove_uid(const unsigned short loc)
58932 +{
58933 + unsigned short i;
58934 +
58935 + for (i = loc + 1; i < uid_used; i++)
58936 + uid_set[i - 1] = uid_set[i];
58937 +
58938 + uid_used--;
58939 +
58940 + return;
58941 +}
58942 +
58943 +int
58944 +gr_check_crash_uid(const uid_t uid)
58945 +{
58946 + int loc;
58947 + int ret = 0;
58948 +
58949 + if (unlikely(!gr_acl_is_enabled()))
58950 + return 0;
58951 +
58952 + spin_lock(&gr_uid_lock);
58953 + loc = gr_find_uid(uid);
58954 +
58955 + if (loc < 0)
58956 + goto out_unlock;
58957 +
58958 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
58959 + gr_remove_uid(loc);
58960 + else
58961 + ret = 1;
58962 +
58963 +out_unlock:
58964 + spin_unlock(&gr_uid_lock);
58965 + return ret;
58966 +}
58967 +
58968 +static __inline__ int
58969 +proc_is_setxid(const struct cred *cred)
58970 +{
58971 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
58972 + !uid_eq(cred->uid, cred->fsuid))
58973 + return 1;
58974 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
58975 + !uid_eq(cred->gid, cred->fsgid))
58976 + return 1;
58977 +
58978 + return 0;
58979 +}
58980 +
58981 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
58982 +
58983 +void
58984 +gr_handle_crash(struct task_struct *task, const int sig)
58985 +{
58986 + struct acl_subject_label *curr;
58987 + struct task_struct *tsk, *tsk2;
58988 + const struct cred *cred;
58989 + const struct cred *cred2;
58990 +
58991 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
58992 + return;
58993 +
58994 + if (unlikely(!gr_acl_is_enabled()))
58995 + return;
58996 +
58997 + curr = task->acl;
58998 +
58999 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
59000 + return;
59001 +
59002 + if (time_before_eq(curr->expires, get_seconds())) {
59003 + curr->expires = 0;
59004 + curr->crashes = 0;
59005 + }
59006 +
59007 + curr->crashes++;
59008 +
59009 + if (!curr->expires)
59010 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59011 +
59012 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59013 + time_after(curr->expires, get_seconds())) {
59014 + rcu_read_lock();
59015 + cred = __task_cred(task);
59016 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59017 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59018 + spin_lock(&gr_uid_lock);
59019 + gr_insert_uid(cred->uid, curr->expires);
59020 + spin_unlock(&gr_uid_lock);
59021 + curr->expires = 0;
59022 + curr->crashes = 0;
59023 + read_lock(&tasklist_lock);
59024 + do_each_thread(tsk2, tsk) {
59025 + cred2 = __task_cred(tsk);
59026 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
59027 + gr_fake_force_sig(SIGKILL, tsk);
59028 + } while_each_thread(tsk2, tsk);
59029 + read_unlock(&tasklist_lock);
59030 + } else {
59031 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59032 + read_lock(&tasklist_lock);
59033 + read_lock(&grsec_exec_file_lock);
59034 + do_each_thread(tsk2, tsk) {
59035 + if (likely(tsk != task)) {
59036 + // if this thread has the same subject as the one that triggered
59037 + // RES_CRASH and it's the same binary, kill it
59038 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59039 + gr_fake_force_sig(SIGKILL, tsk);
59040 + }
59041 + } while_each_thread(tsk2, tsk);
59042 + read_unlock(&grsec_exec_file_lock);
59043 + read_unlock(&tasklist_lock);
59044 + }
59045 + rcu_read_unlock();
59046 + }
59047 +
59048 + return;
59049 +}
59050 +
59051 +int
59052 +gr_check_crash_exec(const struct file *filp)
59053 +{
59054 + struct acl_subject_label *curr;
59055 +
59056 + if (unlikely(!gr_acl_is_enabled()))
59057 + return 0;
59058 +
59059 + read_lock(&gr_inode_lock);
59060 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59061 + __get_dev(filp->f_path.dentry),
59062 + current->role);
59063 + read_unlock(&gr_inode_lock);
59064 +
59065 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59066 + (!curr->crashes && !curr->expires))
59067 + return 0;
59068 +
59069 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59070 + time_after(curr->expires, get_seconds()))
59071 + return 1;
59072 + else if (time_before_eq(curr->expires, get_seconds())) {
59073 + curr->crashes = 0;
59074 + curr->expires = 0;
59075 + }
59076 +
59077 + return 0;
59078 +}
59079 +
59080 +void
59081 +gr_handle_alertkill(struct task_struct *task)
59082 +{
59083 + struct acl_subject_label *curracl;
59084 + __u32 curr_ip;
59085 + struct task_struct *p, *p2;
59086 +
59087 + if (unlikely(!gr_acl_is_enabled()))
59088 + return;
59089 +
59090 + curracl = task->acl;
59091 + curr_ip = task->signal->curr_ip;
59092 +
59093 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
59094 + read_lock(&tasklist_lock);
59095 + do_each_thread(p2, p) {
59096 + if (p->signal->curr_ip == curr_ip)
59097 + gr_fake_force_sig(SIGKILL, p);
59098 + } while_each_thread(p2, p);
59099 + read_unlock(&tasklist_lock);
59100 + } else if (curracl->mode & GR_KILLPROC)
59101 + gr_fake_force_sig(SIGKILL, task);
59102 +
59103 + return;
59104 +}
59105 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59106 new file mode 100644
59107 index 0000000..9d83a69
59108 --- /dev/null
59109 +++ b/grsecurity/gracl_shm.c
59110 @@ -0,0 +1,40 @@
59111 +#include <linux/kernel.h>
59112 +#include <linux/mm.h>
59113 +#include <linux/sched.h>
59114 +#include <linux/file.h>
59115 +#include <linux/ipc.h>
59116 +#include <linux/gracl.h>
59117 +#include <linux/grsecurity.h>
59118 +#include <linux/grinternal.h>
59119 +
59120 +int
59121 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59122 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59123 +{
59124 + struct task_struct *task;
59125 +
59126 + if (!gr_acl_is_enabled())
59127 + return 1;
59128 +
59129 + rcu_read_lock();
59130 + read_lock(&tasklist_lock);
59131 +
59132 + task = find_task_by_vpid(shm_cprid);
59133 +
59134 + if (unlikely(!task))
59135 + task = find_task_by_vpid(shm_lapid);
59136 +
59137 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59138 + (task->pid == shm_lapid)) &&
59139 + (task->acl->mode & GR_PROTSHM) &&
59140 + (task->acl != current->acl))) {
59141 + read_unlock(&tasklist_lock);
59142 + rcu_read_unlock();
59143 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59144 + return 0;
59145 + }
59146 + read_unlock(&tasklist_lock);
59147 + rcu_read_unlock();
59148 +
59149 + return 1;
59150 +}
59151 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59152 new file mode 100644
59153 index 0000000..bc0be01
59154 --- /dev/null
59155 +++ b/grsecurity/grsec_chdir.c
59156 @@ -0,0 +1,19 @@
59157 +#include <linux/kernel.h>
59158 +#include <linux/sched.h>
59159 +#include <linux/fs.h>
59160 +#include <linux/file.h>
59161 +#include <linux/grsecurity.h>
59162 +#include <linux/grinternal.h>
59163 +
59164 +void
59165 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59166 +{
59167 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59168 + if ((grsec_enable_chdir && grsec_enable_group &&
59169 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59170 + !grsec_enable_group)) {
59171 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59172 + }
59173 +#endif
59174 + return;
59175 +}
59176 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59177 new file mode 100644
59178 index 0000000..70fe0ae
59179 --- /dev/null
59180 +++ b/grsecurity/grsec_chroot.c
59181 @@ -0,0 +1,357 @@
59182 +#include <linux/kernel.h>
59183 +#include <linux/module.h>
59184 +#include <linux/sched.h>
59185 +#include <linux/file.h>
59186 +#include <linux/fs.h>
59187 +#include <linux/mount.h>
59188 +#include <linux/types.h>
59189 +#include "../fs/mount.h"
59190 +#include <linux/grsecurity.h>
59191 +#include <linux/grinternal.h>
59192 +
59193 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59194 +{
59195 +#ifdef CONFIG_GRKERNSEC
59196 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59197 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59198 + task->gr_is_chrooted = 1;
59199 + else
59200 + task->gr_is_chrooted = 0;
59201 +
59202 + task->gr_chroot_dentry = path->dentry;
59203 +#endif
59204 + return;
59205 +}
59206 +
59207 +void gr_clear_chroot_entries(struct task_struct *task)
59208 +{
59209 +#ifdef CONFIG_GRKERNSEC
59210 + task->gr_is_chrooted = 0;
59211 + task->gr_chroot_dentry = NULL;
59212 +#endif
59213 + return;
59214 +}
59215 +
59216 +int
59217 +gr_handle_chroot_unix(const pid_t pid)
59218 +{
59219 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59220 + struct task_struct *p;
59221 +
59222 + if (unlikely(!grsec_enable_chroot_unix))
59223 + return 1;
59224 +
59225 + if (likely(!proc_is_chrooted(current)))
59226 + return 1;
59227 +
59228 + rcu_read_lock();
59229 + read_lock(&tasklist_lock);
59230 + p = find_task_by_vpid_unrestricted(pid);
59231 + if (unlikely(p && !have_same_root(current, p))) {
59232 + read_unlock(&tasklist_lock);
59233 + rcu_read_unlock();
59234 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59235 + return 0;
59236 + }
59237 + read_unlock(&tasklist_lock);
59238 + rcu_read_unlock();
59239 +#endif
59240 + return 1;
59241 +}
59242 +
59243 +int
59244 +gr_handle_chroot_nice(void)
59245 +{
59246 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59247 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59248 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59249 + return -EPERM;
59250 + }
59251 +#endif
59252 + return 0;
59253 +}
59254 +
59255 +int
59256 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59257 +{
59258 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59259 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59260 + && proc_is_chrooted(current)) {
59261 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59262 + return -EACCES;
59263 + }
59264 +#endif
59265 + return 0;
59266 +}
59267 +
59268 +int
59269 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59270 +{
59271 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59272 + struct task_struct *p;
59273 + int ret = 0;
59274 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59275 + return ret;
59276 +
59277 + read_lock(&tasklist_lock);
59278 + do_each_pid_task(pid, type, p) {
59279 + if (!have_same_root(current, p)) {
59280 + ret = 1;
59281 + goto out;
59282 + }
59283 + } while_each_pid_task(pid, type, p);
59284 +out:
59285 + read_unlock(&tasklist_lock);
59286 + return ret;
59287 +#endif
59288 + return 0;
59289 +}
59290 +
59291 +int
59292 +gr_pid_is_chrooted(struct task_struct *p)
59293 +{
59294 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59295 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59296 + return 0;
59297 +
59298 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59299 + !have_same_root(current, p)) {
59300 + return 1;
59301 + }
59302 +#endif
59303 + return 0;
59304 +}
59305 +
59306 +EXPORT_SYMBOL(gr_pid_is_chrooted);
59307 +
59308 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59309 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59310 +{
59311 + struct path path, currentroot;
59312 + int ret = 0;
59313 +
59314 + path.dentry = (struct dentry *)u_dentry;
59315 + path.mnt = (struct vfsmount *)u_mnt;
59316 + get_fs_root(current->fs, &currentroot);
59317 + if (path_is_under(&path, &currentroot))
59318 + ret = 1;
59319 + path_put(&currentroot);
59320 +
59321 + return ret;
59322 +}
59323 +#endif
59324 +
59325 +int
59326 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59327 +{
59328 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59329 + if (!grsec_enable_chroot_fchdir)
59330 + return 1;
59331 +
59332 + if (!proc_is_chrooted(current))
59333 + return 1;
59334 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59335 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59336 + return 0;
59337 + }
59338 +#endif
59339 + return 1;
59340 +}
59341 +
59342 +int
59343 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59344 + const time_t shm_createtime)
59345 +{
59346 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59347 + struct task_struct *p;
59348 + time_t starttime;
59349 +
59350 + if (unlikely(!grsec_enable_chroot_shmat))
59351 + return 1;
59352 +
59353 + if (likely(!proc_is_chrooted(current)))
59354 + return 1;
59355 +
59356 + rcu_read_lock();
59357 + read_lock(&tasklist_lock);
59358 +
59359 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59360 + starttime = p->start_time.tv_sec;
59361 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59362 + if (have_same_root(current, p)) {
59363 + goto allow;
59364 + } else {
59365 + read_unlock(&tasklist_lock);
59366 + rcu_read_unlock();
59367 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59368 + return 0;
59369 + }
59370 + }
59371 + /* creator exited, pid reuse, fall through to next check */
59372 + }
59373 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59374 + if (unlikely(!have_same_root(current, p))) {
59375 + read_unlock(&tasklist_lock);
59376 + rcu_read_unlock();
59377 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59378 + return 0;
59379 + }
59380 + }
59381 +
59382 +allow:
59383 + read_unlock(&tasklist_lock);
59384 + rcu_read_unlock();
59385 +#endif
59386 + return 1;
59387 +}
59388 +
59389 +void
59390 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59391 +{
59392 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59393 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59394 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59395 +#endif
59396 + return;
59397 +}
59398 +
59399 +int
59400 +gr_handle_chroot_mknod(const struct dentry *dentry,
59401 + const struct vfsmount *mnt, const int mode)
59402 +{
59403 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59404 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59405 + proc_is_chrooted(current)) {
59406 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59407 + return -EPERM;
59408 + }
59409 +#endif
59410 + return 0;
59411 +}
59412 +
59413 +int
59414 +gr_handle_chroot_mount(const struct dentry *dentry,
59415 + const struct vfsmount *mnt, const char *dev_name)
59416 +{
59417 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59418 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59419 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59420 + return -EPERM;
59421 + }
59422 +#endif
59423 + return 0;
59424 +}
59425 +
59426 +int
59427 +gr_handle_chroot_pivot(void)
59428 +{
59429 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59430 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59431 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59432 + return -EPERM;
59433 + }
59434 +#endif
59435 + return 0;
59436 +}
59437 +
59438 +int
59439 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59440 +{
59441 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59442 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59443 + !gr_is_outside_chroot(dentry, mnt)) {
59444 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59445 + return -EPERM;
59446 + }
59447 +#endif
59448 + return 0;
59449 +}
59450 +
59451 +extern const char *captab_log[];
59452 +extern int captab_log_entries;
59453 +
59454 +int
59455 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59456 +{
59457 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59458 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59459 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59460 + if (cap_raised(chroot_caps, cap)) {
59461 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59462 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59463 + }
59464 + return 0;
59465 + }
59466 + }
59467 +#endif
59468 + return 1;
59469 +}
59470 +
59471 +int
59472 +gr_chroot_is_capable(const int cap)
59473 +{
59474 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59475 + return gr_task_chroot_is_capable(current, current_cred(), cap);
59476 +#endif
59477 + return 1;
59478 +}
59479 +
59480 +int
59481 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59482 +{
59483 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59484 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59485 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59486 + if (cap_raised(chroot_caps, cap)) {
59487 + return 0;
59488 + }
59489 + }
59490 +#endif
59491 + return 1;
59492 +}
59493 +
59494 +int
59495 +gr_chroot_is_capable_nolog(const int cap)
59496 +{
59497 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59498 + return gr_task_chroot_is_capable_nolog(current, cap);
59499 +#endif
59500 + return 1;
59501 +}
59502 +
59503 +int
59504 +gr_handle_chroot_sysctl(const int op)
59505 +{
59506 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59507 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59508 + proc_is_chrooted(current))
59509 + return -EACCES;
59510 +#endif
59511 + return 0;
59512 +}
59513 +
59514 +void
59515 +gr_handle_chroot_chdir(struct path *path)
59516 +{
59517 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59518 + if (grsec_enable_chroot_chdir)
59519 + set_fs_pwd(current->fs, path);
59520 +#endif
59521 + return;
59522 +}
59523 +
59524 +int
59525 +gr_handle_chroot_chmod(const struct dentry *dentry,
59526 + const struct vfsmount *mnt, const int mode)
59527 +{
59528 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59529 + /* allow chmod +s on directories, but not files */
59530 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59531 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59532 + proc_is_chrooted(current)) {
59533 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59534 + return -EPERM;
59535 + }
59536 +#endif
59537 + return 0;
59538 +}
59539 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59540 new file mode 100644
59541 index 0000000..e6796b3
59542 --- /dev/null
59543 +++ b/grsecurity/grsec_disabled.c
59544 @@ -0,0 +1,434 @@
59545 +#include <linux/kernel.h>
59546 +#include <linux/module.h>
59547 +#include <linux/sched.h>
59548 +#include <linux/file.h>
59549 +#include <linux/fs.h>
59550 +#include <linux/kdev_t.h>
59551 +#include <linux/net.h>
59552 +#include <linux/in.h>
59553 +#include <linux/ip.h>
59554 +#include <linux/skbuff.h>
59555 +#include <linux/sysctl.h>
59556 +
59557 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59558 +void
59559 +pax_set_initial_flags(struct linux_binprm *bprm)
59560 +{
59561 + return;
59562 +}
59563 +#endif
59564 +
59565 +#ifdef CONFIG_SYSCTL
59566 +__u32
59567 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59568 +{
59569 + return 0;
59570 +}
59571 +#endif
59572 +
59573 +#ifdef CONFIG_TASKSTATS
59574 +int gr_is_taskstats_denied(int pid)
59575 +{
59576 + return 0;
59577 +}
59578 +#endif
59579 +
59580 +int
59581 +gr_acl_is_enabled(void)
59582 +{
59583 + return 0;
59584 +}
59585 +
59586 +void
59587 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59588 +{
59589 + return;
59590 +}
59591 +
59592 +int
59593 +gr_handle_rawio(const struct inode *inode)
59594 +{
59595 + return 0;
59596 +}
59597 +
59598 +void
59599 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59600 +{
59601 + return;
59602 +}
59603 +
59604 +int
59605 +gr_handle_ptrace(struct task_struct *task, const long request)
59606 +{
59607 + return 0;
59608 +}
59609 +
59610 +int
59611 +gr_handle_proc_ptrace(struct task_struct *task)
59612 +{
59613 + return 0;
59614 +}
59615 +
59616 +int
59617 +gr_set_acls(const int type)
59618 +{
59619 + return 0;
59620 +}
59621 +
59622 +int
59623 +gr_check_hidden_task(const struct task_struct *tsk)
59624 +{
59625 + return 0;
59626 +}
59627 +
59628 +int
59629 +gr_check_protected_task(const struct task_struct *task)
59630 +{
59631 + return 0;
59632 +}
59633 +
59634 +int
59635 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59636 +{
59637 + return 0;
59638 +}
59639 +
59640 +void
59641 +gr_copy_label(struct task_struct *tsk)
59642 +{
59643 + return;
59644 +}
59645 +
59646 +void
59647 +gr_set_pax_flags(struct task_struct *task)
59648 +{
59649 + return;
59650 +}
59651 +
59652 +int
59653 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59654 + const int unsafe_share)
59655 +{
59656 + return 0;
59657 +}
59658 +
59659 +void
59660 +gr_handle_delete(const ino_t ino, const dev_t dev)
59661 +{
59662 + return;
59663 +}
59664 +
59665 +void
59666 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59667 +{
59668 + return;
59669 +}
59670 +
59671 +void
59672 +gr_handle_crash(struct task_struct *task, const int sig)
59673 +{
59674 + return;
59675 +}
59676 +
59677 +int
59678 +gr_check_crash_exec(const struct file *filp)
59679 +{
59680 + return 0;
59681 +}
59682 +
59683 +int
59684 +gr_check_crash_uid(const uid_t uid)
59685 +{
59686 + return 0;
59687 +}
59688 +
59689 +void
59690 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59691 + struct dentry *old_dentry,
59692 + struct dentry *new_dentry,
59693 + struct vfsmount *mnt, const __u8 replace)
59694 +{
59695 + return;
59696 +}
59697 +
59698 +int
59699 +gr_search_socket(const int family, const int type, const int protocol)
59700 +{
59701 + return 1;
59702 +}
59703 +
59704 +int
59705 +gr_search_connectbind(const int mode, const struct socket *sock,
59706 + const struct sockaddr_in *addr)
59707 +{
59708 + return 0;
59709 +}
59710 +
59711 +void
59712 +gr_handle_alertkill(struct task_struct *task)
59713 +{
59714 + return;
59715 +}
59716 +
59717 +__u32
59718 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59719 +{
59720 + return 1;
59721 +}
59722 +
59723 +__u32
59724 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59725 + const struct vfsmount * mnt)
59726 +{
59727 + return 1;
59728 +}
59729 +
59730 +__u32
59731 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59732 + int acc_mode)
59733 +{
59734 + return 1;
59735 +}
59736 +
59737 +__u32
59738 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59739 +{
59740 + return 1;
59741 +}
59742 +
59743 +__u32
59744 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59745 +{
59746 + return 1;
59747 +}
59748 +
59749 +int
59750 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59751 + unsigned int *vm_flags)
59752 +{
59753 + return 1;
59754 +}
59755 +
59756 +__u32
59757 +gr_acl_handle_truncate(const struct dentry * dentry,
59758 + const struct vfsmount * mnt)
59759 +{
59760 + return 1;
59761 +}
59762 +
59763 +__u32
59764 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59765 +{
59766 + return 1;
59767 +}
59768 +
59769 +__u32
59770 +gr_acl_handle_access(const struct dentry * dentry,
59771 + const struct vfsmount * mnt, const int fmode)
59772 +{
59773 + return 1;
59774 +}
59775 +
59776 +__u32
59777 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59778 + umode_t *mode)
59779 +{
59780 + return 1;
59781 +}
59782 +
59783 +__u32
59784 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59785 +{
59786 + return 1;
59787 +}
59788 +
59789 +__u32
59790 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59791 +{
59792 + return 1;
59793 +}
59794 +
59795 +void
59796 +grsecurity_init(void)
59797 +{
59798 + return;
59799 +}
59800 +
59801 +umode_t gr_acl_umask(void)
59802 +{
59803 + return 0;
59804 +}
59805 +
59806 +__u32
59807 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59808 + const struct dentry * parent_dentry,
59809 + const struct vfsmount * parent_mnt,
59810 + const int mode)
59811 +{
59812 + return 1;
59813 +}
59814 +
59815 +__u32
59816 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
59817 + const struct dentry * parent_dentry,
59818 + const struct vfsmount * parent_mnt)
59819 +{
59820 + return 1;
59821 +}
59822 +
59823 +__u32
59824 +gr_acl_handle_symlink(const struct dentry * new_dentry,
59825 + const struct dentry * parent_dentry,
59826 + const struct vfsmount * parent_mnt, const struct filename *from)
59827 +{
59828 + return 1;
59829 +}
59830 +
59831 +__u32
59832 +gr_acl_handle_link(const struct dentry * new_dentry,
59833 + const struct dentry * parent_dentry,
59834 + const struct vfsmount * parent_mnt,
59835 + const struct dentry * old_dentry,
59836 + const struct vfsmount * old_mnt, const struct filename *to)
59837 +{
59838 + return 1;
59839 +}
59840 +
59841 +int
59842 +gr_acl_handle_rename(const struct dentry *new_dentry,
59843 + const struct dentry *parent_dentry,
59844 + const struct vfsmount *parent_mnt,
59845 + const struct dentry *old_dentry,
59846 + const struct inode *old_parent_inode,
59847 + const struct vfsmount *old_mnt, const struct filename *newname)
59848 +{
59849 + return 0;
59850 +}
59851 +
59852 +int
59853 +gr_acl_handle_filldir(const struct file *file, const char *name,
59854 + const int namelen, const ino_t ino)
59855 +{
59856 + return 1;
59857 +}
59858 +
59859 +int
59860 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59861 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59862 +{
59863 + return 1;
59864 +}
59865 +
59866 +int
59867 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59868 +{
59869 + return 0;
59870 +}
59871 +
59872 +int
59873 +gr_search_accept(const struct socket *sock)
59874 +{
59875 + return 0;
59876 +}
59877 +
59878 +int
59879 +gr_search_listen(const struct socket *sock)
59880 +{
59881 + return 0;
59882 +}
59883 +
59884 +int
59885 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59886 +{
59887 + return 0;
59888 +}
59889 +
59890 +__u32
59891 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
59892 +{
59893 + return 1;
59894 +}
59895 +
59896 +__u32
59897 +gr_acl_handle_creat(const struct dentry * dentry,
59898 + const struct dentry * p_dentry,
59899 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59900 + const int imode)
59901 +{
59902 + return 1;
59903 +}
59904 +
59905 +void
59906 +gr_acl_handle_exit(void)
59907 +{
59908 + return;
59909 +}
59910 +
59911 +int
59912 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59913 +{
59914 + return 1;
59915 +}
59916 +
59917 +void
59918 +gr_set_role_label(const uid_t uid, const gid_t gid)
59919 +{
59920 + return;
59921 +}
59922 +
59923 +int
59924 +gr_acl_handle_procpidmem(const struct task_struct *task)
59925 +{
59926 + return 0;
59927 +}
59928 +
59929 +int
59930 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
59931 +{
59932 + return 0;
59933 +}
59934 +
59935 +int
59936 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
59937 +{
59938 + return 0;
59939 +}
59940 +
59941 +void
59942 +gr_set_kernel_label(struct task_struct *task)
59943 +{
59944 + return;
59945 +}
59946 +
59947 +int
59948 +gr_check_user_change(int real, int effective, int fs)
59949 +{
59950 + return 0;
59951 +}
59952 +
59953 +int
59954 +gr_check_group_change(int real, int effective, int fs)
59955 +{
59956 + return 0;
59957 +}
59958 +
59959 +int gr_acl_enable_at_secure(void)
59960 +{
59961 + return 0;
59962 +}
59963 +
59964 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
59965 +{
59966 + return dentry->d_inode->i_sb->s_dev;
59967 +}
59968 +
59969 +void gr_put_exec_file(struct task_struct *task)
59970 +{
59971 + return;
59972 +}
59973 +
59974 +EXPORT_SYMBOL(gr_set_kernel_label);
59975 +#ifdef CONFIG_SECURITY
59976 +EXPORT_SYMBOL(gr_check_user_change);
59977 +EXPORT_SYMBOL(gr_check_group_change);
59978 +#endif
59979 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
59980 new file mode 100644
59981 index 0000000..abfa971
59982 --- /dev/null
59983 +++ b/grsecurity/grsec_exec.c
59984 @@ -0,0 +1,174 @@
59985 +#include <linux/kernel.h>
59986 +#include <linux/sched.h>
59987 +#include <linux/file.h>
59988 +#include <linux/binfmts.h>
59989 +#include <linux/fs.h>
59990 +#include <linux/types.h>
59991 +#include <linux/grdefs.h>
59992 +#include <linux/grsecurity.h>
59993 +#include <linux/grinternal.h>
59994 +#include <linux/capability.h>
59995 +#include <linux/module.h>
59996 +
59997 +#include <asm/uaccess.h>
59998 +
59999 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60000 +static char gr_exec_arg_buf[132];
60001 +static DEFINE_MUTEX(gr_exec_arg_mutex);
60002 +#endif
60003 +
60004 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60005 +
60006 +void
60007 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60008 +{
60009 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60010 + char *grarg = gr_exec_arg_buf;
60011 + unsigned int i, x, execlen = 0;
60012 + char c;
60013 +
60014 + if (!((grsec_enable_execlog && grsec_enable_group &&
60015 + in_group_p(grsec_audit_gid))
60016 + || (grsec_enable_execlog && !grsec_enable_group)))
60017 + return;
60018 +
60019 + mutex_lock(&gr_exec_arg_mutex);
60020 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
60021 +
60022 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
60023 + const char __user *p;
60024 + unsigned int len;
60025 +
60026 + p = get_user_arg_ptr(argv, i);
60027 + if (IS_ERR(p))
60028 + goto log;
60029 +
60030 + len = strnlen_user(p, 128 - execlen);
60031 + if (len > 128 - execlen)
60032 + len = 128 - execlen;
60033 + else if (len > 0)
60034 + len--;
60035 + if (copy_from_user(grarg + execlen, p, len))
60036 + goto log;
60037 +
60038 + /* rewrite unprintable characters */
60039 + for (x = 0; x < len; x++) {
60040 + c = *(grarg + execlen + x);
60041 + if (c < 32 || c > 126)
60042 + *(grarg + execlen + x) = ' ';
60043 + }
60044 +
60045 + execlen += len;
60046 + *(grarg + execlen) = ' ';
60047 + *(grarg + execlen + 1) = '\0';
60048 + execlen++;
60049 + }
60050 +
60051 + log:
60052 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60053 + bprm->file->f_path.mnt, grarg);
60054 + mutex_unlock(&gr_exec_arg_mutex);
60055 +#endif
60056 + return;
60057 +}
60058 +
60059 +#ifdef CONFIG_GRKERNSEC
60060 +extern int gr_acl_is_capable(const int cap);
60061 +extern int gr_acl_is_capable_nolog(const int cap);
60062 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60063 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60064 +extern int gr_chroot_is_capable(const int cap);
60065 +extern int gr_chroot_is_capable_nolog(const int cap);
60066 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60067 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60068 +#endif
60069 +
60070 +const char *captab_log[] = {
60071 + "CAP_CHOWN",
60072 + "CAP_DAC_OVERRIDE",
60073 + "CAP_DAC_READ_SEARCH",
60074 + "CAP_FOWNER",
60075 + "CAP_FSETID",
60076 + "CAP_KILL",
60077 + "CAP_SETGID",
60078 + "CAP_SETUID",
60079 + "CAP_SETPCAP",
60080 + "CAP_LINUX_IMMUTABLE",
60081 + "CAP_NET_BIND_SERVICE",
60082 + "CAP_NET_BROADCAST",
60083 + "CAP_NET_ADMIN",
60084 + "CAP_NET_RAW",
60085 + "CAP_IPC_LOCK",
60086 + "CAP_IPC_OWNER",
60087 + "CAP_SYS_MODULE",
60088 + "CAP_SYS_RAWIO",
60089 + "CAP_SYS_CHROOT",
60090 + "CAP_SYS_PTRACE",
60091 + "CAP_SYS_PACCT",
60092 + "CAP_SYS_ADMIN",
60093 + "CAP_SYS_BOOT",
60094 + "CAP_SYS_NICE",
60095 + "CAP_SYS_RESOURCE",
60096 + "CAP_SYS_TIME",
60097 + "CAP_SYS_TTY_CONFIG",
60098 + "CAP_MKNOD",
60099 + "CAP_LEASE",
60100 + "CAP_AUDIT_WRITE",
60101 + "CAP_AUDIT_CONTROL",
60102 + "CAP_SETFCAP",
60103 + "CAP_MAC_OVERRIDE",
60104 + "CAP_MAC_ADMIN",
60105 + "CAP_SYSLOG",
60106 + "CAP_WAKE_ALARM"
60107 +};
60108 +
60109 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60110 +
60111 +int gr_is_capable(const int cap)
60112 +{
60113 +#ifdef CONFIG_GRKERNSEC
60114 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60115 + return 1;
60116 + return 0;
60117 +#else
60118 + return 1;
60119 +#endif
60120 +}
60121 +
60122 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60123 +{
60124 +#ifdef CONFIG_GRKERNSEC
60125 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60126 + return 1;
60127 + return 0;
60128 +#else
60129 + return 1;
60130 +#endif
60131 +}
60132 +
60133 +int gr_is_capable_nolog(const int cap)
60134 +{
60135 +#ifdef CONFIG_GRKERNSEC
60136 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60137 + return 1;
60138 + return 0;
60139 +#else
60140 + return 1;
60141 +#endif
60142 +}
60143 +
60144 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60145 +{
60146 +#ifdef CONFIG_GRKERNSEC
60147 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60148 + return 1;
60149 + return 0;
60150 +#else
60151 + return 1;
60152 +#endif
60153 +}
60154 +
60155 +EXPORT_SYMBOL(gr_is_capable);
60156 +EXPORT_SYMBOL(gr_is_capable_nolog);
60157 +EXPORT_SYMBOL(gr_task_is_capable);
60158 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
60159 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60160 new file mode 100644
60161 index 0000000..d3ee748
60162 --- /dev/null
60163 +++ b/grsecurity/grsec_fifo.c
60164 @@ -0,0 +1,24 @@
60165 +#include <linux/kernel.h>
60166 +#include <linux/sched.h>
60167 +#include <linux/fs.h>
60168 +#include <linux/file.h>
60169 +#include <linux/grinternal.h>
60170 +
60171 +int
60172 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60173 + const struct dentry *dir, const int flag, const int acc_mode)
60174 +{
60175 +#ifdef CONFIG_GRKERNSEC_FIFO
60176 + const struct cred *cred = current_cred();
60177 +
60178 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60179 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60180 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60181 + (cred->fsuid != dentry->d_inode->i_uid)) {
60182 + if (!inode_permission(dentry->d_inode, acc_mode))
60183 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60184 + return -EACCES;
60185 + }
60186 +#endif
60187 + return 0;
60188 +}
60189 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60190 new file mode 100644
60191 index 0000000..8ca18bf
60192 --- /dev/null
60193 +++ b/grsecurity/grsec_fork.c
60194 @@ -0,0 +1,23 @@
60195 +#include <linux/kernel.h>
60196 +#include <linux/sched.h>
60197 +#include <linux/grsecurity.h>
60198 +#include <linux/grinternal.h>
60199 +#include <linux/errno.h>
60200 +
60201 +void
60202 +gr_log_forkfail(const int retval)
60203 +{
60204 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60205 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60206 + switch (retval) {
60207 + case -EAGAIN:
60208 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60209 + break;
60210 + case -ENOMEM:
60211 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60212 + break;
60213 + }
60214 + }
60215 +#endif
60216 + return;
60217 +}
60218 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60219 new file mode 100644
60220 index 0000000..05a6015
60221 --- /dev/null
60222 +++ b/grsecurity/grsec_init.c
60223 @@ -0,0 +1,283 @@
60224 +#include <linux/kernel.h>
60225 +#include <linux/sched.h>
60226 +#include <linux/mm.h>
60227 +#include <linux/gracl.h>
60228 +#include <linux/slab.h>
60229 +#include <linux/vmalloc.h>
60230 +#include <linux/percpu.h>
60231 +#include <linux/module.h>
60232 +
60233 +int grsec_enable_ptrace_readexec;
60234 +int grsec_enable_setxid;
60235 +int grsec_enable_symlinkown;
60236 +int grsec_symlinkown_gid;
60237 +int grsec_enable_brute;
60238 +int grsec_enable_link;
60239 +int grsec_enable_dmesg;
60240 +int grsec_enable_harden_ptrace;
60241 +int grsec_enable_fifo;
60242 +int grsec_enable_execlog;
60243 +int grsec_enable_signal;
60244 +int grsec_enable_forkfail;
60245 +int grsec_enable_audit_ptrace;
60246 +int grsec_enable_time;
60247 +int grsec_enable_audit_textrel;
60248 +int grsec_enable_group;
60249 +int grsec_audit_gid;
60250 +int grsec_enable_chdir;
60251 +int grsec_enable_mount;
60252 +int grsec_enable_rofs;
60253 +int grsec_enable_chroot_findtask;
60254 +int grsec_enable_chroot_mount;
60255 +int grsec_enable_chroot_shmat;
60256 +int grsec_enable_chroot_fchdir;
60257 +int grsec_enable_chroot_double;
60258 +int grsec_enable_chroot_pivot;
60259 +int grsec_enable_chroot_chdir;
60260 +int grsec_enable_chroot_chmod;
60261 +int grsec_enable_chroot_mknod;
60262 +int grsec_enable_chroot_nice;
60263 +int grsec_enable_chroot_execlog;
60264 +int grsec_enable_chroot_caps;
60265 +int grsec_enable_chroot_sysctl;
60266 +int grsec_enable_chroot_unix;
60267 +int grsec_enable_tpe;
60268 +int grsec_tpe_gid;
60269 +int grsec_enable_blackhole;
60270 +#ifdef CONFIG_IPV6_MODULE
60271 +EXPORT_SYMBOL(grsec_enable_blackhole);
60272 +#endif
60273 +int grsec_lastack_retries;
60274 +int grsec_enable_tpe_all;
60275 +int grsec_enable_tpe_invert;
60276 +int grsec_enable_socket_all;
60277 +int grsec_socket_all_gid;
60278 +int grsec_enable_socket_client;
60279 +int grsec_socket_client_gid;
60280 +int grsec_enable_socket_server;
60281 +int grsec_socket_server_gid;
60282 +int grsec_resource_logging;
60283 +int grsec_disable_privio;
60284 +int grsec_enable_log_rwxmaps;
60285 +int grsec_lock;
60286 +
60287 +DEFINE_SPINLOCK(grsec_alert_lock);
60288 +unsigned long grsec_alert_wtime = 0;
60289 +unsigned long grsec_alert_fyet = 0;
60290 +
60291 +DEFINE_SPINLOCK(grsec_audit_lock);
60292 +
60293 +DEFINE_RWLOCK(grsec_exec_file_lock);
60294 +
60295 +char *gr_shared_page[4];
60296 +
60297 +char *gr_alert_log_fmt;
60298 +char *gr_audit_log_fmt;
60299 +char *gr_alert_log_buf;
60300 +char *gr_audit_log_buf;
60301 +
60302 +extern struct gr_arg *gr_usermode;
60303 +extern unsigned char *gr_system_salt;
60304 +extern unsigned char *gr_system_sum;
60305 +
60306 +void __init
60307 +grsecurity_init(void)
60308 +{
60309 + int j;
60310 + /* create the per-cpu shared pages */
60311 +
60312 +#ifdef CONFIG_X86
60313 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60314 +#endif
60315 +
60316 + for (j = 0; j < 4; j++) {
60317 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60318 + if (gr_shared_page[j] == NULL) {
60319 + panic("Unable to allocate grsecurity shared page");
60320 + return;
60321 + }
60322 + }
60323 +
60324 + /* allocate log buffers */
60325 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60326 + if (!gr_alert_log_fmt) {
60327 + panic("Unable to allocate grsecurity alert log format buffer");
60328 + return;
60329 + }
60330 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60331 + if (!gr_audit_log_fmt) {
60332 + panic("Unable to allocate grsecurity audit log format buffer");
60333 + return;
60334 + }
60335 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60336 + if (!gr_alert_log_buf) {
60337 + panic("Unable to allocate grsecurity alert log buffer");
60338 + return;
60339 + }
60340 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60341 + if (!gr_audit_log_buf) {
60342 + panic("Unable to allocate grsecurity audit log buffer");
60343 + return;
60344 + }
60345 +
60346 + /* allocate memory for authentication structure */
60347 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60348 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60349 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60350 +
60351 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60352 + panic("Unable to allocate grsecurity authentication structure");
60353 + return;
60354 + }
60355 +
60356 +
60357 +#ifdef CONFIG_GRKERNSEC_IO
60358 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60359 + grsec_disable_privio = 1;
60360 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60361 + grsec_disable_privio = 1;
60362 +#else
60363 + grsec_disable_privio = 0;
60364 +#endif
60365 +#endif
60366 +
60367 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60368 + /* for backward compatibility, tpe_invert always defaults to on if
60369 + enabled in the kernel
60370 + */
60371 + grsec_enable_tpe_invert = 1;
60372 +#endif
60373 +
60374 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60375 +#ifndef CONFIG_GRKERNSEC_SYSCTL
60376 + grsec_lock = 1;
60377 +#endif
60378 +
60379 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60380 + grsec_enable_audit_textrel = 1;
60381 +#endif
60382 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60383 + grsec_enable_log_rwxmaps = 1;
60384 +#endif
60385 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60386 + grsec_enable_group = 1;
60387 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60388 +#endif
60389 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60390 + grsec_enable_ptrace_readexec = 1;
60391 +#endif
60392 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60393 + grsec_enable_chdir = 1;
60394 +#endif
60395 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60396 + grsec_enable_harden_ptrace = 1;
60397 +#endif
60398 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60399 + grsec_enable_mount = 1;
60400 +#endif
60401 +#ifdef CONFIG_GRKERNSEC_LINK
60402 + grsec_enable_link = 1;
60403 +#endif
60404 +#ifdef CONFIG_GRKERNSEC_BRUTE
60405 + grsec_enable_brute = 1;
60406 +#endif
60407 +#ifdef CONFIG_GRKERNSEC_DMESG
60408 + grsec_enable_dmesg = 1;
60409 +#endif
60410 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60411 + grsec_enable_blackhole = 1;
60412 + grsec_lastack_retries = 4;
60413 +#endif
60414 +#ifdef CONFIG_GRKERNSEC_FIFO
60415 + grsec_enable_fifo = 1;
60416 +#endif
60417 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60418 + grsec_enable_execlog = 1;
60419 +#endif
60420 +#ifdef CONFIG_GRKERNSEC_SETXID
60421 + grsec_enable_setxid = 1;
60422 +#endif
60423 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60424 + grsec_enable_signal = 1;
60425 +#endif
60426 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60427 + grsec_enable_forkfail = 1;
60428 +#endif
60429 +#ifdef CONFIG_GRKERNSEC_TIME
60430 + grsec_enable_time = 1;
60431 +#endif
60432 +#ifdef CONFIG_GRKERNSEC_RESLOG
60433 + grsec_resource_logging = 1;
60434 +#endif
60435 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60436 + grsec_enable_chroot_findtask = 1;
60437 +#endif
60438 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60439 + grsec_enable_chroot_unix = 1;
60440 +#endif
60441 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60442 + grsec_enable_chroot_mount = 1;
60443 +#endif
60444 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60445 + grsec_enable_chroot_fchdir = 1;
60446 +#endif
60447 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60448 + grsec_enable_chroot_shmat = 1;
60449 +#endif
60450 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60451 + grsec_enable_audit_ptrace = 1;
60452 +#endif
60453 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60454 + grsec_enable_chroot_double = 1;
60455 +#endif
60456 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60457 + grsec_enable_chroot_pivot = 1;
60458 +#endif
60459 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60460 + grsec_enable_chroot_chdir = 1;
60461 +#endif
60462 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60463 + grsec_enable_chroot_chmod = 1;
60464 +#endif
60465 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60466 + grsec_enable_chroot_mknod = 1;
60467 +#endif
60468 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60469 + grsec_enable_chroot_nice = 1;
60470 +#endif
60471 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60472 + grsec_enable_chroot_execlog = 1;
60473 +#endif
60474 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60475 + grsec_enable_chroot_caps = 1;
60476 +#endif
60477 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60478 + grsec_enable_chroot_sysctl = 1;
60479 +#endif
60480 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60481 + grsec_enable_symlinkown = 1;
60482 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60483 +#endif
60484 +#ifdef CONFIG_GRKERNSEC_TPE
60485 + grsec_enable_tpe = 1;
60486 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60487 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60488 + grsec_enable_tpe_all = 1;
60489 +#endif
60490 +#endif
60491 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60492 + grsec_enable_socket_all = 1;
60493 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60494 +#endif
60495 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60496 + grsec_enable_socket_client = 1;
60497 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60498 +#endif
60499 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60500 + grsec_enable_socket_server = 1;
60501 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60502 +#endif
60503 +#endif
60504 +
60505 + return;
60506 +}
60507 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60508 new file mode 100644
60509 index 0000000..6095407
60510 --- /dev/null
60511 +++ b/grsecurity/grsec_link.c
60512 @@ -0,0 +1,58 @@
60513 +#include <linux/kernel.h>
60514 +#include <linux/sched.h>
60515 +#include <linux/fs.h>
60516 +#include <linux/file.h>
60517 +#include <linux/grinternal.h>
60518 +
60519 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60520 +{
60521 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60522 + const struct inode *link_inode = link->dentry->d_inode;
60523 +
60524 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60525 + /* ignore root-owned links, e.g. /proc/self */
60526 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60527 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60528 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60529 + return 1;
60530 + }
60531 +#endif
60532 + return 0;
60533 +}
60534 +
60535 +int
60536 +gr_handle_follow_link(const struct inode *parent,
60537 + const struct inode *inode,
60538 + const struct dentry *dentry, const struct vfsmount *mnt)
60539 +{
60540 +#ifdef CONFIG_GRKERNSEC_LINK
60541 + const struct cred *cred = current_cred();
60542 +
60543 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60544 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60545 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60546 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60547 + return -EACCES;
60548 + }
60549 +#endif
60550 + return 0;
60551 +}
60552 +
60553 +int
60554 +gr_handle_hardlink(const struct dentry *dentry,
60555 + const struct vfsmount *mnt,
60556 + struct inode *inode, const int mode, const struct filename *to)
60557 +{
60558 +#ifdef CONFIG_GRKERNSEC_LINK
60559 + const struct cred *cred = current_cred();
60560 +
60561 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60562 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60563 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60564 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60565 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60566 + return -EPERM;
60567 + }
60568 +#endif
60569 + return 0;
60570 +}
60571 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60572 new file mode 100644
60573 index 0000000..7bd6c2b
60574 --- /dev/null
60575 +++ b/grsecurity/grsec_log.c
60576 @@ -0,0 +1,329 @@
60577 +#include <linux/kernel.h>
60578 +#include <linux/sched.h>
60579 +#include <linux/file.h>
60580 +#include <linux/tty.h>
60581 +#include <linux/fs.h>
60582 +#include <linux/grinternal.h>
60583 +
60584 +#ifdef CONFIG_TREE_PREEMPT_RCU
60585 +#define DISABLE_PREEMPT() preempt_disable()
60586 +#define ENABLE_PREEMPT() preempt_enable()
60587 +#else
60588 +#define DISABLE_PREEMPT()
60589 +#define ENABLE_PREEMPT()
60590 +#endif
60591 +
60592 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60593 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60594 +
60595 +#define BEGIN_LOCKS(x) \
60596 + DISABLE_PREEMPT(); \
60597 + rcu_read_lock(); \
60598 + read_lock(&tasklist_lock); \
60599 + read_lock(&grsec_exec_file_lock); \
60600 + if (x != GR_DO_AUDIT) \
60601 + spin_lock(&grsec_alert_lock); \
60602 + else \
60603 + spin_lock(&grsec_audit_lock)
60604 +
60605 +#define END_LOCKS(x) \
60606 + if (x != GR_DO_AUDIT) \
60607 + spin_unlock(&grsec_alert_lock); \
60608 + else \
60609 + spin_unlock(&grsec_audit_lock); \
60610 + read_unlock(&grsec_exec_file_lock); \
60611 + read_unlock(&tasklist_lock); \
60612 + rcu_read_unlock(); \
60613 + ENABLE_PREEMPT(); \
60614 + if (x == GR_DONT_AUDIT) \
60615 + gr_handle_alertkill(current)
60616 +
60617 +enum {
60618 + FLOODING,
60619 + NO_FLOODING
60620 +};
60621 +
60622 +extern char *gr_alert_log_fmt;
60623 +extern char *gr_audit_log_fmt;
60624 +extern char *gr_alert_log_buf;
60625 +extern char *gr_audit_log_buf;
60626 +
60627 +static int gr_log_start(int audit)
60628 +{
60629 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60630 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60631 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60632 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60633 + unsigned long curr_secs = get_seconds();
60634 +
60635 + if (audit == GR_DO_AUDIT)
60636 + goto set_fmt;
60637 +
60638 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60639 + grsec_alert_wtime = curr_secs;
60640 + grsec_alert_fyet = 0;
60641 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60642 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60643 + grsec_alert_fyet++;
60644 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60645 + grsec_alert_wtime = curr_secs;
60646 + grsec_alert_fyet++;
60647 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60648 + return FLOODING;
60649 + }
60650 + else return FLOODING;
60651 +
60652 +set_fmt:
60653 +#endif
60654 + memset(buf, 0, PAGE_SIZE);
60655 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60656 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60657 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60658 + } else if (current->signal->curr_ip) {
60659 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60660 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60661 + } else if (gr_acl_is_enabled()) {
60662 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60663 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60664 + } else {
60665 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60666 + strcpy(buf, fmt);
60667 + }
60668 +
60669 + return NO_FLOODING;
60670 +}
60671 +
60672 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60673 + __attribute__ ((format (printf, 2, 0)));
60674 +
60675 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60676 +{
60677 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60678 + unsigned int len = strlen(buf);
60679 +
60680 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60681 +
60682 + return;
60683 +}
60684 +
60685 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60686 + __attribute__ ((format (printf, 2, 3)));
60687 +
60688 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60689 +{
60690 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60691 + unsigned int len = strlen(buf);
60692 + va_list ap;
60693 +
60694 + va_start(ap, msg);
60695 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60696 + va_end(ap);
60697 +
60698 + return;
60699 +}
60700 +
60701 +static void gr_log_end(int audit, int append_default)
60702 +{
60703 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60704 + if (append_default) {
60705 + struct task_struct *task = current;
60706 + struct task_struct *parent = task->real_parent;
60707 + const struct cred *cred = __task_cred(task);
60708 + const struct cred *pcred = __task_cred(parent);
60709 + unsigned int len = strlen(buf);
60710 +
60711 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60712 + }
60713 +
60714 + printk("%s\n", buf);
60715 +
60716 + return;
60717 +}
60718 +
60719 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60720 +{
60721 + int logtype;
60722 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60723 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60724 + void *voidptr = NULL;
60725 + int num1 = 0, num2 = 0;
60726 + unsigned long ulong1 = 0, ulong2 = 0;
60727 + struct dentry *dentry = NULL;
60728 + struct vfsmount *mnt = NULL;
60729 + struct file *file = NULL;
60730 + struct task_struct *task = NULL;
60731 + const struct cred *cred, *pcred;
60732 + va_list ap;
60733 +
60734 + BEGIN_LOCKS(audit);
60735 + logtype = gr_log_start(audit);
60736 + if (logtype == FLOODING) {
60737 + END_LOCKS(audit);
60738 + return;
60739 + }
60740 + va_start(ap, argtypes);
60741 + switch (argtypes) {
60742 + case GR_TTYSNIFF:
60743 + task = va_arg(ap, struct task_struct *);
60744 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
60745 + break;
60746 + case GR_SYSCTL_HIDDEN:
60747 + str1 = va_arg(ap, char *);
60748 + gr_log_middle_varargs(audit, msg, result, str1);
60749 + break;
60750 + case GR_RBAC:
60751 + dentry = va_arg(ap, struct dentry *);
60752 + mnt = va_arg(ap, struct vfsmount *);
60753 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60754 + break;
60755 + case GR_RBAC_STR:
60756 + dentry = va_arg(ap, struct dentry *);
60757 + mnt = va_arg(ap, struct vfsmount *);
60758 + str1 = va_arg(ap, char *);
60759 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60760 + break;
60761 + case GR_STR_RBAC:
60762 + str1 = va_arg(ap, char *);
60763 + dentry = va_arg(ap, struct dentry *);
60764 + mnt = va_arg(ap, struct vfsmount *);
60765 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60766 + break;
60767 + case GR_RBAC_MODE2:
60768 + dentry = va_arg(ap, struct dentry *);
60769 + mnt = va_arg(ap, struct vfsmount *);
60770 + str1 = va_arg(ap, char *);
60771 + str2 = va_arg(ap, char *);
60772 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60773 + break;
60774 + case GR_RBAC_MODE3:
60775 + dentry = va_arg(ap, struct dentry *);
60776 + mnt = va_arg(ap, struct vfsmount *);
60777 + str1 = va_arg(ap, char *);
60778 + str2 = va_arg(ap, char *);
60779 + str3 = va_arg(ap, char *);
60780 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60781 + break;
60782 + case GR_FILENAME:
60783 + dentry = va_arg(ap, struct dentry *);
60784 + mnt = va_arg(ap, struct vfsmount *);
60785 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60786 + break;
60787 + case GR_STR_FILENAME:
60788 + str1 = va_arg(ap, char *);
60789 + dentry = va_arg(ap, struct dentry *);
60790 + mnt = va_arg(ap, struct vfsmount *);
60791 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60792 + break;
60793 + case GR_FILENAME_STR:
60794 + dentry = va_arg(ap, struct dentry *);
60795 + mnt = va_arg(ap, struct vfsmount *);
60796 + str1 = va_arg(ap, char *);
60797 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60798 + break;
60799 + case GR_FILENAME_TWO_INT:
60800 + dentry = va_arg(ap, struct dentry *);
60801 + mnt = va_arg(ap, struct vfsmount *);
60802 + num1 = va_arg(ap, int);
60803 + num2 = va_arg(ap, int);
60804 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60805 + break;
60806 + case GR_FILENAME_TWO_INT_STR:
60807 + dentry = va_arg(ap, struct dentry *);
60808 + mnt = va_arg(ap, struct vfsmount *);
60809 + num1 = va_arg(ap, int);
60810 + num2 = va_arg(ap, int);
60811 + str1 = va_arg(ap, char *);
60812 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60813 + break;
60814 + case GR_TEXTREL:
60815 + file = va_arg(ap, struct file *);
60816 + ulong1 = va_arg(ap, unsigned long);
60817 + ulong2 = va_arg(ap, unsigned long);
60818 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60819 + break;
60820 + case GR_PTRACE:
60821 + task = va_arg(ap, struct task_struct *);
60822 + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task_pid_nr(task));
60823 + break;
60824 + case GR_RESOURCE:
60825 + task = va_arg(ap, struct task_struct *);
60826 + cred = __task_cred(task);
60827 + pcred = __task_cred(task->real_parent);
60828 + ulong1 = va_arg(ap, unsigned long);
60829 + str1 = va_arg(ap, char *);
60830 + ulong2 = va_arg(ap, unsigned long);
60831 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60832 + break;
60833 + case GR_CAP:
60834 + task = va_arg(ap, struct task_struct *);
60835 + cred = __task_cred(task);
60836 + pcred = __task_cred(task->real_parent);
60837 + str1 = va_arg(ap, char *);
60838 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60839 + break;
60840 + case GR_SIG:
60841 + str1 = va_arg(ap, char *);
60842 + voidptr = va_arg(ap, void *);
60843 + gr_log_middle_varargs(audit, msg, str1, voidptr);
60844 + break;
60845 + case GR_SIG2:
60846 + task = va_arg(ap, struct task_struct *);
60847 + cred = __task_cred(task);
60848 + pcred = __task_cred(task->real_parent);
60849 + num1 = va_arg(ap, int);
60850 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60851 + break;
60852 + case GR_CRASH1:
60853 + task = va_arg(ap, struct task_struct *);
60854 + cred = __task_cred(task);
60855 + pcred = __task_cred(task->real_parent);
60856 + ulong1 = va_arg(ap, unsigned long);
60857 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
60858 + break;
60859 + case GR_CRASH2:
60860 + task = va_arg(ap, struct task_struct *);
60861 + cred = __task_cred(task);
60862 + pcred = __task_cred(task->real_parent);
60863 + ulong1 = va_arg(ap, unsigned long);
60864 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
60865 + break;
60866 + case GR_RWXMAP:
60867 + file = va_arg(ap, struct file *);
60868 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60869 + break;
60870 + case GR_PSACCT:
60871 + {
60872 + unsigned int wday, cday;
60873 + __u8 whr, chr;
60874 + __u8 wmin, cmin;
60875 + __u8 wsec, csec;
60876 + char cur_tty[64] = { 0 };
60877 + char parent_tty[64] = { 0 };
60878 +
60879 + task = va_arg(ap, struct task_struct *);
60880 + wday = va_arg(ap, unsigned int);
60881 + cday = va_arg(ap, unsigned int);
60882 + whr = va_arg(ap, int);
60883 + chr = va_arg(ap, int);
60884 + wmin = va_arg(ap, int);
60885 + cmin = va_arg(ap, int);
60886 + wsec = va_arg(ap, int);
60887 + csec = va_arg(ap, int);
60888 + ulong1 = va_arg(ap, unsigned long);
60889 + cred = __task_cred(task);
60890 + pcred = __task_cred(task->real_parent);
60891 +
60892 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60893 + }
60894 + break;
60895 + default:
60896 + gr_log_middle(audit, msg, ap);
60897 + }
60898 + va_end(ap);
60899 + // these don't need DEFAULTSECARGS printed on the end
60900 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
60901 + gr_log_end(audit, 0);
60902 + else
60903 + gr_log_end(audit, 1);
60904 + END_LOCKS(audit);
60905 +}
60906 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
60907 new file mode 100644
60908 index 0000000..f536303
60909 --- /dev/null
60910 +++ b/grsecurity/grsec_mem.c
60911 @@ -0,0 +1,40 @@
60912 +#include <linux/kernel.h>
60913 +#include <linux/sched.h>
60914 +#include <linux/mm.h>
60915 +#include <linux/mman.h>
60916 +#include <linux/grinternal.h>
60917 +
60918 +void
60919 +gr_handle_ioperm(void)
60920 +{
60921 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
60922 + return;
60923 +}
60924 +
60925 +void
60926 +gr_handle_iopl(void)
60927 +{
60928 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
60929 + return;
60930 +}
60931 +
60932 +void
60933 +gr_handle_mem_readwrite(u64 from, u64 to)
60934 +{
60935 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
60936 + return;
60937 +}
60938 +
60939 +void
60940 +gr_handle_vm86(void)
60941 +{
60942 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
60943 + return;
60944 +}
60945 +
60946 +void
60947 +gr_log_badprocpid(const char *entry)
60948 +{
60949 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
60950 + return;
60951 +}
60952 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
60953 new file mode 100644
60954 index 0000000..2131422
60955 --- /dev/null
60956 +++ b/grsecurity/grsec_mount.c
60957 @@ -0,0 +1,62 @@
60958 +#include <linux/kernel.h>
60959 +#include <linux/sched.h>
60960 +#include <linux/mount.h>
60961 +#include <linux/grsecurity.h>
60962 +#include <linux/grinternal.h>
60963 +
60964 +void
60965 +gr_log_remount(const char *devname, const int retval)
60966 +{
60967 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60968 + if (grsec_enable_mount && (retval >= 0))
60969 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
60970 +#endif
60971 + return;
60972 +}
60973 +
60974 +void
60975 +gr_log_unmount(const char *devname, const int retval)
60976 +{
60977 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60978 + if (grsec_enable_mount && (retval >= 0))
60979 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
60980 +#endif
60981 + return;
60982 +}
60983 +
60984 +void
60985 +gr_log_mount(const char *from, const char *to, const int retval)
60986 +{
60987 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60988 + if (grsec_enable_mount && (retval >= 0))
60989 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
60990 +#endif
60991 + return;
60992 +}
60993 +
60994 +int
60995 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
60996 +{
60997 +#ifdef CONFIG_GRKERNSEC_ROFS
60998 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
60999 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61000 + return -EPERM;
61001 + } else
61002 + return 0;
61003 +#endif
61004 + return 0;
61005 +}
61006 +
61007 +int
61008 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61009 +{
61010 +#ifdef CONFIG_GRKERNSEC_ROFS
61011 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61012 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61013 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61014 + return -EPERM;
61015 + } else
61016 + return 0;
61017 +#endif
61018 + return 0;
61019 +}
61020 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61021 new file mode 100644
61022 index 0000000..a3b12a0
61023 --- /dev/null
61024 +++ b/grsecurity/grsec_pax.c
61025 @@ -0,0 +1,36 @@
61026 +#include <linux/kernel.h>
61027 +#include <linux/sched.h>
61028 +#include <linux/mm.h>
61029 +#include <linux/file.h>
61030 +#include <linux/grinternal.h>
61031 +#include <linux/grsecurity.h>
61032 +
61033 +void
61034 +gr_log_textrel(struct vm_area_struct * vma)
61035 +{
61036 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61037 + if (grsec_enable_audit_textrel)
61038 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61039 +#endif
61040 + return;
61041 +}
61042 +
61043 +void
61044 +gr_log_rwxmmap(struct file *file)
61045 +{
61046 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61047 + if (grsec_enable_log_rwxmaps)
61048 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61049 +#endif
61050 + return;
61051 +}
61052 +
61053 +void
61054 +gr_log_rwxmprotect(struct file *file)
61055 +{
61056 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61057 + if (grsec_enable_log_rwxmaps)
61058 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61059 +#endif
61060 + return;
61061 +}
61062 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61063 new file mode 100644
61064 index 0000000..f7f29aa
61065 --- /dev/null
61066 +++ b/grsecurity/grsec_ptrace.c
61067 @@ -0,0 +1,30 @@
61068 +#include <linux/kernel.h>
61069 +#include <linux/sched.h>
61070 +#include <linux/grinternal.h>
61071 +#include <linux/security.h>
61072 +
61073 +void
61074 +gr_audit_ptrace(struct task_struct *task)
61075 +{
61076 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61077 + if (grsec_enable_audit_ptrace)
61078 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61079 +#endif
61080 + return;
61081 +}
61082 +
61083 +int
61084 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
61085 +{
61086 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61087 + const struct dentry *dentry = file->f_path.dentry;
61088 + const struct vfsmount *mnt = file->f_path.mnt;
61089 +
61090 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61091 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61092 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61093 + return -EACCES;
61094 + }
61095 +#endif
61096 + return 0;
61097 +}
61098 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61099 new file mode 100644
61100 index 0000000..5c00416
61101 --- /dev/null
61102 +++ b/grsecurity/grsec_sig.c
61103 @@ -0,0 +1,222 @@
61104 +#include <linux/kernel.h>
61105 +#include <linux/sched.h>
61106 +#include <linux/delay.h>
61107 +#include <linux/grsecurity.h>
61108 +#include <linux/grinternal.h>
61109 +#include <linux/hardirq.h>
61110 +
61111 +char *signames[] = {
61112 + [SIGSEGV] = "Segmentation fault",
61113 + [SIGILL] = "Illegal instruction",
61114 + [SIGABRT] = "Abort",
61115 + [SIGBUS] = "Invalid alignment/Bus error"
61116 +};
61117 +
61118 +void
61119 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61120 +{
61121 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61122 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61123 + (sig == SIGABRT) || (sig == SIGBUS))) {
61124 + if (t->pid == current->pid) {
61125 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61126 + } else {
61127 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61128 + }
61129 + }
61130 +#endif
61131 + return;
61132 +}
61133 +
61134 +int
61135 +gr_handle_signal(const struct task_struct *p, const int sig)
61136 +{
61137 +#ifdef CONFIG_GRKERNSEC
61138 + /* ignore the 0 signal for protected task checks */
61139 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61140 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61141 + return -EPERM;
61142 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61143 + return -EPERM;
61144 + }
61145 +#endif
61146 + return 0;
61147 +}
61148 +
61149 +#ifdef CONFIG_GRKERNSEC
61150 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61151 +
61152 +int gr_fake_force_sig(int sig, struct task_struct *t)
61153 +{
61154 + unsigned long int flags;
61155 + int ret, blocked, ignored;
61156 + struct k_sigaction *action;
61157 +
61158 + spin_lock_irqsave(&t->sighand->siglock, flags);
61159 + action = &t->sighand->action[sig-1];
61160 + ignored = action->sa.sa_handler == SIG_IGN;
61161 + blocked = sigismember(&t->blocked, sig);
61162 + if (blocked || ignored) {
61163 + action->sa.sa_handler = SIG_DFL;
61164 + if (blocked) {
61165 + sigdelset(&t->blocked, sig);
61166 + recalc_sigpending_and_wake(t);
61167 + }
61168 + }
61169 + if (action->sa.sa_handler == SIG_DFL)
61170 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
61171 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61172 +
61173 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
61174 +
61175 + return ret;
61176 +}
61177 +#endif
61178 +
61179 +#ifdef CONFIG_GRKERNSEC_BRUTE
61180 +#define GR_USER_BAN_TIME (15 * 60)
61181 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
61182 +
61183 +static int __get_dumpable(unsigned long mm_flags)
61184 +{
61185 + int ret;
61186 +
61187 + ret = mm_flags & MMF_DUMPABLE_MASK;
61188 + return (ret >= 2) ? 2 : ret;
61189 +}
61190 +#endif
61191 +
61192 +void gr_handle_brute_attach(unsigned long mm_flags)
61193 +{
61194 +#ifdef CONFIG_GRKERNSEC_BRUTE
61195 + struct task_struct *p = current;
61196 + kuid_t uid = GLOBAL_ROOT_UID;
61197 + int daemon = 0;
61198 +
61199 + if (!grsec_enable_brute)
61200 + return;
61201 +
61202 + rcu_read_lock();
61203 + read_lock(&tasklist_lock);
61204 + read_lock(&grsec_exec_file_lock);
61205 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61206 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61207 + p->real_parent->brute = 1;
61208 + daemon = 1;
61209 + } else {
61210 + const struct cred *cred = __task_cred(p), *cred2;
61211 + struct task_struct *tsk, *tsk2;
61212 +
61213 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61214 + struct user_struct *user;
61215 +
61216 + uid = cred->uid;
61217 +
61218 + /* this is put upon execution past expiration */
61219 + user = find_user(uid);
61220 + if (user == NULL)
61221 + goto unlock;
61222 + user->banned = 1;
61223 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61224 + if (user->ban_expires == ~0UL)
61225 + user->ban_expires--;
61226 +
61227 + do_each_thread(tsk2, tsk) {
61228 + cred2 = __task_cred(tsk);
61229 + if (tsk != p && uid_eq(cred2->uid, uid))
61230 + gr_fake_force_sig(SIGKILL, tsk);
61231 + } while_each_thread(tsk2, tsk);
61232 + }
61233 + }
61234 +unlock:
61235 + read_unlock(&grsec_exec_file_lock);
61236 + read_unlock(&tasklist_lock);
61237 + rcu_read_unlock();
61238 +
61239 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
61240 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61241 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61242 + else if (daemon)
61243 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61244 +
61245 +#endif
61246 + return;
61247 +}
61248 +
61249 +void gr_handle_brute_check(void)
61250 +{
61251 +#ifdef CONFIG_GRKERNSEC_BRUTE
61252 + struct task_struct *p = current;
61253 +
61254 + if (unlikely(p->brute)) {
61255 + if (!grsec_enable_brute)
61256 + p->brute = 0;
61257 + else if (time_before(get_seconds(), p->brute_expires))
61258 + msleep(30 * 1000);
61259 + }
61260 +#endif
61261 + return;
61262 +}
61263 +
61264 +void gr_handle_kernel_exploit(void)
61265 +{
61266 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61267 + const struct cred *cred;
61268 + struct task_struct *tsk, *tsk2;
61269 + struct user_struct *user;
61270 + kuid_t uid;
61271 +
61272 + if (in_irq() || in_serving_softirq() || in_nmi())
61273 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61274 +
61275 + uid = current_uid();
61276 +
61277 + if (uid_eq(uid, GLOBAL_ROOT_UID))
61278 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
61279 + else {
61280 + /* kill all the processes of this user, hold a reference
61281 + to their creds struct, and prevent them from creating
61282 + another process until system reset
61283 + */
61284 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61285 + from_kuid_munged(&init_user_ns, uid));
61286 + /* we intentionally leak this ref */
61287 + user = get_uid(current->cred->user);
61288 + if (user) {
61289 + user->banned = 1;
61290 + user->ban_expires = ~0UL;
61291 + }
61292 +
61293 + read_lock(&tasklist_lock);
61294 + do_each_thread(tsk2, tsk) {
61295 + cred = __task_cred(tsk);
61296 + if (uid_eq(cred->uid, uid))
61297 + gr_fake_force_sig(SIGKILL, tsk);
61298 + } while_each_thread(tsk2, tsk);
61299 + read_unlock(&tasklist_lock);
61300 + }
61301 +#endif
61302 +}
61303 +
61304 +int __gr_process_user_ban(struct user_struct *user)
61305 +{
61306 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61307 + if (unlikely(user->banned)) {
61308 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61309 + user->banned = 0;
61310 + user->ban_expires = 0;
61311 + free_uid(user);
61312 + } else
61313 + return -EPERM;
61314 + }
61315 +#endif
61316 + return 0;
61317 +}
61318 +
61319 +int gr_process_user_ban(void)
61320 +{
61321 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61322 + return __gr_process_user_ban(current->cred->user);
61323 +#endif
61324 + return 0;
61325 +}
61326 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61327 new file mode 100644
61328 index 0000000..4030d57
61329 --- /dev/null
61330 +++ b/grsecurity/grsec_sock.c
61331 @@ -0,0 +1,244 @@
61332 +#include <linux/kernel.h>
61333 +#include <linux/module.h>
61334 +#include <linux/sched.h>
61335 +#include <linux/file.h>
61336 +#include <linux/net.h>
61337 +#include <linux/in.h>
61338 +#include <linux/ip.h>
61339 +#include <net/sock.h>
61340 +#include <net/inet_sock.h>
61341 +#include <linux/grsecurity.h>
61342 +#include <linux/grinternal.h>
61343 +#include <linux/gracl.h>
61344 +
61345 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61346 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61347 +
61348 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
61349 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
61350 +
61351 +#ifdef CONFIG_UNIX_MODULE
61352 +EXPORT_SYMBOL(gr_acl_handle_unix);
61353 +EXPORT_SYMBOL(gr_acl_handle_mknod);
61354 +EXPORT_SYMBOL(gr_handle_chroot_unix);
61355 +EXPORT_SYMBOL(gr_handle_create);
61356 +#endif
61357 +
61358 +#ifdef CONFIG_GRKERNSEC
61359 +#define gr_conn_table_size 32749
61360 +struct conn_table_entry {
61361 + struct conn_table_entry *next;
61362 + struct signal_struct *sig;
61363 +};
61364 +
61365 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61366 +DEFINE_SPINLOCK(gr_conn_table_lock);
61367 +
61368 +extern const char * gr_socktype_to_name(unsigned char type);
61369 +extern const char * gr_proto_to_name(unsigned char proto);
61370 +extern const char * gr_sockfamily_to_name(unsigned char family);
61371 +
61372 +static __inline__ int
61373 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61374 +{
61375 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61376 +}
61377 +
61378 +static __inline__ int
61379 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61380 + __u16 sport, __u16 dport)
61381 +{
61382 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61383 + sig->gr_sport == sport && sig->gr_dport == dport))
61384 + return 1;
61385 + else
61386 + return 0;
61387 +}
61388 +
61389 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61390 +{
61391 + struct conn_table_entry **match;
61392 + unsigned int index;
61393 +
61394 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61395 + sig->gr_sport, sig->gr_dport,
61396 + gr_conn_table_size);
61397 +
61398 + newent->sig = sig;
61399 +
61400 + match = &gr_conn_table[index];
61401 + newent->next = *match;
61402 + *match = newent;
61403 +
61404 + return;
61405 +}
61406 +
61407 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61408 +{
61409 + struct conn_table_entry *match, *last = NULL;
61410 + unsigned int index;
61411 +
61412 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61413 + sig->gr_sport, sig->gr_dport,
61414 + gr_conn_table_size);
61415 +
61416 + match = gr_conn_table[index];
61417 + while (match && !conn_match(match->sig,
61418 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61419 + sig->gr_dport)) {
61420 + last = match;
61421 + match = match->next;
61422 + }
61423 +
61424 + if (match) {
61425 + if (last)
61426 + last->next = match->next;
61427 + else
61428 + gr_conn_table[index] = NULL;
61429 + kfree(match);
61430 + }
61431 +
61432 + return;
61433 +}
61434 +
61435 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61436 + __u16 sport, __u16 dport)
61437 +{
61438 + struct conn_table_entry *match;
61439 + unsigned int index;
61440 +
61441 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61442 +
61443 + match = gr_conn_table[index];
61444 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61445 + match = match->next;
61446 +
61447 + if (match)
61448 + return match->sig;
61449 + else
61450 + return NULL;
61451 +}
61452 +
61453 +#endif
61454 +
61455 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61456 +{
61457 +#ifdef CONFIG_GRKERNSEC
61458 + struct signal_struct *sig = task->signal;
61459 + struct conn_table_entry *newent;
61460 +
61461 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61462 + if (newent == NULL)
61463 + return;
61464 + /* no bh lock needed since we are called with bh disabled */
61465 + spin_lock(&gr_conn_table_lock);
61466 + gr_del_task_from_ip_table_nolock(sig);
61467 + sig->gr_saddr = inet->inet_rcv_saddr;
61468 + sig->gr_daddr = inet->inet_daddr;
61469 + sig->gr_sport = inet->inet_sport;
61470 + sig->gr_dport = inet->inet_dport;
61471 + gr_add_to_task_ip_table_nolock(sig, newent);
61472 + spin_unlock(&gr_conn_table_lock);
61473 +#endif
61474 + return;
61475 +}
61476 +
61477 +void gr_del_task_from_ip_table(struct task_struct *task)
61478 +{
61479 +#ifdef CONFIG_GRKERNSEC
61480 + spin_lock_bh(&gr_conn_table_lock);
61481 + gr_del_task_from_ip_table_nolock(task->signal);
61482 + spin_unlock_bh(&gr_conn_table_lock);
61483 +#endif
61484 + return;
61485 +}
61486 +
61487 +void
61488 +gr_attach_curr_ip(const struct sock *sk)
61489 +{
61490 +#ifdef CONFIG_GRKERNSEC
61491 + struct signal_struct *p, *set;
61492 + const struct inet_sock *inet = inet_sk(sk);
61493 +
61494 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61495 + return;
61496 +
61497 + set = current->signal;
61498 +
61499 + spin_lock_bh(&gr_conn_table_lock);
61500 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61501 + inet->inet_dport, inet->inet_sport);
61502 + if (unlikely(p != NULL)) {
61503 + set->curr_ip = p->curr_ip;
61504 + set->used_accept = 1;
61505 + gr_del_task_from_ip_table_nolock(p);
61506 + spin_unlock_bh(&gr_conn_table_lock);
61507 + return;
61508 + }
61509 + spin_unlock_bh(&gr_conn_table_lock);
61510 +
61511 + set->curr_ip = inet->inet_daddr;
61512 + set->used_accept = 1;
61513 +#endif
61514 + return;
61515 +}
61516 +
61517 +int
61518 +gr_handle_sock_all(const int family, const int type, const int protocol)
61519 +{
61520 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61521 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61522 + (family != AF_UNIX)) {
61523 + if (family == AF_INET)
61524 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61525 + else
61526 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61527 + return -EACCES;
61528 + }
61529 +#endif
61530 + return 0;
61531 +}
61532 +
61533 +int
61534 +gr_handle_sock_server(const struct sockaddr *sck)
61535 +{
61536 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61537 + if (grsec_enable_socket_server &&
61538 + in_group_p(grsec_socket_server_gid) &&
61539 + sck && (sck->sa_family != AF_UNIX) &&
61540 + (sck->sa_family != AF_LOCAL)) {
61541 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61542 + return -EACCES;
61543 + }
61544 +#endif
61545 + return 0;
61546 +}
61547 +
61548 +int
61549 +gr_handle_sock_server_other(const struct sock *sck)
61550 +{
61551 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61552 + if (grsec_enable_socket_server &&
61553 + in_group_p(grsec_socket_server_gid) &&
61554 + sck && (sck->sk_family != AF_UNIX) &&
61555 + (sck->sk_family != AF_LOCAL)) {
61556 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61557 + return -EACCES;
61558 + }
61559 +#endif
61560 + return 0;
61561 +}
61562 +
61563 +int
61564 +gr_handle_sock_client(const struct sockaddr *sck)
61565 +{
61566 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61567 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61568 + sck && (sck->sa_family != AF_UNIX) &&
61569 + (sck->sa_family != AF_LOCAL)) {
61570 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61571 + return -EACCES;
61572 + }
61573 +#endif
61574 + return 0;
61575 +}
61576 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61577 new file mode 100644
61578 index 0000000..f55ef0f
61579 --- /dev/null
61580 +++ b/grsecurity/grsec_sysctl.c
61581 @@ -0,0 +1,469 @@
61582 +#include <linux/kernel.h>
61583 +#include <linux/sched.h>
61584 +#include <linux/sysctl.h>
61585 +#include <linux/grsecurity.h>
61586 +#include <linux/grinternal.h>
61587 +
61588 +int
61589 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61590 +{
61591 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61592 + if (dirname == NULL || name == NULL)
61593 + return 0;
61594 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61595 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61596 + return -EACCES;
61597 + }
61598 +#endif
61599 + return 0;
61600 +}
61601 +
61602 +#ifdef CONFIG_GRKERNSEC_ROFS
61603 +static int __maybe_unused one = 1;
61604 +#endif
61605 +
61606 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61607 +struct ctl_table grsecurity_table[] = {
61608 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61609 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61610 +#ifdef CONFIG_GRKERNSEC_IO
61611 + {
61612 + .procname = "disable_priv_io",
61613 + .data = &grsec_disable_privio,
61614 + .maxlen = sizeof(int),
61615 + .mode = 0600,
61616 + .proc_handler = &proc_dointvec,
61617 + },
61618 +#endif
61619 +#endif
61620 +#ifdef CONFIG_GRKERNSEC_LINK
61621 + {
61622 + .procname = "linking_restrictions",
61623 + .data = &grsec_enable_link,
61624 + .maxlen = sizeof(int),
61625 + .mode = 0600,
61626 + .proc_handler = &proc_dointvec,
61627 + },
61628 +#endif
61629 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61630 + {
61631 + .procname = "enforce_symlinksifowner",
61632 + .data = &grsec_enable_symlinkown,
61633 + .maxlen = sizeof(int),
61634 + .mode = 0600,
61635 + .proc_handler = &proc_dointvec,
61636 + },
61637 + {
61638 + .procname = "symlinkown_gid",
61639 + .data = &grsec_symlinkown_gid,
61640 + .maxlen = sizeof(int),
61641 + .mode = 0600,
61642 + .proc_handler = &proc_dointvec,
61643 + },
61644 +#endif
61645 +#ifdef CONFIG_GRKERNSEC_BRUTE
61646 + {
61647 + .procname = "deter_bruteforce",
61648 + .data = &grsec_enable_brute,
61649 + .maxlen = sizeof(int),
61650 + .mode = 0600,
61651 + .proc_handler = &proc_dointvec,
61652 + },
61653 +#endif
61654 +#ifdef CONFIG_GRKERNSEC_FIFO
61655 + {
61656 + .procname = "fifo_restrictions",
61657 + .data = &grsec_enable_fifo,
61658 + .maxlen = sizeof(int),
61659 + .mode = 0600,
61660 + .proc_handler = &proc_dointvec,
61661 + },
61662 +#endif
61663 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61664 + {
61665 + .procname = "ptrace_readexec",
61666 + .data = &grsec_enable_ptrace_readexec,
61667 + .maxlen = sizeof(int),
61668 + .mode = 0600,
61669 + .proc_handler = &proc_dointvec,
61670 + },
61671 +#endif
61672 +#ifdef CONFIG_GRKERNSEC_SETXID
61673 + {
61674 + .procname = "consistent_setxid",
61675 + .data = &grsec_enable_setxid,
61676 + .maxlen = sizeof(int),
61677 + .mode = 0600,
61678 + .proc_handler = &proc_dointvec,
61679 + },
61680 +#endif
61681 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61682 + {
61683 + .procname = "ip_blackhole",
61684 + .data = &grsec_enable_blackhole,
61685 + .maxlen = sizeof(int),
61686 + .mode = 0600,
61687 + .proc_handler = &proc_dointvec,
61688 + },
61689 + {
61690 + .procname = "lastack_retries",
61691 + .data = &grsec_lastack_retries,
61692 + .maxlen = sizeof(int),
61693 + .mode = 0600,
61694 + .proc_handler = &proc_dointvec,
61695 + },
61696 +#endif
61697 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61698 + {
61699 + .procname = "exec_logging",
61700 + .data = &grsec_enable_execlog,
61701 + .maxlen = sizeof(int),
61702 + .mode = 0600,
61703 + .proc_handler = &proc_dointvec,
61704 + },
61705 +#endif
61706 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61707 + {
61708 + .procname = "rwxmap_logging",
61709 + .data = &grsec_enable_log_rwxmaps,
61710 + .maxlen = sizeof(int),
61711 + .mode = 0600,
61712 + .proc_handler = &proc_dointvec,
61713 + },
61714 +#endif
61715 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61716 + {
61717 + .procname = "signal_logging",
61718 + .data = &grsec_enable_signal,
61719 + .maxlen = sizeof(int),
61720 + .mode = 0600,
61721 + .proc_handler = &proc_dointvec,
61722 + },
61723 +#endif
61724 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61725 + {
61726 + .procname = "forkfail_logging",
61727 + .data = &grsec_enable_forkfail,
61728 + .maxlen = sizeof(int),
61729 + .mode = 0600,
61730 + .proc_handler = &proc_dointvec,
61731 + },
61732 +#endif
61733 +#ifdef CONFIG_GRKERNSEC_TIME
61734 + {
61735 + .procname = "timechange_logging",
61736 + .data = &grsec_enable_time,
61737 + .maxlen = sizeof(int),
61738 + .mode = 0600,
61739 + .proc_handler = &proc_dointvec,
61740 + },
61741 +#endif
61742 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61743 + {
61744 + .procname = "chroot_deny_shmat",
61745 + .data = &grsec_enable_chroot_shmat,
61746 + .maxlen = sizeof(int),
61747 + .mode = 0600,
61748 + .proc_handler = &proc_dointvec,
61749 + },
61750 +#endif
61751 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61752 + {
61753 + .procname = "chroot_deny_unix",
61754 + .data = &grsec_enable_chroot_unix,
61755 + .maxlen = sizeof(int),
61756 + .mode = 0600,
61757 + .proc_handler = &proc_dointvec,
61758 + },
61759 +#endif
61760 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61761 + {
61762 + .procname = "chroot_deny_mount",
61763 + .data = &grsec_enable_chroot_mount,
61764 + .maxlen = sizeof(int),
61765 + .mode = 0600,
61766 + .proc_handler = &proc_dointvec,
61767 + },
61768 +#endif
61769 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61770 + {
61771 + .procname = "chroot_deny_fchdir",
61772 + .data = &grsec_enable_chroot_fchdir,
61773 + .maxlen = sizeof(int),
61774 + .mode = 0600,
61775 + .proc_handler = &proc_dointvec,
61776 + },
61777 +#endif
61778 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61779 + {
61780 + .procname = "chroot_deny_chroot",
61781 + .data = &grsec_enable_chroot_double,
61782 + .maxlen = sizeof(int),
61783 + .mode = 0600,
61784 + .proc_handler = &proc_dointvec,
61785 + },
61786 +#endif
61787 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61788 + {
61789 + .procname = "chroot_deny_pivot",
61790 + .data = &grsec_enable_chroot_pivot,
61791 + .maxlen = sizeof(int),
61792 + .mode = 0600,
61793 + .proc_handler = &proc_dointvec,
61794 + },
61795 +#endif
61796 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61797 + {
61798 + .procname = "chroot_enforce_chdir",
61799 + .data = &grsec_enable_chroot_chdir,
61800 + .maxlen = sizeof(int),
61801 + .mode = 0600,
61802 + .proc_handler = &proc_dointvec,
61803 + },
61804 +#endif
61805 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61806 + {
61807 + .procname = "chroot_deny_chmod",
61808 + .data = &grsec_enable_chroot_chmod,
61809 + .maxlen = sizeof(int),
61810 + .mode = 0600,
61811 + .proc_handler = &proc_dointvec,
61812 + },
61813 +#endif
61814 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61815 + {
61816 + .procname = "chroot_deny_mknod",
61817 + .data = &grsec_enable_chroot_mknod,
61818 + .maxlen = sizeof(int),
61819 + .mode = 0600,
61820 + .proc_handler = &proc_dointvec,
61821 + },
61822 +#endif
61823 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61824 + {
61825 + .procname = "chroot_restrict_nice",
61826 + .data = &grsec_enable_chroot_nice,
61827 + .maxlen = sizeof(int),
61828 + .mode = 0600,
61829 + .proc_handler = &proc_dointvec,
61830 + },
61831 +#endif
61832 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61833 + {
61834 + .procname = "chroot_execlog",
61835 + .data = &grsec_enable_chroot_execlog,
61836 + .maxlen = sizeof(int),
61837 + .mode = 0600,
61838 + .proc_handler = &proc_dointvec,
61839 + },
61840 +#endif
61841 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61842 + {
61843 + .procname = "chroot_caps",
61844 + .data = &grsec_enable_chroot_caps,
61845 + .maxlen = sizeof(int),
61846 + .mode = 0600,
61847 + .proc_handler = &proc_dointvec,
61848 + },
61849 +#endif
61850 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61851 + {
61852 + .procname = "chroot_deny_sysctl",
61853 + .data = &grsec_enable_chroot_sysctl,
61854 + .maxlen = sizeof(int),
61855 + .mode = 0600,
61856 + .proc_handler = &proc_dointvec,
61857 + },
61858 +#endif
61859 +#ifdef CONFIG_GRKERNSEC_TPE
61860 + {
61861 + .procname = "tpe",
61862 + .data = &grsec_enable_tpe,
61863 + .maxlen = sizeof(int),
61864 + .mode = 0600,
61865 + .proc_handler = &proc_dointvec,
61866 + },
61867 + {
61868 + .procname = "tpe_gid",
61869 + .data = &grsec_tpe_gid,
61870 + .maxlen = sizeof(int),
61871 + .mode = 0600,
61872 + .proc_handler = &proc_dointvec,
61873 + },
61874 +#endif
61875 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61876 + {
61877 + .procname = "tpe_invert",
61878 + .data = &grsec_enable_tpe_invert,
61879 + .maxlen = sizeof(int),
61880 + .mode = 0600,
61881 + .proc_handler = &proc_dointvec,
61882 + },
61883 +#endif
61884 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61885 + {
61886 + .procname = "tpe_restrict_all",
61887 + .data = &grsec_enable_tpe_all,
61888 + .maxlen = sizeof(int),
61889 + .mode = 0600,
61890 + .proc_handler = &proc_dointvec,
61891 + },
61892 +#endif
61893 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61894 + {
61895 + .procname = "socket_all",
61896 + .data = &grsec_enable_socket_all,
61897 + .maxlen = sizeof(int),
61898 + .mode = 0600,
61899 + .proc_handler = &proc_dointvec,
61900 + },
61901 + {
61902 + .procname = "socket_all_gid",
61903 + .data = &grsec_socket_all_gid,
61904 + .maxlen = sizeof(int),
61905 + .mode = 0600,
61906 + .proc_handler = &proc_dointvec,
61907 + },
61908 +#endif
61909 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61910 + {
61911 + .procname = "socket_client",
61912 + .data = &grsec_enable_socket_client,
61913 + .maxlen = sizeof(int),
61914 + .mode = 0600,
61915 + .proc_handler = &proc_dointvec,
61916 + },
61917 + {
61918 + .procname = "socket_client_gid",
61919 + .data = &grsec_socket_client_gid,
61920 + .maxlen = sizeof(int),
61921 + .mode = 0600,
61922 + .proc_handler = &proc_dointvec,
61923 + },
61924 +#endif
61925 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61926 + {
61927 + .procname = "socket_server",
61928 + .data = &grsec_enable_socket_server,
61929 + .maxlen = sizeof(int),
61930 + .mode = 0600,
61931 + .proc_handler = &proc_dointvec,
61932 + },
61933 + {
61934 + .procname = "socket_server_gid",
61935 + .data = &grsec_socket_server_gid,
61936 + .maxlen = sizeof(int),
61937 + .mode = 0600,
61938 + .proc_handler = &proc_dointvec,
61939 + },
61940 +#endif
61941 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61942 + {
61943 + .procname = "audit_group",
61944 + .data = &grsec_enable_group,
61945 + .maxlen = sizeof(int),
61946 + .mode = 0600,
61947 + .proc_handler = &proc_dointvec,
61948 + },
61949 + {
61950 + .procname = "audit_gid",
61951 + .data = &grsec_audit_gid,
61952 + .maxlen = sizeof(int),
61953 + .mode = 0600,
61954 + .proc_handler = &proc_dointvec,
61955 + },
61956 +#endif
61957 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61958 + {
61959 + .procname = "audit_chdir",
61960 + .data = &grsec_enable_chdir,
61961 + .maxlen = sizeof(int),
61962 + .mode = 0600,
61963 + .proc_handler = &proc_dointvec,
61964 + },
61965 +#endif
61966 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61967 + {
61968 + .procname = "audit_mount",
61969 + .data = &grsec_enable_mount,
61970 + .maxlen = sizeof(int),
61971 + .mode = 0600,
61972 + .proc_handler = &proc_dointvec,
61973 + },
61974 +#endif
61975 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61976 + {
61977 + .procname = "audit_textrel",
61978 + .data = &grsec_enable_audit_textrel,
61979 + .maxlen = sizeof(int),
61980 + .mode = 0600,
61981 + .proc_handler = &proc_dointvec,
61982 + },
61983 +#endif
61984 +#ifdef CONFIG_GRKERNSEC_DMESG
61985 + {
61986 + .procname = "dmesg",
61987 + .data = &grsec_enable_dmesg,
61988 + .maxlen = sizeof(int),
61989 + .mode = 0600,
61990 + .proc_handler = &proc_dointvec,
61991 + },
61992 +#endif
61993 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61994 + {
61995 + .procname = "chroot_findtask",
61996 + .data = &grsec_enable_chroot_findtask,
61997 + .maxlen = sizeof(int),
61998 + .mode = 0600,
61999 + .proc_handler = &proc_dointvec,
62000 + },
62001 +#endif
62002 +#ifdef CONFIG_GRKERNSEC_RESLOG
62003 + {
62004 + .procname = "resource_logging",
62005 + .data = &grsec_resource_logging,
62006 + .maxlen = sizeof(int),
62007 + .mode = 0600,
62008 + .proc_handler = &proc_dointvec,
62009 + },
62010 +#endif
62011 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62012 + {
62013 + .procname = "audit_ptrace",
62014 + .data = &grsec_enable_audit_ptrace,
62015 + .maxlen = sizeof(int),
62016 + .mode = 0600,
62017 + .proc_handler = &proc_dointvec,
62018 + },
62019 +#endif
62020 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62021 + {
62022 + .procname = "harden_ptrace",
62023 + .data = &grsec_enable_harden_ptrace,
62024 + .maxlen = sizeof(int),
62025 + .mode = 0600,
62026 + .proc_handler = &proc_dointvec,
62027 + },
62028 +#endif
62029 + {
62030 + .procname = "grsec_lock",
62031 + .data = &grsec_lock,
62032 + .maxlen = sizeof(int),
62033 + .mode = 0600,
62034 + .proc_handler = &proc_dointvec,
62035 + },
62036 +#endif
62037 +#ifdef CONFIG_GRKERNSEC_ROFS
62038 + {
62039 + .procname = "romount_protect",
62040 + .data = &grsec_enable_rofs,
62041 + .maxlen = sizeof(int),
62042 + .mode = 0600,
62043 + .proc_handler = &proc_dointvec_minmax,
62044 + .extra1 = &one,
62045 + .extra2 = &one,
62046 + },
62047 +#endif
62048 + { }
62049 +};
62050 +#endif
62051 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62052 new file mode 100644
62053 index 0000000..0dc13c3
62054 --- /dev/null
62055 +++ b/grsecurity/grsec_time.c
62056 @@ -0,0 +1,16 @@
62057 +#include <linux/kernel.h>
62058 +#include <linux/sched.h>
62059 +#include <linux/grinternal.h>
62060 +#include <linux/module.h>
62061 +
62062 +void
62063 +gr_log_timechange(void)
62064 +{
62065 +#ifdef CONFIG_GRKERNSEC_TIME
62066 + if (grsec_enable_time)
62067 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62068 +#endif
62069 + return;
62070 +}
62071 +
62072 +EXPORT_SYMBOL(gr_log_timechange);
62073 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62074 new file mode 100644
62075 index 0000000..07e0dc0
62076 --- /dev/null
62077 +++ b/grsecurity/grsec_tpe.c
62078 @@ -0,0 +1,73 @@
62079 +#include <linux/kernel.h>
62080 +#include <linux/sched.h>
62081 +#include <linux/file.h>
62082 +#include <linux/fs.h>
62083 +#include <linux/grinternal.h>
62084 +
62085 +extern int gr_acl_tpe_check(void);
62086 +
62087 +int
62088 +gr_tpe_allow(const struct file *file)
62089 +{
62090 +#ifdef CONFIG_GRKERNSEC
62091 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62092 + const struct cred *cred = current_cred();
62093 + char *msg = NULL;
62094 + char *msg2 = NULL;
62095 +
62096 + // never restrict root
62097 + if (!cred->uid)
62098 + return 1;
62099 +
62100 + if (grsec_enable_tpe) {
62101 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62102 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62103 + msg = "not being in trusted group";
62104 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62105 + msg = "being in untrusted group";
62106 +#else
62107 + if (in_group_p(grsec_tpe_gid))
62108 + msg = "being in untrusted group";
62109 +#endif
62110 + }
62111 + if (!msg && gr_acl_tpe_check())
62112 + msg = "being in untrusted role";
62113 +
62114 + // not in any affected group/role
62115 + if (!msg)
62116 + goto next_check;
62117 +
62118 + if (inode->i_uid)
62119 + msg2 = "file in non-root-owned directory";
62120 + else if (inode->i_mode & S_IWOTH)
62121 + msg2 = "file in world-writable directory";
62122 + else if (inode->i_mode & S_IWGRP)
62123 + msg2 = "file in group-writable directory";
62124 +
62125 + if (msg && msg2) {
62126 + char fullmsg[70] = {0};
62127 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62128 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62129 + return 0;
62130 + }
62131 + msg = NULL;
62132 +next_check:
62133 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62134 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62135 + return 1;
62136 +
62137 + if (inode->i_uid && (inode->i_uid != cred->uid))
62138 + msg = "directory not owned by user";
62139 + else if (inode->i_mode & S_IWOTH)
62140 + msg = "file in world-writable directory";
62141 + else if (inode->i_mode & S_IWGRP)
62142 + msg = "file in group-writable directory";
62143 +
62144 + if (msg) {
62145 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62146 + return 0;
62147 + }
62148 +#endif
62149 +#endif
62150 + return 1;
62151 +}
62152 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62153 new file mode 100644
62154 index 0000000..9f7b1ac
62155 --- /dev/null
62156 +++ b/grsecurity/grsum.c
62157 @@ -0,0 +1,61 @@
62158 +#include <linux/err.h>
62159 +#include <linux/kernel.h>
62160 +#include <linux/sched.h>
62161 +#include <linux/mm.h>
62162 +#include <linux/scatterlist.h>
62163 +#include <linux/crypto.h>
62164 +#include <linux/gracl.h>
62165 +
62166 +
62167 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62168 +#error "crypto and sha256 must be built into the kernel"
62169 +#endif
62170 +
62171 +int
62172 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62173 +{
62174 + char *p;
62175 + struct crypto_hash *tfm;
62176 + struct hash_desc desc;
62177 + struct scatterlist sg;
62178 + unsigned char temp_sum[GR_SHA_LEN];
62179 + volatile int retval = 0;
62180 + volatile int dummy = 0;
62181 + unsigned int i;
62182 +
62183 + sg_init_table(&sg, 1);
62184 +
62185 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62186 + if (IS_ERR(tfm)) {
62187 + /* should never happen, since sha256 should be built in */
62188 + return 1;
62189 + }
62190 +
62191 + desc.tfm = tfm;
62192 + desc.flags = 0;
62193 +
62194 + crypto_hash_init(&desc);
62195 +
62196 + p = salt;
62197 + sg_set_buf(&sg, p, GR_SALT_LEN);
62198 + crypto_hash_update(&desc, &sg, sg.length);
62199 +
62200 + p = entry->pw;
62201 + sg_set_buf(&sg, p, strlen(p));
62202 +
62203 + crypto_hash_update(&desc, &sg, sg.length);
62204 +
62205 + crypto_hash_final(&desc, temp_sum);
62206 +
62207 + memset(entry->pw, 0, GR_PW_LEN);
62208 +
62209 + for (i = 0; i < GR_SHA_LEN; i++)
62210 + if (sum[i] != temp_sum[i])
62211 + retval = 1;
62212 + else
62213 + dummy = 1; // waste a cycle
62214 +
62215 + crypto_free_hash(tfm);
62216 +
62217 + return retval;
62218 +}
62219 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62220 index 77ff547..181834f 100644
62221 --- a/include/asm-generic/4level-fixup.h
62222 +++ b/include/asm-generic/4level-fixup.h
62223 @@ -13,8 +13,10 @@
62224 #define pmd_alloc(mm, pud, address) \
62225 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62226 NULL: pmd_offset(pud, address))
62227 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62228
62229 #define pud_alloc(mm, pgd, address) (pgd)
62230 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62231 #define pud_offset(pgd, start) (pgd)
62232 #define pud_none(pud) 0
62233 #define pud_bad(pud) 0
62234 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62235 index b7babf0..04ad282 100644
62236 --- a/include/asm-generic/atomic-long.h
62237 +++ b/include/asm-generic/atomic-long.h
62238 @@ -22,6 +22,12 @@
62239
62240 typedef atomic64_t atomic_long_t;
62241
62242 +#ifdef CONFIG_PAX_REFCOUNT
62243 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
62244 +#else
62245 +typedef atomic64_t atomic_long_unchecked_t;
62246 +#endif
62247 +
62248 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62249
62250 static inline long atomic_long_read(atomic_long_t *l)
62251 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62252 return (long)atomic64_read(v);
62253 }
62254
62255 +#ifdef CONFIG_PAX_REFCOUNT
62256 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62257 +{
62258 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62259 +
62260 + return (long)atomic64_read_unchecked(v);
62261 +}
62262 +#endif
62263 +
62264 static inline void atomic_long_set(atomic_long_t *l, long i)
62265 {
62266 atomic64_t *v = (atomic64_t *)l;
62267 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62268 atomic64_set(v, i);
62269 }
62270
62271 +#ifdef CONFIG_PAX_REFCOUNT
62272 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62273 +{
62274 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62275 +
62276 + atomic64_set_unchecked(v, i);
62277 +}
62278 +#endif
62279 +
62280 static inline void atomic_long_inc(atomic_long_t *l)
62281 {
62282 atomic64_t *v = (atomic64_t *)l;
62283 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62284 atomic64_inc(v);
62285 }
62286
62287 +#ifdef CONFIG_PAX_REFCOUNT
62288 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62289 +{
62290 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62291 +
62292 + atomic64_inc_unchecked(v);
62293 +}
62294 +#endif
62295 +
62296 static inline void atomic_long_dec(atomic_long_t *l)
62297 {
62298 atomic64_t *v = (atomic64_t *)l;
62299 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62300 atomic64_dec(v);
62301 }
62302
62303 +#ifdef CONFIG_PAX_REFCOUNT
62304 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62305 +{
62306 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62307 +
62308 + atomic64_dec_unchecked(v);
62309 +}
62310 +#endif
62311 +
62312 static inline void atomic_long_add(long i, atomic_long_t *l)
62313 {
62314 atomic64_t *v = (atomic64_t *)l;
62315 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62316 atomic64_add(i, v);
62317 }
62318
62319 +#ifdef CONFIG_PAX_REFCOUNT
62320 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62321 +{
62322 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62323 +
62324 + atomic64_add_unchecked(i, v);
62325 +}
62326 +#endif
62327 +
62328 static inline void atomic_long_sub(long i, atomic_long_t *l)
62329 {
62330 atomic64_t *v = (atomic64_t *)l;
62331 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62332 atomic64_sub(i, v);
62333 }
62334
62335 +#ifdef CONFIG_PAX_REFCOUNT
62336 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62337 +{
62338 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62339 +
62340 + atomic64_sub_unchecked(i, v);
62341 +}
62342 +#endif
62343 +
62344 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62345 {
62346 atomic64_t *v = (atomic64_t *)l;
62347 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62348 return (long)atomic64_add_return(i, v);
62349 }
62350
62351 +#ifdef CONFIG_PAX_REFCOUNT
62352 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62353 +{
62354 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62355 +
62356 + return (long)atomic64_add_return_unchecked(i, v);
62357 +}
62358 +#endif
62359 +
62360 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62361 {
62362 atomic64_t *v = (atomic64_t *)l;
62363 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62364 return (long)atomic64_inc_return(v);
62365 }
62366
62367 +#ifdef CONFIG_PAX_REFCOUNT
62368 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62369 +{
62370 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62371 +
62372 + return (long)atomic64_inc_return_unchecked(v);
62373 +}
62374 +#endif
62375 +
62376 static inline long atomic_long_dec_return(atomic_long_t *l)
62377 {
62378 atomic64_t *v = (atomic64_t *)l;
62379 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62380
62381 typedef atomic_t atomic_long_t;
62382
62383 +#ifdef CONFIG_PAX_REFCOUNT
62384 +typedef atomic_unchecked_t atomic_long_unchecked_t;
62385 +#else
62386 +typedef atomic_t atomic_long_unchecked_t;
62387 +#endif
62388 +
62389 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62390 static inline long atomic_long_read(atomic_long_t *l)
62391 {
62392 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62393 return (long)atomic_read(v);
62394 }
62395
62396 +#ifdef CONFIG_PAX_REFCOUNT
62397 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62398 +{
62399 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62400 +
62401 + return (long)atomic_read_unchecked(v);
62402 +}
62403 +#endif
62404 +
62405 static inline void atomic_long_set(atomic_long_t *l, long i)
62406 {
62407 atomic_t *v = (atomic_t *)l;
62408 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62409 atomic_set(v, i);
62410 }
62411
62412 +#ifdef CONFIG_PAX_REFCOUNT
62413 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62414 +{
62415 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62416 +
62417 + atomic_set_unchecked(v, i);
62418 +}
62419 +#endif
62420 +
62421 static inline void atomic_long_inc(atomic_long_t *l)
62422 {
62423 atomic_t *v = (atomic_t *)l;
62424 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62425 atomic_inc(v);
62426 }
62427
62428 +#ifdef CONFIG_PAX_REFCOUNT
62429 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62430 +{
62431 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62432 +
62433 + atomic_inc_unchecked(v);
62434 +}
62435 +#endif
62436 +
62437 static inline void atomic_long_dec(atomic_long_t *l)
62438 {
62439 atomic_t *v = (atomic_t *)l;
62440 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62441 atomic_dec(v);
62442 }
62443
62444 +#ifdef CONFIG_PAX_REFCOUNT
62445 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62446 +{
62447 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62448 +
62449 + atomic_dec_unchecked(v);
62450 +}
62451 +#endif
62452 +
62453 static inline void atomic_long_add(long i, atomic_long_t *l)
62454 {
62455 atomic_t *v = (atomic_t *)l;
62456 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62457 atomic_add(i, v);
62458 }
62459
62460 +#ifdef CONFIG_PAX_REFCOUNT
62461 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62462 +{
62463 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62464 +
62465 + atomic_add_unchecked(i, v);
62466 +}
62467 +#endif
62468 +
62469 static inline void atomic_long_sub(long i, atomic_long_t *l)
62470 {
62471 atomic_t *v = (atomic_t *)l;
62472 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62473 atomic_sub(i, v);
62474 }
62475
62476 +#ifdef CONFIG_PAX_REFCOUNT
62477 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62478 +{
62479 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62480 +
62481 + atomic_sub_unchecked(i, v);
62482 +}
62483 +#endif
62484 +
62485 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62486 {
62487 atomic_t *v = (atomic_t *)l;
62488 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62489 return (long)atomic_add_return(i, v);
62490 }
62491
62492 +#ifdef CONFIG_PAX_REFCOUNT
62493 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62494 +{
62495 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62496 +
62497 + return (long)atomic_add_return_unchecked(i, v);
62498 +}
62499 +
62500 +#endif
62501 +
62502 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62503 {
62504 atomic_t *v = (atomic_t *)l;
62505 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62506 return (long)atomic_inc_return(v);
62507 }
62508
62509 +#ifdef CONFIG_PAX_REFCOUNT
62510 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62511 +{
62512 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62513 +
62514 + return (long)atomic_inc_return_unchecked(v);
62515 +}
62516 +#endif
62517 +
62518 static inline long atomic_long_dec_return(atomic_long_t *l)
62519 {
62520 atomic_t *v = (atomic_t *)l;
62521 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62522
62523 #endif /* BITS_PER_LONG == 64 */
62524
62525 +#ifdef CONFIG_PAX_REFCOUNT
62526 +static inline void pax_refcount_needs_these_functions(void)
62527 +{
62528 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62529 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62530 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62531 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62532 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62533 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62534 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62535 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62536 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62537 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62538 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62539 +#ifdef CONFIG_X86
62540 + atomic_clear_mask_unchecked(0, NULL);
62541 + atomic_set_mask_unchecked(0, NULL);
62542 +#endif
62543 +
62544 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62545 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62546 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62547 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62548 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62549 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62550 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62551 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62552 +}
62553 +#else
62554 +#define atomic_read_unchecked(v) atomic_read(v)
62555 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62556 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62557 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62558 +#define atomic_inc_unchecked(v) atomic_inc(v)
62559 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62560 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62561 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62562 +#define atomic_dec_unchecked(v) atomic_dec(v)
62563 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62564 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62565 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62566 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62567 +
62568 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62569 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62570 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62571 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62572 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62573 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62574 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62575 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62576 +#endif
62577 +
62578 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62579 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62580 index 1ced641..c896ee8 100644
62581 --- a/include/asm-generic/atomic.h
62582 +++ b/include/asm-generic/atomic.h
62583 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62584 * Atomically clears the bits set in @mask from @v
62585 */
62586 #ifndef atomic_clear_mask
62587 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62588 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62589 {
62590 unsigned long flags;
62591
62592 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62593 index b18ce4f..2ee2843 100644
62594 --- a/include/asm-generic/atomic64.h
62595 +++ b/include/asm-generic/atomic64.h
62596 @@ -16,6 +16,8 @@ typedef struct {
62597 long long counter;
62598 } atomic64_t;
62599
62600 +typedef atomic64_t atomic64_unchecked_t;
62601 +
62602 #define ATOMIC64_INIT(i) { (i) }
62603
62604 extern long long atomic64_read(const atomic64_t *v);
62605 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62606 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62607 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62608
62609 +#define atomic64_read_unchecked(v) atomic64_read(v)
62610 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62611 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62612 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62613 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62614 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62615 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62616 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62617 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62618 +
62619 #endif /* _ASM_GENERIC_ATOMIC64_H */
62620 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62621 index 1bfcfe5..e04c5c9 100644
62622 --- a/include/asm-generic/cache.h
62623 +++ b/include/asm-generic/cache.h
62624 @@ -6,7 +6,7 @@
62625 * cache lines need to provide their own cache.h.
62626 */
62627
62628 -#define L1_CACHE_SHIFT 5
62629 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62630 +#define L1_CACHE_SHIFT 5UL
62631 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62632
62633 #endif /* __ASM_GENERIC_CACHE_H */
62634 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62635 index 0d68a1e..b74a761 100644
62636 --- a/include/asm-generic/emergency-restart.h
62637 +++ b/include/asm-generic/emergency-restart.h
62638 @@ -1,7 +1,7 @@
62639 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62640 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62641
62642 -static inline void machine_emergency_restart(void)
62643 +static inline __noreturn void machine_emergency_restart(void)
62644 {
62645 machine_restart(NULL);
62646 }
62647 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62648 index 90f99c7..00ce236 100644
62649 --- a/include/asm-generic/kmap_types.h
62650 +++ b/include/asm-generic/kmap_types.h
62651 @@ -2,9 +2,9 @@
62652 #define _ASM_GENERIC_KMAP_TYPES_H
62653
62654 #ifdef __WITH_KM_FENCE
62655 -# define KM_TYPE_NR 41
62656 +# define KM_TYPE_NR 42
62657 #else
62658 -# define KM_TYPE_NR 20
62659 +# define KM_TYPE_NR 21
62660 #endif
62661
62662 #endif
62663 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62664 index 9ceb03b..62b0b8f 100644
62665 --- a/include/asm-generic/local.h
62666 +++ b/include/asm-generic/local.h
62667 @@ -23,24 +23,37 @@ typedef struct
62668 atomic_long_t a;
62669 } local_t;
62670
62671 +typedef struct {
62672 + atomic_long_unchecked_t a;
62673 +} local_unchecked_t;
62674 +
62675 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62676
62677 #define local_read(l) atomic_long_read(&(l)->a)
62678 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62679 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62680 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62681 #define local_inc(l) atomic_long_inc(&(l)->a)
62682 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62683 #define local_dec(l) atomic_long_dec(&(l)->a)
62684 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62685 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62686 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62687 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62688 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62689
62690 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62691 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62692 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62693 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62694 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62695 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62696 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62697 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62698 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62699
62700 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62701 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62702 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62703 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62704 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62705 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62706 index 725612b..9cc513a 100644
62707 --- a/include/asm-generic/pgtable-nopmd.h
62708 +++ b/include/asm-generic/pgtable-nopmd.h
62709 @@ -1,14 +1,19 @@
62710 #ifndef _PGTABLE_NOPMD_H
62711 #define _PGTABLE_NOPMD_H
62712
62713 -#ifndef __ASSEMBLY__
62714 -
62715 #include <asm-generic/pgtable-nopud.h>
62716
62717 -struct mm_struct;
62718 -
62719 #define __PAGETABLE_PMD_FOLDED
62720
62721 +#define PMD_SHIFT PUD_SHIFT
62722 +#define PTRS_PER_PMD 1
62723 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62724 +#define PMD_MASK (~(PMD_SIZE-1))
62725 +
62726 +#ifndef __ASSEMBLY__
62727 +
62728 +struct mm_struct;
62729 +
62730 /*
62731 * Having the pmd type consist of a pud gets the size right, and allows
62732 * us to conceptually access the pud entry that this pmd is folded into
62733 @@ -16,11 +21,6 @@ struct mm_struct;
62734 */
62735 typedef struct { pud_t pud; } pmd_t;
62736
62737 -#define PMD_SHIFT PUD_SHIFT
62738 -#define PTRS_PER_PMD 1
62739 -#define PMD_SIZE (1UL << PMD_SHIFT)
62740 -#define PMD_MASK (~(PMD_SIZE-1))
62741 -
62742 /*
62743 * The "pud_xxx()" functions here are trivial for a folded two-level
62744 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62745 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62746 index 810431d..0ec4804f 100644
62747 --- a/include/asm-generic/pgtable-nopud.h
62748 +++ b/include/asm-generic/pgtable-nopud.h
62749 @@ -1,10 +1,15 @@
62750 #ifndef _PGTABLE_NOPUD_H
62751 #define _PGTABLE_NOPUD_H
62752
62753 -#ifndef __ASSEMBLY__
62754 -
62755 #define __PAGETABLE_PUD_FOLDED
62756
62757 +#define PUD_SHIFT PGDIR_SHIFT
62758 +#define PTRS_PER_PUD 1
62759 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62760 +#define PUD_MASK (~(PUD_SIZE-1))
62761 +
62762 +#ifndef __ASSEMBLY__
62763 +
62764 /*
62765 * Having the pud type consist of a pgd gets the size right, and allows
62766 * us to conceptually access the pgd entry that this pud is folded into
62767 @@ -12,11 +17,6 @@
62768 */
62769 typedef struct { pgd_t pgd; } pud_t;
62770
62771 -#define PUD_SHIFT PGDIR_SHIFT
62772 -#define PTRS_PER_PUD 1
62773 -#define PUD_SIZE (1UL << PUD_SHIFT)
62774 -#define PUD_MASK (~(PUD_SIZE-1))
62775 -
62776 /*
62777 * The "pgd_xxx()" functions here are trivial for a folded two-level
62778 * setup: the pud is never bad, and a pud always exists (as it's folded
62779 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62780 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62781
62782 #define pgd_populate(mm, pgd, pud) do { } while (0)
62783 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62784 /*
62785 * (puds are folded into pgds so this doesn't get actually called,
62786 * but the define is needed for a generic inline function.)
62787 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62788 index b36ce40..019426d 100644
62789 --- a/include/asm-generic/pgtable.h
62790 +++ b/include/asm-generic/pgtable.h
62791 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62792 #endif
62793 }
62794
62795 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62796 +static inline unsigned long pax_open_kernel(void) { return 0; }
62797 +#endif
62798 +
62799 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62800 +static inline unsigned long pax_close_kernel(void) { return 0; }
62801 +#endif
62802 +
62803 #endif /* CONFIG_MMU */
62804
62805 #endif /* !__ASSEMBLY__ */
62806 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62807 index d1ea7ce..b1ebf2a 100644
62808 --- a/include/asm-generic/vmlinux.lds.h
62809 +++ b/include/asm-generic/vmlinux.lds.h
62810 @@ -218,6 +218,7 @@
62811 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62812 VMLINUX_SYMBOL(__start_rodata) = .; \
62813 *(.rodata) *(.rodata.*) \
62814 + *(.data..read_only) \
62815 *(__vermagic) /* Kernel version magic */ \
62816 . = ALIGN(8); \
62817 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62818 @@ -725,17 +726,18 @@
62819 * section in the linker script will go there too. @phdr should have
62820 * a leading colon.
62821 *
62822 - * Note that this macros defines __per_cpu_load as an absolute symbol.
62823 + * Note that this macros defines per_cpu_load as an absolute symbol.
62824 * If there is no need to put the percpu section at a predetermined
62825 * address, use PERCPU_SECTION.
62826 */
62827 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62828 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
62829 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62830 + per_cpu_load = .; \
62831 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62832 - LOAD_OFFSET) { \
62833 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62834 PERCPU_INPUT(cacheline) \
62835 } phdr \
62836 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62837 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62838
62839 /**
62840 * PERCPU_SECTION - define output section for percpu area, simple version
62841 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62842 index 418d270..bfd2794 100644
62843 --- a/include/crypto/algapi.h
62844 +++ b/include/crypto/algapi.h
62845 @@ -34,7 +34,7 @@ struct crypto_type {
62846 unsigned int maskclear;
62847 unsigned int maskset;
62848 unsigned int tfmsize;
62849 -};
62850 +} __do_const;
62851
62852 struct crypto_instance {
62853 struct crypto_alg alg;
62854 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62855 index 3fd8280..2b3c415 100644
62856 --- a/include/drm/drmP.h
62857 +++ b/include/drm/drmP.h
62858 @@ -72,6 +72,7 @@
62859 #include <linux/workqueue.h>
62860 #include <linux/poll.h>
62861 #include <asm/pgalloc.h>
62862 +#include <asm/local.h>
62863 #include <drm/drm.h>
62864 #include <drm/drm_sarea.h>
62865
62866 @@ -1068,7 +1069,7 @@ struct drm_device {
62867
62868 /** \name Usage Counters */
62869 /*@{ */
62870 - int open_count; /**< Outstanding files open */
62871 + local_t open_count; /**< Outstanding files open */
62872 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62873 atomic_t vma_count; /**< Outstanding vma areas open */
62874 int buf_use; /**< Buffers in use -- cannot alloc */
62875 @@ -1079,7 +1080,7 @@ struct drm_device {
62876 /*@{ */
62877 unsigned long counters;
62878 enum drm_stat_type types[15];
62879 - atomic_t counts[15];
62880 + atomic_unchecked_t counts[15];
62881 /*@} */
62882
62883 struct list_head filelist;
62884 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62885 index e01cc80..6fb6f25 100644
62886 --- a/include/drm/drm_crtc_helper.h
62887 +++ b/include/drm/drm_crtc_helper.h
62888 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
62889 struct drm_connector *connector);
62890 /* disable encoder when not in use - more explicit than dpms off */
62891 void (*disable)(struct drm_encoder *encoder);
62892 -};
62893 +} __no_const;
62894
62895 /**
62896 * drm_connector_helper_funcs - helper operations for connectors
62897 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
62898 index d6d1da4..fdd1ac5 100644
62899 --- a/include/drm/ttm/ttm_memory.h
62900 +++ b/include/drm/ttm/ttm_memory.h
62901 @@ -48,7 +48,7 @@
62902
62903 struct ttm_mem_shrink {
62904 int (*do_shrink) (struct ttm_mem_shrink *);
62905 -};
62906 +} __no_const;
62907
62908 /**
62909 * struct ttm_mem_global - Global memory accounting structure.
62910 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
62911 index 22ef21c..75904ba 100644
62912 --- a/include/linux/atmdev.h
62913 +++ b/include/linux/atmdev.h
62914 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
62915 #endif
62916
62917 struct k_atm_aal_stats {
62918 -#define __HANDLE_ITEM(i) atomic_t i
62919 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62920 __AAL_STAT_ITEMS
62921 #undef __HANDLE_ITEM
62922 };
62923 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
62924 index de0628e..38f42eb 100644
62925 --- a/include/linux/binfmts.h
62926 +++ b/include/linux/binfmts.h
62927 @@ -75,6 +75,7 @@ struct linux_binfmt {
62928 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
62929 int (*load_shlib)(struct file *);
62930 int (*core_dump)(struct coredump_params *cprm);
62931 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
62932 unsigned long min_coredump; /* minimal dump size */
62933 };
62934
62935 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
62936 index 1756001..ab117ec 100644
62937 --- a/include/linux/blkdev.h
62938 +++ b/include/linux/blkdev.h
62939 @@ -1478,7 +1478,7 @@ struct block_device_operations {
62940 /* this callback is with swap_lock and sometimes page table lock held */
62941 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
62942 struct module *owner;
62943 -};
62944 +} __do_const;
62945
62946 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
62947 unsigned long);
62948 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
62949 index 7c2e030..b72475d 100644
62950 --- a/include/linux/blktrace_api.h
62951 +++ b/include/linux/blktrace_api.h
62952 @@ -23,7 +23,7 @@ struct blk_trace {
62953 struct dentry *dir;
62954 struct dentry *dropped_file;
62955 struct dentry *msg_file;
62956 - atomic_t dropped;
62957 + atomic_unchecked_t dropped;
62958 };
62959
62960 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
62961 diff --git a/include/linux/cache.h b/include/linux/cache.h
62962 index 4c57065..4307975 100644
62963 --- a/include/linux/cache.h
62964 +++ b/include/linux/cache.h
62965 @@ -16,6 +16,10 @@
62966 #define __read_mostly
62967 #endif
62968
62969 +#ifndef __read_only
62970 +#define __read_only __read_mostly
62971 +#endif
62972 +
62973 #ifndef ____cacheline_aligned
62974 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
62975 #endif
62976 diff --git a/include/linux/capability.h b/include/linux/capability.h
62977 index 98503b7..cc36d18 100644
62978 --- a/include/linux/capability.h
62979 +++ b/include/linux/capability.h
62980 @@ -211,8 +211,13 @@ extern bool capable(int cap);
62981 extern bool ns_capable(struct user_namespace *ns, int cap);
62982 extern bool nsown_capable(int cap);
62983 extern bool inode_capable(const struct inode *inode, int cap);
62984 +extern bool capable_nolog(int cap);
62985 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
62986 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
62987
62988 /* audit system wants to get cap info from files as well */
62989 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
62990
62991 +extern int is_privileged_binary(const struct dentry *dentry);
62992 +
62993 #endif /* !_LINUX_CAPABILITY_H */
62994 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
62995 index 8609d57..86e4d79 100644
62996 --- a/include/linux/cdrom.h
62997 +++ b/include/linux/cdrom.h
62998 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
62999
63000 /* driver specifications */
63001 const int capability; /* capability flags */
63002 - int n_minors; /* number of active minor devices */
63003 /* handle uniform packets for scsi type devices (scsi,atapi) */
63004 int (*generic_packet) (struct cdrom_device_info *,
63005 struct packet_command *);
63006 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63007 index 42e55de..1cd0e66 100644
63008 --- a/include/linux/cleancache.h
63009 +++ b/include/linux/cleancache.h
63010 @@ -31,7 +31,7 @@ struct cleancache_ops {
63011 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63012 void (*invalidate_inode)(int, struct cleancache_filekey);
63013 void (*invalidate_fs)(int);
63014 -};
63015 +} __no_const;
63016
63017 extern struct cleancache_ops
63018 cleancache_register_ops(struct cleancache_ops *ops);
63019 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63020 index 412bc6c..c31666e 100644
63021 --- a/include/linux/compiler-gcc4.h
63022 +++ b/include/linux/compiler-gcc4.h
63023 @@ -32,6 +32,21 @@
63024 #define __linktime_error(message) __attribute__((__error__(message)))
63025
63026 #if __GNUC_MINOR__ >= 5
63027 +
63028 +#ifdef CONSTIFY_PLUGIN
63029 +#define __no_const __attribute__((no_const))
63030 +#define __do_const __attribute__((do_const))
63031 +#endif
63032 +
63033 +#ifdef SIZE_OVERFLOW_PLUGIN
63034 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63035 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63036 +#endif
63037 +
63038 +#ifdef LATENT_ENTROPY_PLUGIN
63039 +#define __latent_entropy __attribute__((latent_entropy))
63040 +#endif
63041 +
63042 /*
63043 * Mark a position in code as unreachable. This can be used to
63044 * suppress control flow warnings after asm blocks that transfer
63045 @@ -47,6 +62,11 @@
63046 #define __noclone __attribute__((__noclone__))
63047
63048 #endif
63049 +
63050 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63051 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63052 +#define __bos0(ptr) __bos((ptr), 0)
63053 +#define __bos1(ptr) __bos((ptr), 1)
63054 #endif
63055
63056 #if __GNUC_MINOR__ >= 6
63057 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63058 index f430e41..38be90f 100644
63059 --- a/include/linux/compiler.h
63060 +++ b/include/linux/compiler.h
63061 @@ -5,31 +5,62 @@
63062
63063 #ifdef __CHECKER__
63064 # define __user __attribute__((noderef, address_space(1)))
63065 +# define __force_user __force __user
63066 # define __kernel __attribute__((address_space(0)))
63067 +# define __force_kernel __force __kernel
63068 # define __safe __attribute__((safe))
63069 # define __force __attribute__((force))
63070 # define __nocast __attribute__((nocast))
63071 # define __iomem __attribute__((noderef, address_space(2)))
63072 +# define __force_iomem __force __iomem
63073 # define __acquires(x) __attribute__((context(x,0,1)))
63074 # define __releases(x) __attribute__((context(x,1,0)))
63075 # define __acquire(x) __context__(x,1)
63076 # define __release(x) __context__(x,-1)
63077 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63078 # define __percpu __attribute__((noderef, address_space(3)))
63079 +# define __force_percpu __force __percpu
63080 #ifdef CONFIG_SPARSE_RCU_POINTER
63081 # define __rcu __attribute__((noderef, address_space(4)))
63082 +# define __force_rcu __force __rcu
63083 #else
63084 # define __rcu
63085 +# define __force_rcu
63086 #endif
63087 extern void __chk_user_ptr(const volatile void __user *);
63088 extern void __chk_io_ptr(const volatile void __iomem *);
63089 +#elif defined(CHECKER_PLUGIN)
63090 +//# define __user
63091 +//# define __force_user
63092 +//# define __kernel
63093 +//# define __force_kernel
63094 +# define __safe
63095 +# define __force
63096 +# define __nocast
63097 +# define __iomem
63098 +# define __force_iomem
63099 +# define __chk_user_ptr(x) (void)0
63100 +# define __chk_io_ptr(x) (void)0
63101 +# define __builtin_warning(x, y...) (1)
63102 +# define __acquires(x)
63103 +# define __releases(x)
63104 +# define __acquire(x) (void)0
63105 +# define __release(x) (void)0
63106 +# define __cond_lock(x,c) (c)
63107 +# define __percpu
63108 +# define __force_percpu
63109 +# define __rcu
63110 +# define __force_rcu
63111 #else
63112 # define __user
63113 +# define __force_user
63114 # define __kernel
63115 +# define __force_kernel
63116 # define __safe
63117 # define __force
63118 # define __nocast
63119 # define __iomem
63120 +# define __force_iomem
63121 # define __chk_user_ptr(x) (void)0
63122 # define __chk_io_ptr(x) (void)0
63123 # define __builtin_warning(x, y...) (1)
63124 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63125 # define __release(x) (void)0
63126 # define __cond_lock(x,c) (c)
63127 # define __percpu
63128 +# define __force_percpu
63129 # define __rcu
63130 +# define __force_rcu
63131 #endif
63132
63133 #ifdef __KERNEL__
63134 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63135 # define __attribute_const__ /* unimplemented */
63136 #endif
63137
63138 +#ifndef __no_const
63139 +# define __no_const
63140 +#endif
63141 +
63142 +#ifndef __do_const
63143 +# define __do_const
63144 +#endif
63145 +
63146 +#ifndef __size_overflow
63147 +# define __size_overflow(...)
63148 +#endif
63149 +
63150 +#ifndef __intentional_overflow
63151 +# define __intentional_overflow(...)
63152 +#endif
63153 +
63154 +#ifndef __latent_entropy
63155 +# define __latent_entropy
63156 +#endif
63157 +
63158 /*
63159 * Tell gcc if a function is cold. The compiler will assume any path
63160 * directly leading to the call is unlikely.
63161 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63162 #define __cold
63163 #endif
63164
63165 +#ifndef __alloc_size
63166 +#define __alloc_size(...)
63167 +#endif
63168 +
63169 +#ifndef __bos
63170 +#define __bos(ptr, arg)
63171 +#endif
63172 +
63173 +#ifndef __bos0
63174 +#define __bos0(ptr)
63175 +#endif
63176 +
63177 +#ifndef __bos1
63178 +#define __bos1(ptr)
63179 +#endif
63180 +
63181 /* Simple shorthand for a section definition */
63182 #ifndef __section
63183 # define __section(S) __attribute__ ((__section__(#S)))
63184 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63185 * use is to mediate communication between process-level code and irq/NMI
63186 * handlers, all running on the same CPU.
63187 */
63188 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63189 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63190 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63191
63192 #endif /* __LINUX_COMPILER_H */
63193 diff --git a/include/linux/cred.h b/include/linux/cred.h
63194 index ebbed2c..908cc2c 100644
63195 --- a/include/linux/cred.h
63196 +++ b/include/linux/cred.h
63197 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63198 static inline void validate_process_creds(void)
63199 {
63200 }
63201 +static inline void validate_task_creds(struct task_struct *task)
63202 +{
63203 +}
63204 #endif
63205
63206 /**
63207 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63208 index b92eadf..b4ecdc1 100644
63209 --- a/include/linux/crypto.h
63210 +++ b/include/linux/crypto.h
63211 @@ -373,7 +373,7 @@ struct cipher_tfm {
63212 const u8 *key, unsigned int keylen);
63213 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63214 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63215 -};
63216 +} __no_const;
63217
63218 struct hash_tfm {
63219 int (*init)(struct hash_desc *desc);
63220 @@ -394,13 +394,13 @@ struct compress_tfm {
63221 int (*cot_decompress)(struct crypto_tfm *tfm,
63222 const u8 *src, unsigned int slen,
63223 u8 *dst, unsigned int *dlen);
63224 -};
63225 +} __no_const;
63226
63227 struct rng_tfm {
63228 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63229 unsigned int dlen);
63230 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63231 -};
63232 +} __no_const;
63233
63234 #define crt_ablkcipher crt_u.ablkcipher
63235 #define crt_aead crt_u.aead
63236 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63237 index 7925bf0..d5143d2 100644
63238 --- a/include/linux/decompress/mm.h
63239 +++ b/include/linux/decompress/mm.h
63240 @@ -77,7 +77,7 @@ static void free(void *where)
63241 * warnings when not needed (indeed large_malloc / large_free are not
63242 * needed by inflate */
63243
63244 -#define malloc(a) kmalloc(a, GFP_KERNEL)
63245 +#define malloc(a) kmalloc((a), GFP_KERNEL)
63246 #define free(a) kfree(a)
63247
63248 #define large_malloc(a) vmalloc(a)
63249 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63250 index 94af418..b1ca7a2 100644
63251 --- a/include/linux/dma-mapping.h
63252 +++ b/include/linux/dma-mapping.h
63253 @@ -54,7 +54,7 @@ struct dma_map_ops {
63254 u64 (*get_required_mask)(struct device *dev);
63255 #endif
63256 int is_phys;
63257 -};
63258 +} __do_const;
63259
63260 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63261
63262 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63263 index d3201e4..8281e63 100644
63264 --- a/include/linux/dmaengine.h
63265 +++ b/include/linux/dmaengine.h
63266 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63267 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63268 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63269
63270 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63271 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63272 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63273 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63274 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63275 struct dma_pinned_list *pinned_list, struct page *page,
63276 unsigned int offset, size_t len);
63277
63278 diff --git a/include/linux/efi.h b/include/linux/efi.h
63279 index b424f64..fd36c1b 100644
63280 --- a/include/linux/efi.h
63281 +++ b/include/linux/efi.h
63282 @@ -656,6 +656,7 @@ struct efivar_operations {
63283 efi_get_next_variable_t *get_next_variable;
63284 efi_set_variable_t *set_variable;
63285 };
63286 +typedef struct efivar_operations __no_const efivar_operations_no_const;
63287
63288 struct efivars {
63289 /*
63290 diff --git a/include/linux/elf.h b/include/linux/elf.h
63291 index 8c9048e..16a4665 100644
63292 --- a/include/linux/elf.h
63293 +++ b/include/linux/elf.h
63294 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63295 #define elf_note elf32_note
63296 #define elf_addr_t Elf32_Off
63297 #define Elf_Half Elf32_Half
63298 +#define elf_dyn Elf32_Dyn
63299
63300 #else
63301
63302 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63303 #define elf_note elf64_note
63304 #define elf_addr_t Elf64_Off
63305 #define Elf_Half Elf64_Half
63306 +#define elf_dyn Elf64_Dyn
63307
63308 #endif
63309
63310 diff --git a/include/linux/filter.h b/include/linux/filter.h
63311 index 24d251f..7afb83d 100644
63312 --- a/include/linux/filter.h
63313 +++ b/include/linux/filter.h
63314 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
63315
63316 struct sk_buff;
63317 struct sock;
63318 +struct bpf_jit_work;
63319
63320 struct sk_filter
63321 {
63322 @@ -27,6 +28,9 @@ struct sk_filter
63323 unsigned int len; /* Number of filter blocks */
63324 unsigned int (*bpf_func)(const struct sk_buff *skb,
63325 const struct sock_filter *filter);
63326 +#ifdef CONFIG_BPF_JIT
63327 + struct bpf_jit_work *work;
63328 +#endif
63329 struct rcu_head rcu;
63330 struct sock_filter insns[0];
63331 };
63332 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63333 index 3044254..9767f41 100644
63334 --- a/include/linux/frontswap.h
63335 +++ b/include/linux/frontswap.h
63336 @@ -11,7 +11,7 @@ struct frontswap_ops {
63337 int (*load)(unsigned, pgoff_t, struct page *);
63338 void (*invalidate_page)(unsigned, pgoff_t);
63339 void (*invalidate_area)(unsigned);
63340 -};
63341 +} __no_const;
63342
63343 extern bool frontswap_enabled;
63344 extern struct frontswap_ops
63345 diff --git a/include/linux/fs.h b/include/linux/fs.h
63346 index 75fe9a1..8417cac 100644
63347 --- a/include/linux/fs.h
63348 +++ b/include/linux/fs.h
63349 @@ -1543,7 +1543,8 @@ struct file_operations {
63350 int (*setlease)(struct file *, long, struct file_lock **);
63351 long (*fallocate)(struct file *file, int mode, loff_t offset,
63352 loff_t len);
63353 -};
63354 +} __do_const;
63355 +typedef struct file_operations __no_const file_operations_no_const;
63356
63357 struct inode_operations {
63358 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63359 @@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63360 inode->i_flags |= S_NOSEC;
63361 }
63362
63363 +static inline bool is_sidechannel_device(const struct inode *inode)
63364 +{
63365 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63366 + umode_t mode = inode->i_mode;
63367 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63368 +#else
63369 + return false;
63370 +#endif
63371 +}
63372 +
63373 #endif /* _LINUX_FS_H */
63374 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63375 index 003dc0f..3c4ea97 100644
63376 --- a/include/linux/fs_struct.h
63377 +++ b/include/linux/fs_struct.h
63378 @@ -6,7 +6,7 @@
63379 #include <linux/seqlock.h>
63380
63381 struct fs_struct {
63382 - int users;
63383 + atomic_t users;
63384 spinlock_t lock;
63385 seqcount_t seq;
63386 int umask;
63387 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63388 index ce31408..b1ad003 100644
63389 --- a/include/linux/fscache-cache.h
63390 +++ b/include/linux/fscache-cache.h
63391 @@ -102,7 +102,7 @@ struct fscache_operation {
63392 fscache_operation_release_t release;
63393 };
63394
63395 -extern atomic_t fscache_op_debug_id;
63396 +extern atomic_unchecked_t fscache_op_debug_id;
63397 extern void fscache_op_work_func(struct work_struct *work);
63398
63399 extern void fscache_enqueue_operation(struct fscache_operation *);
63400 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63401 {
63402 INIT_WORK(&op->work, fscache_op_work_func);
63403 atomic_set(&op->usage, 1);
63404 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63405 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63406 op->processor = processor;
63407 op->release = release;
63408 INIT_LIST_HEAD(&op->pend_link);
63409 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63410 index 0fbfb46..508eb0d 100644
63411 --- a/include/linux/fsnotify.h
63412 +++ b/include/linux/fsnotify.h
63413 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63414 struct inode *inode = path->dentry->d_inode;
63415 __u32 mask = FS_ACCESS;
63416
63417 + if (is_sidechannel_device(inode))
63418 + return;
63419 +
63420 if (S_ISDIR(inode->i_mode))
63421 mask |= FS_ISDIR;
63422
63423 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63424 struct inode *inode = path->dentry->d_inode;
63425 __u32 mask = FS_MODIFY;
63426
63427 + if (is_sidechannel_device(inode))
63428 + return;
63429 +
63430 if (S_ISDIR(inode->i_mode))
63431 mask |= FS_ISDIR;
63432
63433 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63434 */
63435 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63436 {
63437 - return kstrdup(name, GFP_KERNEL);
63438 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63439 }
63440
63441 /*
63442 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63443 index 642928c..93afe6a 100644
63444 --- a/include/linux/ftrace_event.h
63445 +++ b/include/linux/ftrace_event.h
63446 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63447 extern int trace_add_event_call(struct ftrace_event_call *call);
63448 extern void trace_remove_event_call(struct ftrace_event_call *call);
63449
63450 -#define is_signed_type(type) (((type)(-1)) < 0)
63451 +#define is_signed_type(type) (((type)(-1)) < (type)1)
63452
63453 int trace_set_clr_event(const char *system, const char *event, int set);
63454
63455 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63456 index 4f440b3..342233a 100644
63457 --- a/include/linux/genhd.h
63458 +++ b/include/linux/genhd.h
63459 @@ -190,7 +190,7 @@ struct gendisk {
63460 struct kobject *slave_dir;
63461
63462 struct timer_rand_state *random;
63463 - atomic_t sync_io; /* RAID */
63464 + atomic_unchecked_t sync_io; /* RAID */
63465 struct disk_events *ev;
63466 #ifdef CONFIG_BLK_DEV_INTEGRITY
63467 struct blk_integrity *integrity;
63468 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63469 index d0a7967..63c4c47 100644
63470 --- a/include/linux/gfp.h
63471 +++ b/include/linux/gfp.h
63472 @@ -35,6 +35,12 @@ struct vm_area_struct;
63473 #define ___GFP_OTHER_NODE 0x800000u
63474 #define ___GFP_WRITE 0x1000000u
63475
63476 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63477 +#define ___GFP_USERCOPY 0x2000000u
63478 +#else
63479 +#define ___GFP_USERCOPY 0
63480 +#endif
63481 +
63482 /*
63483 * GFP bitmasks..
63484 *
63485 @@ -89,6 +95,7 @@ struct vm_area_struct;
63486 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63487 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63488 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63489 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63490
63491 /*
63492 * This may seem redundant, but it's a way of annotating false positives vs.
63493 @@ -96,7 +103,7 @@ struct vm_area_struct;
63494 */
63495 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63496
63497 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63498 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63499 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63500
63501 /* This equals 0, but use constants in case they ever change */
63502 @@ -150,6 +157,8 @@ struct vm_area_struct;
63503 /* 4GB DMA on some platforms */
63504 #define GFP_DMA32 __GFP_DMA32
63505
63506 +#define GFP_USERCOPY __GFP_USERCOPY
63507 +
63508 /* Convert GFP flags to their corresponding migrate type */
63509 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63510 {
63511 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63512 new file mode 100644
63513 index 0000000..ebe6d72
63514 --- /dev/null
63515 +++ b/include/linux/gracl.h
63516 @@ -0,0 +1,319 @@
63517 +#ifndef GR_ACL_H
63518 +#define GR_ACL_H
63519 +
63520 +#include <linux/grdefs.h>
63521 +#include <linux/resource.h>
63522 +#include <linux/capability.h>
63523 +#include <linux/dcache.h>
63524 +#include <asm/resource.h>
63525 +
63526 +/* Major status information */
63527 +
63528 +#define GR_VERSION "grsecurity 2.9.1"
63529 +#define GRSECURITY_VERSION 0x2901
63530 +
63531 +enum {
63532 + GR_SHUTDOWN = 0,
63533 + GR_ENABLE = 1,
63534 + GR_SPROLE = 2,
63535 + GR_RELOAD = 3,
63536 + GR_SEGVMOD = 4,
63537 + GR_STATUS = 5,
63538 + GR_UNSPROLE = 6,
63539 + GR_PASSSET = 7,
63540 + GR_SPROLEPAM = 8,
63541 +};
63542 +
63543 +/* Password setup definitions
63544 + * kernel/grhash.c */
63545 +enum {
63546 + GR_PW_LEN = 128,
63547 + GR_SALT_LEN = 16,
63548 + GR_SHA_LEN = 32,
63549 +};
63550 +
63551 +enum {
63552 + GR_SPROLE_LEN = 64,
63553 +};
63554 +
63555 +enum {
63556 + GR_NO_GLOB = 0,
63557 + GR_REG_GLOB,
63558 + GR_CREATE_GLOB
63559 +};
63560 +
63561 +#define GR_NLIMITS 32
63562 +
63563 +/* Begin Data Structures */
63564 +
63565 +struct sprole_pw {
63566 + unsigned char *rolename;
63567 + unsigned char salt[GR_SALT_LEN];
63568 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63569 +};
63570 +
63571 +struct name_entry {
63572 + __u32 key;
63573 + ino_t inode;
63574 + dev_t device;
63575 + char *name;
63576 + __u16 len;
63577 + __u8 deleted;
63578 + struct name_entry *prev;
63579 + struct name_entry *next;
63580 +};
63581 +
63582 +struct inodev_entry {
63583 + struct name_entry *nentry;
63584 + struct inodev_entry *prev;
63585 + struct inodev_entry *next;
63586 +};
63587 +
63588 +struct acl_role_db {
63589 + struct acl_role_label **r_hash;
63590 + __u32 r_size;
63591 +};
63592 +
63593 +struct inodev_db {
63594 + struct inodev_entry **i_hash;
63595 + __u32 i_size;
63596 +};
63597 +
63598 +struct name_db {
63599 + struct name_entry **n_hash;
63600 + __u32 n_size;
63601 +};
63602 +
63603 +struct crash_uid {
63604 + uid_t uid;
63605 + unsigned long expires;
63606 +};
63607 +
63608 +struct gr_hash_struct {
63609 + void **table;
63610 + void **nametable;
63611 + void *first;
63612 + __u32 table_size;
63613 + __u32 used_size;
63614 + int type;
63615 +};
63616 +
63617 +/* Userspace Grsecurity ACL data structures */
63618 +
63619 +struct acl_subject_label {
63620 + char *filename;
63621 + ino_t inode;
63622 + dev_t device;
63623 + __u32 mode;
63624 + kernel_cap_t cap_mask;
63625 + kernel_cap_t cap_lower;
63626 + kernel_cap_t cap_invert_audit;
63627 +
63628 + struct rlimit res[GR_NLIMITS];
63629 + __u32 resmask;
63630 +
63631 + __u8 user_trans_type;
63632 + __u8 group_trans_type;
63633 + uid_t *user_transitions;
63634 + gid_t *group_transitions;
63635 + __u16 user_trans_num;
63636 + __u16 group_trans_num;
63637 +
63638 + __u32 sock_families[2];
63639 + __u32 ip_proto[8];
63640 + __u32 ip_type;
63641 + struct acl_ip_label **ips;
63642 + __u32 ip_num;
63643 + __u32 inaddr_any_override;
63644 +
63645 + __u32 crashes;
63646 + unsigned long expires;
63647 +
63648 + struct acl_subject_label *parent_subject;
63649 + struct gr_hash_struct *hash;
63650 + struct acl_subject_label *prev;
63651 + struct acl_subject_label *next;
63652 +
63653 + struct acl_object_label **obj_hash;
63654 + __u32 obj_hash_size;
63655 + __u16 pax_flags;
63656 +};
63657 +
63658 +struct role_allowed_ip {
63659 + __u32 addr;
63660 + __u32 netmask;
63661 +
63662 + struct role_allowed_ip *prev;
63663 + struct role_allowed_ip *next;
63664 +};
63665 +
63666 +struct role_transition {
63667 + char *rolename;
63668 +
63669 + struct role_transition *prev;
63670 + struct role_transition *next;
63671 +};
63672 +
63673 +struct acl_role_label {
63674 + char *rolename;
63675 + uid_t uidgid;
63676 + __u16 roletype;
63677 +
63678 + __u16 auth_attempts;
63679 + unsigned long expires;
63680 +
63681 + struct acl_subject_label *root_label;
63682 + struct gr_hash_struct *hash;
63683 +
63684 + struct acl_role_label *prev;
63685 + struct acl_role_label *next;
63686 +
63687 + struct role_transition *transitions;
63688 + struct role_allowed_ip *allowed_ips;
63689 + uid_t *domain_children;
63690 + __u16 domain_child_num;
63691 +
63692 + umode_t umask;
63693 +
63694 + struct acl_subject_label **subj_hash;
63695 + __u32 subj_hash_size;
63696 +};
63697 +
63698 +struct user_acl_role_db {
63699 + struct acl_role_label **r_table;
63700 + __u32 num_pointers; /* Number of allocations to track */
63701 + __u32 num_roles; /* Number of roles */
63702 + __u32 num_domain_children; /* Number of domain children */
63703 + __u32 num_subjects; /* Number of subjects */
63704 + __u32 num_objects; /* Number of objects */
63705 +};
63706 +
63707 +struct acl_object_label {
63708 + char *filename;
63709 + ino_t inode;
63710 + dev_t device;
63711 + __u32 mode;
63712 +
63713 + struct acl_subject_label *nested;
63714 + struct acl_object_label *globbed;
63715 +
63716 + /* next two structures not used */
63717 +
63718 + struct acl_object_label *prev;
63719 + struct acl_object_label *next;
63720 +};
63721 +
63722 +struct acl_ip_label {
63723 + char *iface;
63724 + __u32 addr;
63725 + __u32 netmask;
63726 + __u16 low, high;
63727 + __u8 mode;
63728 + __u32 type;
63729 + __u32 proto[8];
63730 +
63731 + /* next two structures not used */
63732 +
63733 + struct acl_ip_label *prev;
63734 + struct acl_ip_label *next;
63735 +};
63736 +
63737 +struct gr_arg {
63738 + struct user_acl_role_db role_db;
63739 + unsigned char pw[GR_PW_LEN];
63740 + unsigned char salt[GR_SALT_LEN];
63741 + unsigned char sum[GR_SHA_LEN];
63742 + unsigned char sp_role[GR_SPROLE_LEN];
63743 + struct sprole_pw *sprole_pws;
63744 + dev_t segv_device;
63745 + ino_t segv_inode;
63746 + uid_t segv_uid;
63747 + __u16 num_sprole_pws;
63748 + __u16 mode;
63749 +};
63750 +
63751 +struct gr_arg_wrapper {
63752 + struct gr_arg *arg;
63753 + __u32 version;
63754 + __u32 size;
63755 +};
63756 +
63757 +struct subject_map {
63758 + struct acl_subject_label *user;
63759 + struct acl_subject_label *kernel;
63760 + struct subject_map *prev;
63761 + struct subject_map *next;
63762 +};
63763 +
63764 +struct acl_subj_map_db {
63765 + struct subject_map **s_hash;
63766 + __u32 s_size;
63767 +};
63768 +
63769 +/* End Data Structures Section */
63770 +
63771 +/* Hash functions generated by empirical testing by Brad Spengler
63772 + Makes good use of the low bits of the inode. Generally 0-1 times
63773 + in loop for successful match. 0-3 for unsuccessful match.
63774 + Shift/add algorithm with modulus of table size and an XOR*/
63775 +
63776 +static __inline__ unsigned int
63777 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63778 +{
63779 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
63780 +}
63781 +
63782 + static __inline__ unsigned int
63783 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63784 +{
63785 + return ((const unsigned long)userp % sz);
63786 +}
63787 +
63788 +static __inline__ unsigned int
63789 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63790 +{
63791 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63792 +}
63793 +
63794 +static __inline__ unsigned int
63795 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63796 +{
63797 + return full_name_hash((const unsigned char *)name, len) % sz;
63798 +}
63799 +
63800 +#define FOR_EACH_ROLE_START(role) \
63801 + role = role_list; \
63802 + while (role) {
63803 +
63804 +#define FOR_EACH_ROLE_END(role) \
63805 + role = role->prev; \
63806 + }
63807 +
63808 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63809 + subj = NULL; \
63810 + iter = 0; \
63811 + while (iter < role->subj_hash_size) { \
63812 + if (subj == NULL) \
63813 + subj = role->subj_hash[iter]; \
63814 + if (subj == NULL) { \
63815 + iter++; \
63816 + continue; \
63817 + }
63818 +
63819 +#define FOR_EACH_SUBJECT_END(subj,iter) \
63820 + subj = subj->next; \
63821 + if (subj == NULL) \
63822 + iter++; \
63823 + }
63824 +
63825 +
63826 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63827 + subj = role->hash->first; \
63828 + while (subj != NULL) {
63829 +
63830 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63831 + subj = subj->next; \
63832 + }
63833 +
63834 +#endif
63835 +
63836 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63837 new file mode 100644
63838 index 0000000..323ecf2
63839 --- /dev/null
63840 +++ b/include/linux/gralloc.h
63841 @@ -0,0 +1,9 @@
63842 +#ifndef __GRALLOC_H
63843 +#define __GRALLOC_H
63844 +
63845 +void acl_free_all(void);
63846 +int acl_alloc_stack_init(unsigned long size);
63847 +void *acl_alloc(unsigned long len);
63848 +void *acl_alloc_num(unsigned long num, unsigned long len);
63849 +
63850 +#endif
63851 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63852 new file mode 100644
63853 index 0000000..be66033
63854 --- /dev/null
63855 +++ b/include/linux/grdefs.h
63856 @@ -0,0 +1,140 @@
63857 +#ifndef GRDEFS_H
63858 +#define GRDEFS_H
63859 +
63860 +/* Begin grsecurity status declarations */
63861 +
63862 +enum {
63863 + GR_READY = 0x01,
63864 + GR_STATUS_INIT = 0x00 // disabled state
63865 +};
63866 +
63867 +/* Begin ACL declarations */
63868 +
63869 +/* Role flags */
63870 +
63871 +enum {
63872 + GR_ROLE_USER = 0x0001,
63873 + GR_ROLE_GROUP = 0x0002,
63874 + GR_ROLE_DEFAULT = 0x0004,
63875 + GR_ROLE_SPECIAL = 0x0008,
63876 + GR_ROLE_AUTH = 0x0010,
63877 + GR_ROLE_NOPW = 0x0020,
63878 + GR_ROLE_GOD = 0x0040,
63879 + GR_ROLE_LEARN = 0x0080,
63880 + GR_ROLE_TPE = 0x0100,
63881 + GR_ROLE_DOMAIN = 0x0200,
63882 + GR_ROLE_PAM = 0x0400,
63883 + GR_ROLE_PERSIST = 0x0800
63884 +};
63885 +
63886 +/* ACL Subject and Object mode flags */
63887 +enum {
63888 + GR_DELETED = 0x80000000
63889 +};
63890 +
63891 +/* ACL Object-only mode flags */
63892 +enum {
63893 + GR_READ = 0x00000001,
63894 + GR_APPEND = 0x00000002,
63895 + GR_WRITE = 0x00000004,
63896 + GR_EXEC = 0x00000008,
63897 + GR_FIND = 0x00000010,
63898 + GR_INHERIT = 0x00000020,
63899 + GR_SETID = 0x00000040,
63900 + GR_CREATE = 0x00000080,
63901 + GR_DELETE = 0x00000100,
63902 + GR_LINK = 0x00000200,
63903 + GR_AUDIT_READ = 0x00000400,
63904 + GR_AUDIT_APPEND = 0x00000800,
63905 + GR_AUDIT_WRITE = 0x00001000,
63906 + GR_AUDIT_EXEC = 0x00002000,
63907 + GR_AUDIT_FIND = 0x00004000,
63908 + GR_AUDIT_INHERIT= 0x00008000,
63909 + GR_AUDIT_SETID = 0x00010000,
63910 + GR_AUDIT_CREATE = 0x00020000,
63911 + GR_AUDIT_DELETE = 0x00040000,
63912 + GR_AUDIT_LINK = 0x00080000,
63913 + GR_PTRACERD = 0x00100000,
63914 + GR_NOPTRACE = 0x00200000,
63915 + GR_SUPPRESS = 0x00400000,
63916 + GR_NOLEARN = 0x00800000,
63917 + GR_INIT_TRANSFER= 0x01000000
63918 +};
63919 +
63920 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
63921 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
63922 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
63923 +
63924 +/* ACL subject-only mode flags */
63925 +enum {
63926 + GR_KILL = 0x00000001,
63927 + GR_VIEW = 0x00000002,
63928 + GR_PROTECTED = 0x00000004,
63929 + GR_LEARN = 0x00000008,
63930 + GR_OVERRIDE = 0x00000010,
63931 + /* just a placeholder, this mode is only used in userspace */
63932 + GR_DUMMY = 0x00000020,
63933 + GR_PROTSHM = 0x00000040,
63934 + GR_KILLPROC = 0x00000080,
63935 + GR_KILLIPPROC = 0x00000100,
63936 + /* just a placeholder, this mode is only used in userspace */
63937 + GR_NOTROJAN = 0x00000200,
63938 + GR_PROTPROCFD = 0x00000400,
63939 + GR_PROCACCT = 0x00000800,
63940 + GR_RELAXPTRACE = 0x00001000,
63941 + //GR_NESTED = 0x00002000,
63942 + GR_INHERITLEARN = 0x00004000,
63943 + GR_PROCFIND = 0x00008000,
63944 + GR_POVERRIDE = 0x00010000,
63945 + GR_KERNELAUTH = 0x00020000,
63946 + GR_ATSECURE = 0x00040000,
63947 + GR_SHMEXEC = 0x00080000
63948 +};
63949 +
63950 +enum {
63951 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
63952 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
63953 + GR_PAX_ENABLE_MPROTECT = 0x0004,
63954 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
63955 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
63956 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
63957 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
63958 + GR_PAX_DISABLE_MPROTECT = 0x0400,
63959 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
63960 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
63961 +};
63962 +
63963 +enum {
63964 + GR_ID_USER = 0x01,
63965 + GR_ID_GROUP = 0x02,
63966 +};
63967 +
63968 +enum {
63969 + GR_ID_ALLOW = 0x01,
63970 + GR_ID_DENY = 0x02,
63971 +};
63972 +
63973 +#define GR_CRASH_RES 31
63974 +#define GR_UIDTABLE_MAX 500
63975 +
63976 +/* begin resource learning section */
63977 +enum {
63978 + GR_RLIM_CPU_BUMP = 60,
63979 + GR_RLIM_FSIZE_BUMP = 50000,
63980 + GR_RLIM_DATA_BUMP = 10000,
63981 + GR_RLIM_STACK_BUMP = 1000,
63982 + GR_RLIM_CORE_BUMP = 10000,
63983 + GR_RLIM_RSS_BUMP = 500000,
63984 + GR_RLIM_NPROC_BUMP = 1,
63985 + GR_RLIM_NOFILE_BUMP = 5,
63986 + GR_RLIM_MEMLOCK_BUMP = 50000,
63987 + GR_RLIM_AS_BUMP = 500000,
63988 + GR_RLIM_LOCKS_BUMP = 2,
63989 + GR_RLIM_SIGPENDING_BUMP = 5,
63990 + GR_RLIM_MSGQUEUE_BUMP = 10000,
63991 + GR_RLIM_NICE_BUMP = 1,
63992 + GR_RLIM_RTPRIO_BUMP = 1,
63993 + GR_RLIM_RTTIME_BUMP = 1000000
63994 +};
63995 +
63996 +#endif
63997 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
63998 new file mode 100644
63999 index 0000000..baa6e96
64000 --- /dev/null
64001 +++ b/include/linux/grinternal.h
64002 @@ -0,0 +1,215 @@
64003 +#ifndef __GRINTERNAL_H
64004 +#define __GRINTERNAL_H
64005 +
64006 +#ifdef CONFIG_GRKERNSEC
64007 +
64008 +#include <linux/fs.h>
64009 +#include <linux/mnt_namespace.h>
64010 +#include <linux/nsproxy.h>
64011 +#include <linux/gracl.h>
64012 +#include <linux/grdefs.h>
64013 +#include <linux/grmsg.h>
64014 +
64015 +void gr_add_learn_entry(const char *fmt, ...)
64016 + __attribute__ ((format (printf, 1, 2)));
64017 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64018 + const struct vfsmount *mnt);
64019 +__u32 gr_check_create(const struct dentry *new_dentry,
64020 + const struct dentry *parent,
64021 + const struct vfsmount *mnt, const __u32 mode);
64022 +int gr_check_protected_task(const struct task_struct *task);
64023 +__u32 to_gr_audit(const __u32 reqmode);
64024 +int gr_set_acls(const int type);
64025 +int gr_apply_subject_to_task(struct task_struct *task);
64026 +int gr_acl_is_enabled(void);
64027 +char gr_roletype_to_char(void);
64028 +
64029 +void gr_handle_alertkill(struct task_struct *task);
64030 +char *gr_to_filename(const struct dentry *dentry,
64031 + const struct vfsmount *mnt);
64032 +char *gr_to_filename1(const struct dentry *dentry,
64033 + const struct vfsmount *mnt);
64034 +char *gr_to_filename2(const struct dentry *dentry,
64035 + const struct vfsmount *mnt);
64036 +char *gr_to_filename3(const struct dentry *dentry,
64037 + const struct vfsmount *mnt);
64038 +
64039 +extern int grsec_enable_ptrace_readexec;
64040 +extern int grsec_enable_harden_ptrace;
64041 +extern int grsec_enable_link;
64042 +extern int grsec_enable_fifo;
64043 +extern int grsec_enable_execve;
64044 +extern int grsec_enable_shm;
64045 +extern int grsec_enable_execlog;
64046 +extern int grsec_enable_signal;
64047 +extern int grsec_enable_audit_ptrace;
64048 +extern int grsec_enable_forkfail;
64049 +extern int grsec_enable_time;
64050 +extern int grsec_enable_rofs;
64051 +extern int grsec_enable_chroot_shmat;
64052 +extern int grsec_enable_chroot_mount;
64053 +extern int grsec_enable_chroot_double;
64054 +extern int grsec_enable_chroot_pivot;
64055 +extern int grsec_enable_chroot_chdir;
64056 +extern int grsec_enable_chroot_chmod;
64057 +extern int grsec_enable_chroot_mknod;
64058 +extern int grsec_enable_chroot_fchdir;
64059 +extern int grsec_enable_chroot_nice;
64060 +extern int grsec_enable_chroot_execlog;
64061 +extern int grsec_enable_chroot_caps;
64062 +extern int grsec_enable_chroot_sysctl;
64063 +extern int grsec_enable_chroot_unix;
64064 +extern int grsec_enable_symlinkown;
64065 +extern int grsec_symlinkown_gid;
64066 +extern int grsec_enable_tpe;
64067 +extern int grsec_tpe_gid;
64068 +extern int grsec_enable_tpe_all;
64069 +extern int grsec_enable_tpe_invert;
64070 +extern int grsec_enable_socket_all;
64071 +extern int grsec_socket_all_gid;
64072 +extern int grsec_enable_socket_client;
64073 +extern int grsec_socket_client_gid;
64074 +extern int grsec_enable_socket_server;
64075 +extern int grsec_socket_server_gid;
64076 +extern int grsec_audit_gid;
64077 +extern int grsec_enable_group;
64078 +extern int grsec_enable_audit_textrel;
64079 +extern int grsec_enable_log_rwxmaps;
64080 +extern int grsec_enable_mount;
64081 +extern int grsec_enable_chdir;
64082 +extern int grsec_resource_logging;
64083 +extern int grsec_enable_blackhole;
64084 +extern int grsec_lastack_retries;
64085 +extern int grsec_enable_brute;
64086 +extern int grsec_lock;
64087 +
64088 +extern spinlock_t grsec_alert_lock;
64089 +extern unsigned long grsec_alert_wtime;
64090 +extern unsigned long grsec_alert_fyet;
64091 +
64092 +extern spinlock_t grsec_audit_lock;
64093 +
64094 +extern rwlock_t grsec_exec_file_lock;
64095 +
64096 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64097 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64098 + (tsk)->exec_file->f_vfsmnt) : "/")
64099 +
64100 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64101 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64102 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64103 +
64104 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64105 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
64106 + (tsk)->exec_file->f_vfsmnt) : "/")
64107 +
64108 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64109 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64110 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64111 +
64112 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64113 +
64114 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64115 +
64116 +#define GR_CHROOT_CAPS {{ \
64117 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64118 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64119 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64120 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64121 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64122 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64123 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64124 +
64125 +#define security_learn(normal_msg,args...) \
64126 +({ \
64127 + read_lock(&grsec_exec_file_lock); \
64128 + gr_add_learn_entry(normal_msg "\n", ## args); \
64129 + read_unlock(&grsec_exec_file_lock); \
64130 +})
64131 +
64132 +enum {
64133 + GR_DO_AUDIT,
64134 + GR_DONT_AUDIT,
64135 + /* used for non-audit messages that we shouldn't kill the task on */
64136 + GR_DONT_AUDIT_GOOD
64137 +};
64138 +
64139 +enum {
64140 + GR_TTYSNIFF,
64141 + GR_RBAC,
64142 + GR_RBAC_STR,
64143 + GR_STR_RBAC,
64144 + GR_RBAC_MODE2,
64145 + GR_RBAC_MODE3,
64146 + GR_FILENAME,
64147 + GR_SYSCTL_HIDDEN,
64148 + GR_NOARGS,
64149 + GR_ONE_INT,
64150 + GR_ONE_INT_TWO_STR,
64151 + GR_ONE_STR,
64152 + GR_STR_INT,
64153 + GR_TWO_STR_INT,
64154 + GR_TWO_INT,
64155 + GR_TWO_U64,
64156 + GR_THREE_INT,
64157 + GR_FIVE_INT_TWO_STR,
64158 + GR_TWO_STR,
64159 + GR_THREE_STR,
64160 + GR_FOUR_STR,
64161 + GR_STR_FILENAME,
64162 + GR_FILENAME_STR,
64163 + GR_FILENAME_TWO_INT,
64164 + GR_FILENAME_TWO_INT_STR,
64165 + GR_TEXTREL,
64166 + GR_PTRACE,
64167 + GR_RESOURCE,
64168 + GR_CAP,
64169 + GR_SIG,
64170 + GR_SIG2,
64171 + GR_CRASH1,
64172 + GR_CRASH2,
64173 + GR_PSACCT,
64174 + GR_RWXMAP
64175 +};
64176 +
64177 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64178 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64179 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64180 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64181 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64182 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64183 +#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)
64184 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64185 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64186 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64187 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64188 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64189 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64190 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64191 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64192 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64193 +#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)
64194 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64195 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64196 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64197 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64198 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64199 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64200 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64201 +#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)
64202 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64203 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64204 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64205 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64206 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64207 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64208 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64209 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64210 +#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)
64211 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64212 +
64213 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64214 +
64215 +#endif
64216 +
64217 +#endif
64218 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64219 new file mode 100644
64220 index 0000000..2bd4c8d
64221 --- /dev/null
64222 +++ b/include/linux/grmsg.h
64223 @@ -0,0 +1,111 @@
64224 +#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"
64225 +#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"
64226 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64227 +#define GR_STOPMOD_MSG "denied modification of module state by "
64228 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64229 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64230 +#define GR_IOPERM_MSG "denied use of ioperm() by "
64231 +#define GR_IOPL_MSG "denied use of iopl() by "
64232 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64233 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64234 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64235 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64236 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64237 +#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"
64238 +#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"
64239 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64240 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64241 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64242 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64243 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64244 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64245 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64246 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64247 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64248 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64249 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64250 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64251 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64252 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64253 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64254 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64255 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64256 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64257 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64258 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64259 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64260 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64261 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64262 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64263 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64264 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64265 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64266 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64267 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64268 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64269 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64270 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64271 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64272 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64273 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64274 +#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"
64275 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64276 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64277 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64278 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64279 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64280 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64281 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64282 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64283 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64284 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64285 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64286 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64287 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64288 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64289 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64290 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64291 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64292 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64293 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64294 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64295 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
64296 +#define GR_NICE_CHROOT_MSG "denied priority change by "
64297 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64298 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64299 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64300 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64301 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64302 +#define GR_TIME_MSG "time set by "
64303 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64304 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64305 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64306 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64307 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64308 +#define GR_BIND_MSG "denied bind() by "
64309 +#define GR_CONNECT_MSG "denied connect() by "
64310 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64311 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64312 +#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"
64313 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64314 +#define GR_CAP_ACL_MSG "use of %s denied for "
64315 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64316 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64317 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64318 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64319 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64320 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64321 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64322 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64323 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64324 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64325 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64326 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64327 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64328 +#define GR_VM86_MSG "denied use of vm86 by "
64329 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64330 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64331 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64332 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64333 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64334 +#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 "
64335 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64336 new file mode 100644
64337 index 0000000..c5e5913
64338 --- /dev/null
64339 +++ b/include/linux/grsecurity.h
64340 @@ -0,0 +1,257 @@
64341 +#ifndef GR_SECURITY_H
64342 +#define GR_SECURITY_H
64343 +#include <linux/fs.h>
64344 +#include <linux/fs_struct.h>
64345 +#include <linux/binfmts.h>
64346 +#include <linux/gracl.h>
64347 +
64348 +/* notify of brain-dead configs */
64349 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64350 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64351 +#endif
64352 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64353 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64354 +#endif
64355 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64356 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64357 +#endif
64358 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64359 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
64360 +#endif
64361 +
64362 +#include <linux/compat.h>
64363 +
64364 +struct user_arg_ptr {
64365 +#ifdef CONFIG_COMPAT
64366 + bool is_compat;
64367 +#endif
64368 + union {
64369 + const char __user *const __user *native;
64370 +#ifdef CONFIG_COMPAT
64371 + const compat_uptr_t __user *compat;
64372 +#endif
64373 + } ptr;
64374 +};
64375 +
64376 +void gr_handle_brute_attach(unsigned long mm_flags);
64377 +void gr_handle_brute_check(void);
64378 +void gr_handle_kernel_exploit(void);
64379 +int gr_process_user_ban(void);
64380 +
64381 +char gr_roletype_to_char(void);
64382 +
64383 +int gr_acl_enable_at_secure(void);
64384 +
64385 +int gr_check_user_change(int real, int effective, int fs);
64386 +int gr_check_group_change(int real, int effective, int fs);
64387 +
64388 +void gr_del_task_from_ip_table(struct task_struct *p);
64389 +
64390 +int gr_pid_is_chrooted(struct task_struct *p);
64391 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64392 +int gr_handle_chroot_nice(void);
64393 +int gr_handle_chroot_sysctl(const int op);
64394 +int gr_handle_chroot_setpriority(struct task_struct *p,
64395 + const int niceval);
64396 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64397 +int gr_handle_chroot_chroot(const struct dentry *dentry,
64398 + const struct vfsmount *mnt);
64399 +void gr_handle_chroot_chdir(struct path *path);
64400 +int gr_handle_chroot_chmod(const struct dentry *dentry,
64401 + const struct vfsmount *mnt, const int mode);
64402 +int gr_handle_chroot_mknod(const struct dentry *dentry,
64403 + const struct vfsmount *mnt, const int mode);
64404 +int gr_handle_chroot_mount(const struct dentry *dentry,
64405 + const struct vfsmount *mnt,
64406 + const char *dev_name);
64407 +int gr_handle_chroot_pivot(void);
64408 +int gr_handle_chroot_unix(const pid_t pid);
64409 +
64410 +int gr_handle_rawio(const struct inode *inode);
64411 +
64412 +void gr_handle_ioperm(void);
64413 +void gr_handle_iopl(void);
64414 +
64415 +umode_t gr_acl_umask(void);
64416 +
64417 +int gr_tpe_allow(const struct file *file);
64418 +
64419 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64420 +void gr_clear_chroot_entries(struct task_struct *task);
64421 +
64422 +void gr_log_forkfail(const int retval);
64423 +void gr_log_timechange(void);
64424 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64425 +void gr_log_chdir(const struct dentry *dentry,
64426 + const struct vfsmount *mnt);
64427 +void gr_log_chroot_exec(const struct dentry *dentry,
64428 + const struct vfsmount *mnt);
64429 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64430 +void gr_log_remount(const char *devname, const int retval);
64431 +void gr_log_unmount(const char *devname, const int retval);
64432 +void gr_log_mount(const char *from, const char *to, const int retval);
64433 +void gr_log_textrel(struct vm_area_struct *vma);
64434 +void gr_log_rwxmmap(struct file *file);
64435 +void gr_log_rwxmprotect(struct file *file);
64436 +
64437 +int gr_handle_follow_link(const struct inode *parent,
64438 + const struct inode *inode,
64439 + const struct dentry *dentry,
64440 + const struct vfsmount *mnt);
64441 +int gr_handle_fifo(const struct dentry *dentry,
64442 + const struct vfsmount *mnt,
64443 + const struct dentry *dir, const int flag,
64444 + const int acc_mode);
64445 +int gr_handle_hardlink(const struct dentry *dentry,
64446 + const struct vfsmount *mnt,
64447 + struct inode *inode,
64448 + const int mode, const struct filename *to);
64449 +
64450 +int gr_is_capable(const int cap);
64451 +int gr_is_capable_nolog(const int cap);
64452 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64453 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64454 +
64455 +void gr_copy_label(struct task_struct *tsk);
64456 +void gr_handle_crash(struct task_struct *task, const int sig);
64457 +int gr_handle_signal(const struct task_struct *p, const int sig);
64458 +int gr_check_crash_uid(const uid_t uid);
64459 +int gr_check_protected_task(const struct task_struct *task);
64460 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64461 +int gr_acl_handle_mmap(const struct file *file,
64462 + const unsigned long prot);
64463 +int gr_acl_handle_mprotect(const struct file *file,
64464 + const unsigned long prot);
64465 +int gr_check_hidden_task(const struct task_struct *tsk);
64466 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64467 + const struct vfsmount *mnt);
64468 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
64469 + const struct vfsmount *mnt);
64470 +__u32 gr_acl_handle_access(const struct dentry *dentry,
64471 + const struct vfsmount *mnt, const int fmode);
64472 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64473 + const struct vfsmount *mnt, umode_t *mode);
64474 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
64475 + const struct vfsmount *mnt);
64476 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64477 + const struct vfsmount *mnt);
64478 +int gr_handle_ptrace(struct task_struct *task, const long request);
64479 +int gr_handle_proc_ptrace(struct task_struct *task);
64480 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
64481 + const struct vfsmount *mnt);
64482 +int gr_check_crash_exec(const struct file *filp);
64483 +int gr_acl_is_enabled(void);
64484 +void gr_set_kernel_label(struct task_struct *task);
64485 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
64486 + const gid_t gid);
64487 +int gr_set_proc_label(const struct dentry *dentry,
64488 + const struct vfsmount *mnt,
64489 + const int unsafe_flags);
64490 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64491 + const struct vfsmount *mnt);
64492 +__u32 gr_acl_handle_open(const struct dentry *dentry,
64493 + const struct vfsmount *mnt, int acc_mode);
64494 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
64495 + const struct dentry *p_dentry,
64496 + const struct vfsmount *p_mnt,
64497 + int open_flags, int acc_mode, const int imode);
64498 +void gr_handle_create(const struct dentry *dentry,
64499 + const struct vfsmount *mnt);
64500 +void gr_handle_proc_create(const struct dentry *dentry,
64501 + const struct inode *inode);
64502 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64503 + const struct dentry *parent_dentry,
64504 + const struct vfsmount *parent_mnt,
64505 + const int mode);
64506 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64507 + const struct dentry *parent_dentry,
64508 + const struct vfsmount *parent_mnt);
64509 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64510 + const struct vfsmount *mnt);
64511 +void gr_handle_delete(const ino_t ino, const dev_t dev);
64512 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64513 + const struct vfsmount *mnt);
64514 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64515 + const struct dentry *parent_dentry,
64516 + const struct vfsmount *parent_mnt,
64517 + const struct filename *from);
64518 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64519 + const struct dentry *parent_dentry,
64520 + const struct vfsmount *parent_mnt,
64521 + const struct dentry *old_dentry,
64522 + const struct vfsmount *old_mnt, const struct filename *to);
64523 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64524 +int gr_acl_handle_rename(struct dentry *new_dentry,
64525 + struct dentry *parent_dentry,
64526 + const struct vfsmount *parent_mnt,
64527 + struct dentry *old_dentry,
64528 + struct inode *old_parent_inode,
64529 + struct vfsmount *old_mnt, const struct filename *newname);
64530 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64531 + struct dentry *old_dentry,
64532 + struct dentry *new_dentry,
64533 + struct vfsmount *mnt, const __u8 replace);
64534 +__u32 gr_check_link(const struct dentry *new_dentry,
64535 + const struct dentry *parent_dentry,
64536 + const struct vfsmount *parent_mnt,
64537 + const struct dentry *old_dentry,
64538 + const struct vfsmount *old_mnt);
64539 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64540 + const unsigned int namelen, const ino_t ino);
64541 +
64542 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64543 + const struct vfsmount *mnt);
64544 +void gr_acl_handle_exit(void);
64545 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64546 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64547 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64548 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64549 +void gr_audit_ptrace(struct task_struct *task);
64550 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64551 +void gr_put_exec_file(struct task_struct *task);
64552 +
64553 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64554 +
64555 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64556 +extern void gr_learn_resource(const struct task_struct *task, const int res,
64557 + const unsigned long wanted, const int gt);
64558 +#else
64559 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
64560 + const unsigned long wanted, const int gt)
64561 +{
64562 +}
64563 +#endif
64564 +
64565 +#ifdef CONFIG_GRKERNSEC_RESLOG
64566 +extern void gr_log_resource(const struct task_struct *task, const int res,
64567 + const unsigned long wanted, const int gt);
64568 +#else
64569 +static inline void gr_log_resource(const struct task_struct *task, const int res,
64570 + const unsigned long wanted, const int gt)
64571 +{
64572 +}
64573 +#endif
64574 +
64575 +#ifdef CONFIG_GRKERNSEC
64576 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64577 +void gr_handle_vm86(void);
64578 +void gr_handle_mem_readwrite(u64 from, u64 to);
64579 +
64580 +void gr_log_badprocpid(const char *entry);
64581 +
64582 +extern int grsec_enable_dmesg;
64583 +extern int grsec_disable_privio;
64584 +
64585 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64586 +extern int grsec_proc_gid;
64587 +#endif
64588 +
64589 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64590 +extern int grsec_enable_chroot_findtask;
64591 +#endif
64592 +#ifdef CONFIG_GRKERNSEC_SETXID
64593 +extern int grsec_enable_setxid;
64594 +#endif
64595 +#endif
64596 +
64597 +#endif
64598 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64599 new file mode 100644
64600 index 0000000..e7ffaaf
64601 --- /dev/null
64602 +++ b/include/linux/grsock.h
64603 @@ -0,0 +1,19 @@
64604 +#ifndef __GRSOCK_H
64605 +#define __GRSOCK_H
64606 +
64607 +extern void gr_attach_curr_ip(const struct sock *sk);
64608 +extern int gr_handle_sock_all(const int family, const int type,
64609 + const int protocol);
64610 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64611 +extern int gr_handle_sock_server_other(const struct sock *sck);
64612 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64613 +extern int gr_search_connect(struct socket * sock,
64614 + struct sockaddr_in * addr);
64615 +extern int gr_search_bind(struct socket * sock,
64616 + struct sockaddr_in * addr);
64617 +extern int gr_search_listen(struct socket * sock);
64618 +extern int gr_search_accept(struct socket * sock);
64619 +extern int gr_search_socket(const int domain, const int type,
64620 + const int protocol);
64621 +
64622 +#endif
64623 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64624 index ef788b5..ac41b7b 100644
64625 --- a/include/linux/highmem.h
64626 +++ b/include/linux/highmem.h
64627 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64628 kunmap_atomic(kaddr);
64629 }
64630
64631 +static inline void sanitize_highpage(struct page *page)
64632 +{
64633 + void *kaddr;
64634 + unsigned long flags;
64635 +
64636 + local_irq_save(flags);
64637 + kaddr = kmap_atomic(page);
64638 + clear_page(kaddr);
64639 + kunmap_atomic(kaddr);
64640 + local_irq_restore(flags);
64641 +}
64642 +
64643 static inline void zero_user_segments(struct page *page,
64644 unsigned start1, unsigned end1,
64645 unsigned start2, unsigned end2)
64646 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64647 index 800de22..7a2fa46 100644
64648 --- a/include/linux/i2c.h
64649 +++ b/include/linux/i2c.h
64650 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64651 /* To determine what the adapter supports */
64652 u32 (*functionality) (struct i2c_adapter *);
64653 };
64654 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64655
64656 /*
64657 * i2c_adapter is the structure used to identify a physical i2c bus along
64658 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64659 index d23c3c2..eb63c81 100644
64660 --- a/include/linux/i2o.h
64661 +++ b/include/linux/i2o.h
64662 @@ -565,7 +565,7 @@ struct i2o_controller {
64663 struct i2o_device *exec; /* Executive */
64664 #if BITS_PER_LONG == 64
64665 spinlock_t context_list_lock; /* lock for context_list */
64666 - atomic_t context_list_counter; /* needed for unique contexts */
64667 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64668 struct list_head context_list; /* list of context id's
64669 and pointers */
64670 #endif
64671 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64672 index aff7ad8..3942bbd 100644
64673 --- a/include/linux/if_pppox.h
64674 +++ b/include/linux/if_pppox.h
64675 @@ -76,7 +76,7 @@ struct pppox_proto {
64676 int (*ioctl)(struct socket *sock, unsigned int cmd,
64677 unsigned long arg);
64678 struct module *owner;
64679 -};
64680 +} __do_const;
64681
64682 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64683 extern void unregister_pppox_proto(int proto_num);
64684 diff --git a/include/linux/init.h b/include/linux/init.h
64685 index e59041e..df0a975 100644
64686 --- a/include/linux/init.h
64687 +++ b/include/linux/init.h
64688 @@ -39,9 +39,36 @@
64689 * Also note, that this data cannot be "const".
64690 */
64691
64692 +#ifdef MODULE
64693 +#define add_init_latent_entropy
64694 +#define add_devinit_latent_entropy
64695 +#define add_cpuinit_latent_entropy
64696 +#define add_meminit_latent_entropy
64697 +#else
64698 +#define add_init_latent_entropy __latent_entropy
64699 +
64700 +#ifdef CONFIG_HOTPLUG
64701 +#define add_devinit_latent_entropy
64702 +#else
64703 +#define add_devinit_latent_entropy __latent_entropy
64704 +#endif
64705 +
64706 +#ifdef CONFIG_HOTPLUG_CPU
64707 +#define add_cpuinit_latent_entropy
64708 +#else
64709 +#define add_cpuinit_latent_entropy __latent_entropy
64710 +#endif
64711 +
64712 +#ifdef CONFIG_MEMORY_HOTPLUG
64713 +#define add_meminit_latent_entropy
64714 +#else
64715 +#define add_meminit_latent_entropy __latent_entropy
64716 +#endif
64717 +#endif
64718 +
64719 /* These are for everybody (although not all archs will actually
64720 discard it in modules) */
64721 -#define __init __section(.init.text) __cold notrace
64722 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64723 #define __initdata __section(.init.data)
64724 #define __initconst __constsection(.init.rodata)
64725 #define __exitdata __section(.exit.data)
64726 @@ -94,7 +121,7 @@
64727 #define __exit __section(.exit.text) __exitused __cold notrace
64728
64729 /* Used for HOTPLUG */
64730 -#define __devinit __section(.devinit.text) __cold notrace
64731 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64732 #define __devinitdata __section(.devinit.data)
64733 #define __devinitconst __constsection(.devinit.rodata)
64734 #define __devexit __section(.devexit.text) __exitused __cold notrace
64735 @@ -102,7 +129,7 @@
64736 #define __devexitconst __constsection(.devexit.rodata)
64737
64738 /* Used for HOTPLUG_CPU */
64739 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64740 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64741 #define __cpuinitdata __section(.cpuinit.data)
64742 #define __cpuinitconst __constsection(.cpuinit.rodata)
64743 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64744 @@ -110,7 +137,7 @@
64745 #define __cpuexitconst __constsection(.cpuexit.rodata)
64746
64747 /* Used for MEMORY_HOTPLUG */
64748 -#define __meminit __section(.meminit.text) __cold notrace
64749 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64750 #define __meminitdata __section(.meminit.data)
64751 #define __meminitconst __constsection(.meminit.rodata)
64752 #define __memexit __section(.memexit.text) __exitused __cold notrace
64753 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64754 index 6d087c5..401cab8 100644
64755 --- a/include/linux/init_task.h
64756 +++ b/include/linux/init_task.h
64757 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64758
64759 #define INIT_TASK_COMM "swapper"
64760
64761 +#ifdef CONFIG_X86
64762 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64763 +#else
64764 +#define INIT_TASK_THREAD_INFO
64765 +#endif
64766 +
64767 /*
64768 * INIT_TASK is used to set up the first task table, touch at
64769 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64770 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64771 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64772 .comm = INIT_TASK_COMM, \
64773 .thread = INIT_THREAD, \
64774 + INIT_TASK_THREAD_INFO \
64775 .fs = &init_fs, \
64776 .files = &init_files, \
64777 .signal = &init_signals, \
64778 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64779 index 5e4e617..073b866 100644
64780 --- a/include/linux/interrupt.h
64781 +++ b/include/linux/interrupt.h
64782 @@ -435,7 +435,7 @@ enum
64783 /* map softirq index to softirq name. update 'softirq_to_name' in
64784 * kernel/softirq.c when adding a new softirq.
64785 */
64786 -extern char *softirq_to_name[NR_SOFTIRQS];
64787 +extern const char * const softirq_to_name[NR_SOFTIRQS];
64788
64789 /* softirq mask and active fields moved to irq_cpustat_t in
64790 * asm/hardirq.h to get better cache usage. KAO
64791 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64792
64793 struct softirq_action
64794 {
64795 - void (*action)(struct softirq_action *);
64796 -};
64797 + void (*action)(void);
64798 +} __no_const;
64799
64800 asmlinkage void do_softirq(void);
64801 asmlinkage void __do_softirq(void);
64802 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64803 +extern void open_softirq(int nr, void (*action)(void));
64804 extern void softirq_init(void);
64805 extern void __raise_softirq_irqoff(unsigned int nr);
64806
64807 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64808 index 6883e19..06992b1 100644
64809 --- a/include/linux/kallsyms.h
64810 +++ b/include/linux/kallsyms.h
64811 @@ -15,7 +15,8 @@
64812
64813 struct module;
64814
64815 -#ifdef CONFIG_KALLSYMS
64816 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64817 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64818 /* Lookup the address for a symbol. Returns 0 if not found. */
64819 unsigned long kallsyms_lookup_name(const char *name);
64820
64821 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64822 /* Stupid that this does nothing, but I didn't create this mess. */
64823 #define __print_symbol(fmt, addr)
64824 #endif /*CONFIG_KALLSYMS*/
64825 +#else /* when included by kallsyms.c, vsnprintf.c, or
64826 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64827 +extern void __print_symbol(const char *fmt, unsigned long address);
64828 +extern int sprint_backtrace(char *buffer, unsigned long address);
64829 +extern int sprint_symbol(char *buffer, unsigned long address);
64830 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64831 +const char *kallsyms_lookup(unsigned long addr,
64832 + unsigned long *symbolsize,
64833 + unsigned long *offset,
64834 + char **modname, char *namebuf);
64835 +#endif
64836
64837 /* This macro allows us to keep printk typechecking */
64838 static __printf(1, 2)
64839 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64840 index 4dff0c6..1ca9b72 100644
64841 --- a/include/linux/kgdb.h
64842 +++ b/include/linux/kgdb.h
64843 @@ -53,7 +53,7 @@ extern int kgdb_connected;
64844 extern int kgdb_io_module_registered;
64845
64846 extern atomic_t kgdb_setting_breakpoint;
64847 -extern atomic_t kgdb_cpu_doing_single_step;
64848 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64849
64850 extern struct task_struct *kgdb_usethread;
64851 extern struct task_struct *kgdb_contthread;
64852 @@ -255,7 +255,7 @@ struct kgdb_arch {
64853 void (*correct_hw_break)(void);
64854
64855 void (*enable_nmi)(bool on);
64856 -};
64857 +} __do_const;
64858
64859 /**
64860 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64861 @@ -280,7 +280,7 @@ struct kgdb_io {
64862 void (*pre_exception) (void);
64863 void (*post_exception) (void);
64864 int is_console;
64865 -};
64866 +} __do_const;
64867
64868 extern struct kgdb_arch arch_kgdb_ops;
64869
64870 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64871 index 5398d58..5883a34 100644
64872 --- a/include/linux/kmod.h
64873 +++ b/include/linux/kmod.h
64874 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64875 * usually useless though. */
64876 extern __printf(2, 3)
64877 int __request_module(bool wait, const char *name, ...);
64878 +extern __printf(3, 4)
64879 +int ___request_module(bool wait, char *param_name, const char *name, ...);
64880 #define request_module(mod...) __request_module(true, mod)
64881 #define request_module_nowait(mod...) __request_module(false, mod)
64882 #define try_then_request_module(x, mod...) \
64883 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64884 index 1e57449..4fede7b 100644
64885 --- a/include/linux/kobject.h
64886 +++ b/include/linux/kobject.h
64887 @@ -111,7 +111,7 @@ struct kobj_type {
64888 struct attribute **default_attrs;
64889 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64890 const void *(*namespace)(struct kobject *kobj);
64891 -};
64892 +} __do_const;
64893
64894 struct kobj_uevent_env {
64895 char *envp[UEVENT_NUM_ENVP];
64896 diff --git a/include/linux/kref.h b/include/linux/kref.h
64897 index 65af688..0592677 100644
64898 --- a/include/linux/kref.h
64899 +++ b/include/linux/kref.h
64900 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
64901 static inline int kref_sub(struct kref *kref, unsigned int count,
64902 void (*release)(struct kref *kref))
64903 {
64904 - WARN_ON(release == NULL);
64905 + BUG_ON(release == NULL);
64906
64907 if (atomic_sub_and_test((int) count, &kref->refcount)) {
64908 release(kref);
64909 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
64910 index ecc5543..0e96bcc 100644
64911 --- a/include/linux/kvm_host.h
64912 +++ b/include/linux/kvm_host.h
64913 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
64914 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
64915 void vcpu_put(struct kvm_vcpu *vcpu);
64916
64917 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64918 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64919 struct module *module);
64920 void kvm_exit(void);
64921
64922 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
64923 struct kvm_guest_debug *dbg);
64924 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
64925
64926 -int kvm_arch_init(void *opaque);
64927 +int kvm_arch_init(const void *opaque);
64928 void kvm_arch_exit(void);
64929
64930 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
64931 diff --git a/include/linux/libata.h b/include/linux/libata.h
64932 index 1e36c63..0c5046e 100644
64933 --- a/include/linux/libata.h
64934 +++ b/include/linux/libata.h
64935 @@ -915,7 +915,7 @@ struct ata_port_operations {
64936 * fields must be pointers.
64937 */
64938 const struct ata_port_operations *inherits;
64939 -};
64940 +} __do_const;
64941
64942 struct ata_port_info {
64943 unsigned long flags;
64944 diff --git a/include/linux/list.h b/include/linux/list.h
64945 index cc6d2aa..71febca 100644
64946 --- a/include/linux/list.h
64947 +++ b/include/linux/list.h
64948 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
64949 extern void list_del(struct list_head *entry);
64950 #endif
64951
64952 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
64953 +extern void pax_list_del(struct list_head *entry);
64954 +
64955 /**
64956 * list_replace - replace old entry by new one
64957 * @old : the element to be replaced
64958 diff --git a/include/linux/mm.h b/include/linux/mm.h
64959 index 280dae5..baea6c8 100644
64960 --- a/include/linux/mm.h
64961 +++ b/include/linux/mm.h
64962 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
64963 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
64964 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
64965 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
64966 +
64967 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64968 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
64969 +#endif
64970 +
64971 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
64972
64973 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
64974 @@ -231,6 +236,7 @@ struct vm_operations_struct {
64975 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
64976 unsigned long size, pgoff_t pgoff);
64977 };
64978 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
64979
64980 struct mmu_gather;
64981 struct inode;
64982 @@ -1039,34 +1045,6 @@ int set_page_dirty(struct page *page);
64983 int set_page_dirty_lock(struct page *page);
64984 int clear_page_dirty_for_io(struct page *page);
64985
64986 -/* Is the vma a continuation of the stack vma above it? */
64987 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
64988 -{
64989 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
64990 -}
64991 -
64992 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
64993 - unsigned long addr)
64994 -{
64995 - return (vma->vm_flags & VM_GROWSDOWN) &&
64996 - (vma->vm_start == addr) &&
64997 - !vma_growsdown(vma->vm_prev, addr);
64998 -}
64999 -
65000 -/* Is the vma a continuation of the stack vma below it? */
65001 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65002 -{
65003 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65004 -}
65005 -
65006 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
65007 - unsigned long addr)
65008 -{
65009 - return (vma->vm_flags & VM_GROWSUP) &&
65010 - (vma->vm_end == addr) &&
65011 - !vma_growsup(vma->vm_next, addr);
65012 -}
65013 -
65014 extern pid_t
65015 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65016
65017 @@ -1166,6 +1144,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65018 }
65019 #endif
65020
65021 +#ifdef CONFIG_MMU
65022 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65023 +#else
65024 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65025 +{
65026 + return __pgprot(0);
65027 +}
65028 +#endif
65029 +
65030 int vma_wants_writenotify(struct vm_area_struct *vma);
65031
65032 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65033 @@ -1184,8 +1171,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65034 {
65035 return 0;
65036 }
65037 +
65038 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65039 + unsigned long address)
65040 +{
65041 + return 0;
65042 +}
65043 #else
65044 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65045 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65046 #endif
65047
65048 #ifdef __PAGETABLE_PMD_FOLDED
65049 @@ -1194,8 +1188,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65050 {
65051 return 0;
65052 }
65053 +
65054 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65055 + unsigned long address)
65056 +{
65057 + return 0;
65058 +}
65059 #else
65060 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65061 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65062 #endif
65063
65064 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65065 @@ -1213,11 +1214,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65066 NULL: pud_offset(pgd, address);
65067 }
65068
65069 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65070 +{
65071 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65072 + NULL: pud_offset(pgd, address);
65073 +}
65074 +
65075 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65076 {
65077 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65078 NULL: pmd_offset(pud, address);
65079 }
65080 +
65081 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65082 +{
65083 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65084 + NULL: pmd_offset(pud, address);
65085 +}
65086 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65087
65088 #if USE_SPLIT_PTLOCKS
65089 @@ -1447,6 +1460,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65090 unsigned long, unsigned long,
65091 unsigned long, unsigned long);
65092 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65093 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65094
65095 /* These take the mm semaphore themselves */
65096 extern unsigned long vm_brk(unsigned long, unsigned long);
65097 @@ -1510,6 +1524,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65098 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65099 struct vm_area_struct **pprev);
65100
65101 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65102 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65103 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65104 +
65105 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65106 NULL if none. Assume start_addr < end_addr. */
65107 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65108 @@ -1538,15 +1556,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65109 return vma;
65110 }
65111
65112 -#ifdef CONFIG_MMU
65113 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
65114 -#else
65115 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65116 -{
65117 - return __pgprot(0);
65118 -}
65119 -#endif
65120 -
65121 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65122 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65123 unsigned long pfn, unsigned long size, pgprot_t);
65124 @@ -1652,7 +1661,7 @@ extern int unpoison_memory(unsigned long pfn);
65125 extern int sysctl_memory_failure_early_kill;
65126 extern int sysctl_memory_failure_recovery;
65127 extern void shake_page(struct page *p, int access);
65128 -extern atomic_long_t mce_bad_pages;
65129 +extern atomic_long_unchecked_t mce_bad_pages;
65130 extern int soft_offline_page(struct page *page, int flags);
65131
65132 extern void dump_page(struct page *page);
65133 @@ -1683,5 +1692,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65134 static inline bool page_is_guard(struct page *page) { return false; }
65135 #endif /* CONFIG_DEBUG_PAGEALLOC */
65136
65137 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65138 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65139 +#else
65140 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65141 +#endif
65142 +
65143 #endif /* __KERNEL__ */
65144 #endif /* _LINUX_MM_H */
65145 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65146 index 31f8a3a..499f1db 100644
65147 --- a/include/linux/mm_types.h
65148 +++ b/include/linux/mm_types.h
65149 @@ -275,6 +275,8 @@ struct vm_area_struct {
65150 #ifdef CONFIG_NUMA
65151 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65152 #endif
65153 +
65154 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65155 };
65156
65157 struct core_thread {
65158 @@ -348,7 +350,7 @@ struct mm_struct {
65159 unsigned long def_flags;
65160 unsigned long nr_ptes; /* Page table pages */
65161 unsigned long start_code, end_code, start_data, end_data;
65162 - unsigned long start_brk, brk, start_stack;
65163 + unsigned long brk_gap, start_brk, brk, start_stack;
65164 unsigned long arg_start, arg_end, env_start, env_end;
65165
65166 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65167 @@ -399,6 +401,24 @@ struct mm_struct {
65168 struct cpumask cpumask_allocation;
65169 #endif
65170 struct uprobes_state uprobes_state;
65171 +
65172 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65173 + unsigned long pax_flags;
65174 +#endif
65175 +
65176 +#ifdef CONFIG_PAX_DLRESOLVE
65177 + unsigned long call_dl_resolve;
65178 +#endif
65179 +
65180 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65181 + unsigned long call_syscall;
65182 +#endif
65183 +
65184 +#ifdef CONFIG_PAX_ASLR
65185 + unsigned long delta_mmap; /* randomized offset */
65186 + unsigned long delta_stack; /* randomized offset */
65187 +#endif
65188 +
65189 };
65190
65191 static inline void mm_init_cpumask(struct mm_struct *mm)
65192 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65193 index c5d5278..f0b68c8 100644
65194 --- a/include/linux/mmiotrace.h
65195 +++ b/include/linux/mmiotrace.h
65196 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65197 /* Called from ioremap.c */
65198 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65199 void __iomem *addr);
65200 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
65201 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65202
65203 /* For anyone to insert markers. Remember trailing newline. */
65204 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65205 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65206 {
65207 }
65208
65209 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65210 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65211 {
65212 }
65213
65214 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65215 index a23923b..073fee4 100644
65216 --- a/include/linux/mmzone.h
65217 +++ b/include/linux/mmzone.h
65218 @@ -421,7 +421,7 @@ struct zone {
65219 unsigned long flags; /* zone flags, see below */
65220
65221 /* Zone statistics */
65222 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65223 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65224
65225 /*
65226 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65227 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65228 index fed3def..7cc3f93 100644
65229 --- a/include/linux/mod_devicetable.h
65230 +++ b/include/linux/mod_devicetable.h
65231 @@ -12,7 +12,7 @@
65232 typedef unsigned long kernel_ulong_t;
65233 #endif
65234
65235 -#define PCI_ANY_ID (~0)
65236 +#define PCI_ANY_ID ((__u16)~0)
65237
65238 struct pci_device_id {
65239 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65240 @@ -139,7 +139,7 @@ struct usb_device_id {
65241 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65242 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65243
65244 -#define HID_ANY_ID (~0)
65245 +#define HID_ANY_ID (~0U)
65246 #define HID_BUS_ANY 0xffff
65247 #define HID_GROUP_ANY 0x0000
65248
65249 diff --git a/include/linux/module.h b/include/linux/module.h
65250 index 1375ee3..d631af0 100644
65251 --- a/include/linux/module.h
65252 +++ b/include/linux/module.h
65253 @@ -17,9 +17,11 @@
65254 #include <linux/moduleparam.h>
65255 #include <linux/tracepoint.h>
65256 #include <linux/export.h>
65257 +#include <linux/fs.h>
65258
65259 #include <linux/percpu.h>
65260 #include <asm/module.h>
65261 +#include <asm/pgtable.h>
65262
65263 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65264 #define MODULE_SIG_STRING "~Module signature appended~\n"
65265 @@ -281,19 +283,16 @@ struct module
65266 int (*init)(void);
65267
65268 /* If this is non-NULL, vfree after init() returns */
65269 - void *module_init;
65270 + void *module_init_rx, *module_init_rw;
65271
65272 /* Here is the actual code + data, vfree'd on unload. */
65273 - void *module_core;
65274 + void *module_core_rx, *module_core_rw;
65275
65276 /* Here are the sizes of the init and core sections */
65277 - unsigned int init_size, core_size;
65278 + unsigned int init_size_rw, core_size_rw;
65279
65280 /* The size of the executable code in each section. */
65281 - unsigned int init_text_size, core_text_size;
65282 -
65283 - /* Size of RO sections of the module (text+rodata) */
65284 - unsigned int init_ro_size, core_ro_size;
65285 + unsigned int init_size_rx, core_size_rx;
65286
65287 /* Arch-specific module values */
65288 struct mod_arch_specific arch;
65289 @@ -349,6 +348,10 @@ struct module
65290 #ifdef CONFIG_EVENT_TRACING
65291 struct ftrace_event_call **trace_events;
65292 unsigned int num_trace_events;
65293 + struct file_operations trace_id;
65294 + struct file_operations trace_enable;
65295 + struct file_operations trace_format;
65296 + struct file_operations trace_filter;
65297 #endif
65298 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65299 unsigned int num_ftrace_callsites;
65300 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65301 bool is_module_percpu_address(unsigned long addr);
65302 bool is_module_text_address(unsigned long addr);
65303
65304 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65305 +{
65306 +
65307 +#ifdef CONFIG_PAX_KERNEXEC
65308 + if (ktla_ktva(addr) >= (unsigned long)start &&
65309 + ktla_ktva(addr) < (unsigned long)start + size)
65310 + return 1;
65311 +#endif
65312 +
65313 + return ((void *)addr >= start && (void *)addr < start + size);
65314 +}
65315 +
65316 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65317 +{
65318 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65319 +}
65320 +
65321 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65322 +{
65323 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65324 +}
65325 +
65326 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65327 +{
65328 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65329 +}
65330 +
65331 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65332 +{
65333 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65334 +}
65335 +
65336 static inline int within_module_core(unsigned long addr, struct module *mod)
65337 {
65338 - return (unsigned long)mod->module_core <= addr &&
65339 - addr < (unsigned long)mod->module_core + mod->core_size;
65340 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65341 }
65342
65343 static inline int within_module_init(unsigned long addr, struct module *mod)
65344 {
65345 - return (unsigned long)mod->module_init <= addr &&
65346 - addr < (unsigned long)mod->module_init + mod->init_size;
65347 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65348 }
65349
65350 /* Search for module by name: must hold module_mutex. */
65351 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65352 index 560ca53..5ee8d73 100644
65353 --- a/include/linux/moduleloader.h
65354 +++ b/include/linux/moduleloader.h
65355 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65356
65357 /* Allocator used for allocating struct module, core sections and init
65358 sections. Returns NULL on failure. */
65359 -void *module_alloc(unsigned long size);
65360 +void *module_alloc(unsigned long size) __size_overflow(1);
65361 +
65362 +#ifdef CONFIG_PAX_KERNEXEC
65363 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
65364 +#else
65365 +#define module_alloc_exec(x) module_alloc(x)
65366 +#endif
65367
65368 /* Free memory returned from module_alloc. */
65369 void module_free(struct module *mod, void *module_region);
65370
65371 +#ifdef CONFIG_PAX_KERNEXEC
65372 +void module_free_exec(struct module *mod, void *module_region);
65373 +#else
65374 +#define module_free_exec(x, y) module_free((x), (y))
65375 +#endif
65376 +
65377 /*
65378 * Apply the given relocation to the (simplified) ELF. Return -error
65379 * or 0.
65380 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65381 unsigned int relsec,
65382 struct module *me)
65383 {
65384 +#ifdef CONFIG_MODULES
65385 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65386 +#endif
65387 return -ENOEXEC;
65388 }
65389 #endif
65390 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65391 unsigned int relsec,
65392 struct module *me)
65393 {
65394 +#ifdef CONFIG_MODULES
65395 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65396 +#endif
65397 return -ENOEXEC;
65398 }
65399 #endif
65400 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65401 index d6a5806..7c13347 100644
65402 --- a/include/linux/moduleparam.h
65403 +++ b/include/linux/moduleparam.h
65404 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65405 * @len is usually just sizeof(string).
65406 */
65407 #define module_param_string(name, string, len, perm) \
65408 - static const struct kparam_string __param_string_##name \
65409 + static const struct kparam_string __param_string_##name __used \
65410 = { len, string }; \
65411 __module_param_call(MODULE_PARAM_PREFIX, name, \
65412 &param_ops_string, \
65413 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65414 */
65415 #define module_param_array_named(name, array, type, nump, perm) \
65416 param_check_##type(name, &(array)[0]); \
65417 - static const struct kparam_array __param_arr_##name \
65418 + static const struct kparam_array __param_arr_##name __used \
65419 = { .max = ARRAY_SIZE(array), .num = nump, \
65420 .ops = &param_ops_##type, \
65421 .elemsize = sizeof(array[0]), .elem = array }; \
65422 diff --git a/include/linux/namei.h b/include/linux/namei.h
65423 index 4bf19d8..5268cea 100644
65424 --- a/include/linux/namei.h
65425 +++ b/include/linux/namei.h
65426 @@ -18,7 +18,7 @@ struct nameidata {
65427 unsigned seq;
65428 int last_type;
65429 unsigned depth;
65430 - char *saved_names[MAX_NESTED_LINKS + 1];
65431 + const char *saved_names[MAX_NESTED_LINKS + 1];
65432 };
65433
65434 /*
65435 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65436
65437 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65438
65439 -static inline void nd_set_link(struct nameidata *nd, char *path)
65440 +static inline void nd_set_link(struct nameidata *nd, const char *path)
65441 {
65442 nd->saved_names[nd->depth] = path;
65443 }
65444
65445 -static inline char *nd_get_link(struct nameidata *nd)
65446 +static inline const char *nd_get_link(const struct nameidata *nd)
65447 {
65448 return nd->saved_names[nd->depth];
65449 }
65450 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65451 index 825fb7e..24cdd41 100644
65452 --- a/include/linux/netdevice.h
65453 +++ b/include/linux/netdevice.h
65454 @@ -1002,6 +1002,7 @@ struct net_device_ops {
65455 struct net_device *dev,
65456 int idx);
65457 };
65458 +typedef struct net_device_ops __no_const net_device_ops_no_const;
65459
65460 /*
65461 * The DEVICE structure.
65462 @@ -1062,7 +1063,7 @@ struct net_device {
65463 int iflink;
65464
65465 struct net_device_stats stats;
65466 - atomic_long_t rx_dropped; /* dropped packets by core network
65467 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65468 * Do not use this in drivers.
65469 */
65470
65471 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65472 index 7958e84..ed74d7a 100644
65473 --- a/include/linux/netfilter/ipset/ip_set.h
65474 +++ b/include/linux/netfilter/ipset/ip_set.h
65475 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
65476 /* Return true if "b" set is the same as "a"
65477 * according to the create set parameters */
65478 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65479 -};
65480 +} __do_const;
65481
65482 /* The core set type structure */
65483 struct ip_set_type {
65484 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65485 index 4966dde..7d8ce06 100644
65486 --- a/include/linux/netfilter/nfnetlink.h
65487 +++ b/include/linux/netfilter/nfnetlink.h
65488 @@ -16,7 +16,7 @@ struct nfnl_callback {
65489 const struct nlattr * const cda[]);
65490 const struct nla_policy *policy; /* netlink attribute policy */
65491 const u_int16_t attr_count; /* number of nlattr's */
65492 -};
65493 +} __do_const;
65494
65495 struct nfnetlink_subsystem {
65496 const char *name;
65497 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65498 new file mode 100644
65499 index 0000000..33f4af8
65500 --- /dev/null
65501 +++ b/include/linux/netfilter/xt_gradm.h
65502 @@ -0,0 +1,9 @@
65503 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
65504 +#define _LINUX_NETFILTER_XT_GRADM_H 1
65505 +
65506 +struct xt_gradm_mtinfo {
65507 + __u16 flags;
65508 + __u16 invflags;
65509 +};
65510 +
65511 +#endif
65512 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65513 index d65746e..62e72c2 100644
65514 --- a/include/linux/notifier.h
65515 +++ b/include/linux/notifier.h
65516 @@ -51,7 +51,8 @@ struct notifier_block {
65517 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65518 struct notifier_block __rcu *next;
65519 int priority;
65520 -};
65521 +} __do_const;
65522 +typedef struct notifier_block __no_const notifier_block_no_const;
65523
65524 struct atomic_notifier_head {
65525 spinlock_t lock;
65526 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65527 index a4c5624..79d6d88 100644
65528 --- a/include/linux/oprofile.h
65529 +++ b/include/linux/oprofile.h
65530 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65531 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65532 char const * name, ulong * val);
65533
65534 -/** Create a file for read-only access to an atomic_t. */
65535 +/** Create a file for read-only access to an atomic_unchecked_t. */
65536 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65537 - char const * name, atomic_t * val);
65538 + char const * name, atomic_unchecked_t * val);
65539
65540 /** create a directory */
65541 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65542 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65543 index 6bfb2faa..1204767 100644
65544 --- a/include/linux/perf_event.h
65545 +++ b/include/linux/perf_event.h
65546 @@ -328,8 +328,8 @@ struct perf_event {
65547
65548 enum perf_event_active_state state;
65549 unsigned int attach_state;
65550 - local64_t count;
65551 - atomic64_t child_count;
65552 + local64_t count; /* PaX: fix it one day */
65553 + atomic64_unchecked_t child_count;
65554
65555 /*
65556 * These are the total time in nanoseconds that the event
65557 @@ -380,8 +380,8 @@ struct perf_event {
65558 * These accumulate total time (in nanoseconds) that children
65559 * events have been enabled and running, respectively.
65560 */
65561 - atomic64_t child_total_time_enabled;
65562 - atomic64_t child_total_time_running;
65563 + atomic64_unchecked_t child_total_time_enabled;
65564 + atomic64_unchecked_t child_total_time_running;
65565
65566 /*
65567 * Protect attach/detach and child_list:
65568 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65569 index ad1a427..6419649 100644
65570 --- a/include/linux/pipe_fs_i.h
65571 +++ b/include/linux/pipe_fs_i.h
65572 @@ -45,9 +45,9 @@ struct pipe_buffer {
65573 struct pipe_inode_info {
65574 wait_queue_head_t wait;
65575 unsigned int nrbufs, curbuf, buffers;
65576 - unsigned int readers;
65577 - unsigned int writers;
65578 - unsigned int waiting_writers;
65579 + atomic_t readers;
65580 + atomic_t writers;
65581 + atomic_t waiting_writers;
65582 unsigned int r_counter;
65583 unsigned int w_counter;
65584 struct page *tmp_page;
65585 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65586 index 5f28cae..3d23723 100644
65587 --- a/include/linux/platform_data/usb-ehci-s5p.h
65588 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65589 @@ -14,7 +14,7 @@
65590 struct s5p_ehci_platdata {
65591 int (*phy_init)(struct platform_device *pdev, int type);
65592 int (*phy_exit)(struct platform_device *pdev, int type);
65593 -};
65594 +} __no_const;
65595
65596 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65597
65598 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65599 index f271860..6b3bec5 100644
65600 --- a/include/linux/pm_runtime.h
65601 +++ b/include/linux/pm_runtime.h
65602 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65603
65604 static inline void pm_runtime_mark_last_busy(struct device *dev)
65605 {
65606 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65607 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65608 }
65609
65610 #else /* !CONFIG_PM_RUNTIME */
65611 diff --git a/include/linux/poison.h b/include/linux/poison.h
65612 index 2110a81..13a11bb 100644
65613 --- a/include/linux/poison.h
65614 +++ b/include/linux/poison.h
65615 @@ -19,8 +19,8 @@
65616 * under normal circumstances, used to verify that nobody uses
65617 * non-initialized list entries.
65618 */
65619 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65620 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65621 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65622 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65623
65624 /********** include/linux/timer.h **********/
65625 /*
65626 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65627 index 4a496eb..d9c5659 100644
65628 --- a/include/linux/power/smartreflex.h
65629 +++ b/include/linux/power/smartreflex.h
65630 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65631 int (*notify)(struct omap_sr *sr, u32 status);
65632 u8 notify_flags;
65633 u8 class_type;
65634 -};
65635 +} __do_const;
65636
65637 /**
65638 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65639 diff --git a/include/linux/printk.h b/include/linux/printk.h
65640 index 9afc01e..92c32e8 100644
65641 --- a/include/linux/printk.h
65642 +++ b/include/linux/printk.h
65643 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65644 extern int printk_needs_cpu(int cpu);
65645 extern void printk_tick(void);
65646
65647 +extern int kptr_restrict;
65648 +
65649 #ifdef CONFIG_PRINTK
65650 asmlinkage __printf(5, 0)
65651 int vprintk_emit(int facility, int level,
65652 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65653
65654 extern int printk_delay_msec;
65655 extern int dmesg_restrict;
65656 -extern int kptr_restrict;
65657
65658 void log_buf_kexec_setup(void);
65659 void __init setup_log_buf(int early);
65660 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65661 index 3fd2e87..75db910 100644
65662 --- a/include/linux/proc_fs.h
65663 +++ b/include/linux/proc_fs.h
65664 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65665 return proc_create_data(name, mode, parent, proc_fops, NULL);
65666 }
65667
65668 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65669 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65670 +{
65671 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65672 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65673 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65674 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65675 +#else
65676 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65677 +#endif
65678 +}
65679 +
65680 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65681 umode_t mode, struct proc_dir_entry *base,
65682 read_proc_t *read_proc, void * data)
65683 diff --git a/include/linux/random.h b/include/linux/random.h
65684 index 6330ed4..419c6c3 100644
65685 --- a/include/linux/random.h
65686 +++ b/include/linux/random.h
65687 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65688
65689 u32 prandom32(struct rnd_state *);
65690
65691 +static inline unsigned long pax_get_random_long(void)
65692 +{
65693 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65694 +}
65695 +
65696 /*
65697 * Handle minimum values for seeds
65698 */
65699 static inline u32 __seed(u32 x, u32 m)
65700 {
65701 - return (x < m) ? x + m : x;
65702 + return (x <= m) ? x + m + 1 : x;
65703 }
65704
65705 /**
65706 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65707 index 23b3630..e1bc12b 100644
65708 --- a/include/linux/reboot.h
65709 +++ b/include/linux/reboot.h
65710 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65711 * Architecture-specific implementations of sys_reboot commands.
65712 */
65713
65714 -extern void machine_restart(char *cmd);
65715 -extern void machine_halt(void);
65716 -extern void machine_power_off(void);
65717 +extern void machine_restart(char *cmd) __noreturn;
65718 +extern void machine_halt(void) __noreturn;
65719 +extern void machine_power_off(void) __noreturn;
65720
65721 extern void machine_shutdown(void);
65722 struct pt_regs;
65723 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65724 */
65725
65726 extern void kernel_restart_prepare(char *cmd);
65727 -extern void kernel_restart(char *cmd);
65728 -extern void kernel_halt(void);
65729 -extern void kernel_power_off(void);
65730 +extern void kernel_restart(char *cmd) __noreturn;
65731 +extern void kernel_halt(void) __noreturn;
65732 +extern void kernel_power_off(void) __noreturn;
65733
65734 extern int C_A_D; /* for sysctl */
65735 void ctrl_alt_del(void);
65736 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65737 * Emergency restart, callable from an interrupt handler.
65738 */
65739
65740 -extern void emergency_restart(void);
65741 +extern void emergency_restart(void) __noreturn;
65742 #include <asm/emergency-restart.h>
65743
65744 #endif /* _LINUX_REBOOT_H */
65745 diff --git a/include/linux/regset.h b/include/linux/regset.h
65746 index 8e0c9fe..ac4d221 100644
65747 --- a/include/linux/regset.h
65748 +++ b/include/linux/regset.h
65749 @@ -161,7 +161,8 @@ struct user_regset {
65750 unsigned int align;
65751 unsigned int bias;
65752 unsigned int core_note_type;
65753 -};
65754 +} __do_const;
65755 +typedef struct user_regset __no_const user_regset_no_const;
65756
65757 /**
65758 * struct user_regset_view - available regsets
65759 diff --git a/include/linux/relay.h b/include/linux/relay.h
65760 index 91cacc3..b55ff74 100644
65761 --- a/include/linux/relay.h
65762 +++ b/include/linux/relay.h
65763 @@ -160,7 +160,7 @@ struct rchan_callbacks
65764 * The callback should return 0 if successful, negative if not.
65765 */
65766 int (*remove_buf_file)(struct dentry *dentry);
65767 -};
65768 +} __no_const;
65769
65770 /*
65771 * CONFIG_RELAY kernel API, kernel/relay.c
65772 diff --git a/include/linux/rio.h b/include/linux/rio.h
65773 index a3e7842..d973ca6 100644
65774 --- a/include/linux/rio.h
65775 +++ b/include/linux/rio.h
65776 @@ -339,7 +339,7 @@ struct rio_ops {
65777 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65778 u64 rstart, u32 size, u32 flags);
65779 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65780 -};
65781 +} __no_const;
65782
65783 #define RIO_RESOURCE_MEM 0x00000100
65784 #define RIO_RESOURCE_DOORBELL 0x00000200
65785 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65786 index bfe1f47..6a33ee3 100644
65787 --- a/include/linux/rmap.h
65788 +++ b/include/linux/rmap.h
65789 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65790 void anon_vma_init(void); /* create anon_vma_cachep */
65791 int anon_vma_prepare(struct vm_area_struct *);
65792 void unlink_anon_vmas(struct vm_area_struct *);
65793 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65794 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65795 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65796 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65797
65798 static inline void anon_vma_merge(struct vm_area_struct *vma,
65799 struct vm_area_struct *next)
65800 diff --git a/include/linux/sched.h b/include/linux/sched.h
65801 index 3e63925..6c93b17 100644
65802 --- a/include/linux/sched.h
65803 +++ b/include/linux/sched.h
65804 @@ -61,6 +61,7 @@ struct bio_list;
65805 struct fs_struct;
65806 struct perf_event_context;
65807 struct blk_plug;
65808 +struct linux_binprm;
65809
65810 /*
65811 * List of flags we want to share for kernel threads,
65812 @@ -344,10 +345,23 @@ struct user_namespace;
65813 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65814
65815 extern int sysctl_max_map_count;
65816 +extern unsigned long sysctl_heap_stack_gap;
65817
65818 #include <linux/aio.h>
65819
65820 #ifdef CONFIG_MMU
65821 +
65822 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65823 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65824 +#else
65825 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65826 +{
65827 + return 0;
65828 +}
65829 +#endif
65830 +
65831 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65832 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65833 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65834 extern unsigned long
65835 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65836 @@ -614,6 +628,17 @@ struct signal_struct {
65837 #ifdef CONFIG_TASKSTATS
65838 struct taskstats *stats;
65839 #endif
65840 +
65841 +#ifdef CONFIG_GRKERNSEC
65842 + u32 curr_ip;
65843 + u32 saved_ip;
65844 + u32 gr_saddr;
65845 + u32 gr_daddr;
65846 + u16 gr_sport;
65847 + u16 gr_dport;
65848 + u8 used_accept:1;
65849 +#endif
65850 +
65851 #ifdef CONFIG_AUDIT
65852 unsigned audit_tty;
65853 struct tty_audit_buf *tty_audit_buf;
65854 @@ -691,6 +716,11 @@ struct user_struct {
65855 struct key *session_keyring; /* UID's default session keyring */
65856 #endif
65857
65858 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65859 + unsigned int banned;
65860 + unsigned long ban_expires;
65861 +#endif
65862 +
65863 /* Hash table maintenance information */
65864 struct hlist_node uidhash_node;
65865 kuid_t uid;
65866 @@ -1312,8 +1342,8 @@ struct task_struct {
65867 struct list_head thread_group;
65868
65869 struct completion *vfork_done; /* for vfork() */
65870 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65871 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65872 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65873 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65874
65875 cputime_t utime, stime, utimescaled, stimescaled;
65876 cputime_t gtime;
65877 @@ -1329,11 +1359,6 @@ struct task_struct {
65878 struct task_cputime cputime_expires;
65879 struct list_head cpu_timers[3];
65880
65881 -/* process credentials */
65882 - const struct cred __rcu *real_cred; /* objective and real subjective task
65883 - * credentials (COW) */
65884 - const struct cred __rcu *cred; /* effective (overridable) subjective task
65885 - * credentials (COW) */
65886 char comm[TASK_COMM_LEN]; /* executable name excluding path
65887 - access with [gs]et_task_comm (which lock
65888 it with task_lock())
65889 @@ -1350,6 +1375,10 @@ struct task_struct {
65890 #endif
65891 /* CPU-specific state of this task */
65892 struct thread_struct thread;
65893 +/* thread_info moved to task_struct */
65894 +#ifdef CONFIG_X86
65895 + struct thread_info tinfo;
65896 +#endif
65897 /* filesystem information */
65898 struct fs_struct *fs;
65899 /* open file information */
65900 @@ -1423,6 +1452,10 @@ struct task_struct {
65901 gfp_t lockdep_reclaim_gfp;
65902 #endif
65903
65904 +/* process credentials */
65905 + const struct cred __rcu *real_cred; /* objective and real subjective task
65906 + * credentials (COW) */
65907 +
65908 /* journalling filesystem info */
65909 void *journal_info;
65910
65911 @@ -1461,6 +1494,10 @@ struct task_struct {
65912 /* cg_list protected by css_set_lock and tsk->alloc_lock */
65913 struct list_head cg_list;
65914 #endif
65915 +
65916 + const struct cred __rcu *cred; /* effective (overridable) subjective task
65917 + * credentials (COW) */
65918 +
65919 #ifdef CONFIG_FUTEX
65920 struct robust_list_head __user *robust_list;
65921 #ifdef CONFIG_COMPAT
65922 @@ -1548,8 +1585,74 @@ struct task_struct {
65923 #ifdef CONFIG_UPROBES
65924 struct uprobe_task *utask;
65925 #endif
65926 +
65927 +#ifdef CONFIG_GRKERNSEC
65928 + /* grsecurity */
65929 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65930 + u64 exec_id;
65931 +#endif
65932 +#ifdef CONFIG_GRKERNSEC_SETXID
65933 + const struct cred *delayed_cred;
65934 +#endif
65935 + struct dentry *gr_chroot_dentry;
65936 + struct acl_subject_label *acl;
65937 + struct acl_role_label *role;
65938 + struct file *exec_file;
65939 + unsigned long brute_expires;
65940 + u16 acl_role_id;
65941 + /* is this the task that authenticated to the special role */
65942 + u8 acl_sp_role;
65943 + u8 is_writable;
65944 + u8 brute;
65945 + u8 gr_is_chrooted;
65946 +#endif
65947 +
65948 };
65949
65950 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
65951 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
65952 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
65953 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
65954 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
65955 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
65956 +
65957 +#ifdef CONFIG_PAX_SOFTMODE
65958 +extern int pax_softmode;
65959 +#endif
65960 +
65961 +extern int pax_check_flags(unsigned long *);
65962 +
65963 +/* if tsk != current then task_lock must be held on it */
65964 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65965 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
65966 +{
65967 + if (likely(tsk->mm))
65968 + return tsk->mm->pax_flags;
65969 + else
65970 + return 0UL;
65971 +}
65972 +
65973 +/* if tsk != current then task_lock must be held on it */
65974 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
65975 +{
65976 + if (likely(tsk->mm)) {
65977 + tsk->mm->pax_flags = flags;
65978 + return 0;
65979 + }
65980 + return -EINVAL;
65981 +}
65982 +#endif
65983 +
65984 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
65985 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
65986 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
65987 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
65988 +#endif
65989 +
65990 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
65991 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
65992 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
65993 +
65994 /* Future-safe accessor for struct task_struct's cpus_allowed. */
65995 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
65996
65997 @@ -2092,7 +2195,9 @@ void yield(void);
65998 extern struct exec_domain default_exec_domain;
65999
66000 union thread_union {
66001 +#ifndef CONFIG_X86
66002 struct thread_info thread_info;
66003 +#endif
66004 unsigned long stack[THREAD_SIZE/sizeof(long)];
66005 };
66006
66007 @@ -2125,6 +2230,7 @@ extern struct pid_namespace init_pid_ns;
66008 */
66009
66010 extern struct task_struct *find_task_by_vpid(pid_t nr);
66011 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66012 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66013 struct pid_namespace *ns);
66014
66015 @@ -2281,7 +2387,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66016 extern void exit_itimers(struct signal_struct *);
66017 extern void flush_itimer_signals(void);
66018
66019 -extern void do_group_exit(int);
66020 +extern __noreturn void do_group_exit(int);
66021
66022 extern void daemonize(const char *, ...);
66023 extern int allow_signal(int);
66024 @@ -2485,9 +2591,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66025
66026 #endif
66027
66028 -static inline int object_is_on_stack(void *obj)
66029 +static inline int object_starts_on_stack(void *obj)
66030 {
66031 - void *stack = task_stack_page(current);
66032 + const void *stack = task_stack_page(current);
66033
66034 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66035 }
66036 diff --git a/include/linux/security.h b/include/linux/security.h
66037 index 05e88bd..5cda002 100644
66038 --- a/include/linux/security.h
66039 +++ b/include/linux/security.h
66040 @@ -26,6 +26,7 @@
66041 #include <linux/capability.h>
66042 #include <linux/slab.h>
66043 #include <linux/err.h>
66044 +#include <linux/grsecurity.h>
66045
66046 struct linux_binprm;
66047 struct cred;
66048 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66049 index 68a04a3..866e6a1 100644
66050 --- a/include/linux/seq_file.h
66051 +++ b/include/linux/seq_file.h
66052 @@ -26,6 +26,9 @@ struct seq_file {
66053 struct mutex lock;
66054 const struct seq_operations *op;
66055 int poll_event;
66056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66057 + u64 exec_id;
66058 +#endif
66059 #ifdef CONFIG_USER_NS
66060 struct user_namespace *user_ns;
66061 #endif
66062 @@ -38,6 +41,7 @@ struct seq_operations {
66063 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66064 int (*show) (struct seq_file *m, void *v);
66065 };
66066 +typedef struct seq_operations __no_const seq_operations_no_const;
66067
66068 #define SEQ_SKIP 1
66069
66070 diff --git a/include/linux/shm.h b/include/linux/shm.h
66071 index bcf8a6a..4d0af77 100644
66072 --- a/include/linux/shm.h
66073 +++ b/include/linux/shm.h
66074 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66075
66076 /* The task created the shm object. NULL if the task is dead. */
66077 struct task_struct *shm_creator;
66078 +#ifdef CONFIG_GRKERNSEC
66079 + time_t shm_createtime;
66080 + pid_t shm_lapid;
66081 +#endif
66082 };
66083
66084 /* shm_mode upper byte flags */
66085 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66086 index 6a2c34e..a1f320f 100644
66087 --- a/include/linux/skbuff.h
66088 +++ b/include/linux/skbuff.h
66089 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66090 extern struct sk_buff *__alloc_skb(unsigned int size,
66091 gfp_t priority, int flags, int node);
66092 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66093 -static inline struct sk_buff *alloc_skb(unsigned int size,
66094 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66095 gfp_t priority)
66096 {
66097 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66098 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66099 */
66100 static inline int skb_queue_empty(const struct sk_buff_head *list)
66101 {
66102 - return list->next == (struct sk_buff *)list;
66103 + return list->next == (const struct sk_buff *)list;
66104 }
66105
66106 /**
66107 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66108 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66109 const struct sk_buff *skb)
66110 {
66111 - return skb->next == (struct sk_buff *)list;
66112 + return skb->next == (const struct sk_buff *)list;
66113 }
66114
66115 /**
66116 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66117 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66118 const struct sk_buff *skb)
66119 {
66120 - return skb->prev == (struct sk_buff *)list;
66121 + return skb->prev == (const struct sk_buff *)list;
66122 }
66123
66124 /**
66125 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66126 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66127 */
66128 #ifndef NET_SKB_PAD
66129 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66130 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66131 #endif
66132
66133 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66134 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66135 int noblock, int *err);
66136 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66137 struct poll_table_struct *wait);
66138 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66139 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66140 int offset, struct iovec *to,
66141 int size);
66142 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66143 diff --git a/include/linux/slab.h b/include/linux/slab.h
66144 index 83d1a14..e23d723 100644
66145 --- a/include/linux/slab.h
66146 +++ b/include/linux/slab.h
66147 @@ -11,12 +11,20 @@
66148
66149 #include <linux/gfp.h>
66150 #include <linux/types.h>
66151 +#include <linux/err.h>
66152
66153 /*
66154 * Flags to pass to kmem_cache_create().
66155 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66156 */
66157 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66158 +
66159 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66160 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66161 +#else
66162 +#define SLAB_USERCOPY 0x00000000UL
66163 +#endif
66164 +
66165 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66166 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66167 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66168 @@ -87,10 +95,13 @@
66169 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66170 * Both make kfree a no-op.
66171 */
66172 -#define ZERO_SIZE_PTR ((void *)16)
66173 +#define ZERO_SIZE_PTR \
66174 +({ \
66175 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66176 + (void *)(-MAX_ERRNO-1L); \
66177 +})
66178
66179 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66180 - (unsigned long)ZERO_SIZE_PTR)
66181 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66182
66183 /*
66184 * Common fields provided in kmem_cache by all slab allocators
66185 @@ -110,7 +121,7 @@ struct kmem_cache {
66186 unsigned int align; /* Alignment as calculated */
66187 unsigned long flags; /* Active flags on the slab */
66188 const char *name; /* Slab name for sysfs */
66189 - int refcount; /* Use counter */
66190 + atomic_t refcount; /* Use counter */
66191 void (*ctor)(void *); /* Called on object slot creation */
66192 struct list_head list; /* List of all slab caches on the system */
66193 };
66194 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66195 void kfree(const void *);
66196 void kzfree(const void *);
66197 size_t ksize(const void *);
66198 +const char *check_heap_object(const void *ptr, unsigned long n);
66199 +bool is_usercopy_object(const void *ptr);
66200
66201 /*
66202 * Allocator specific definitions. These are mainly used to establish optimized
66203 @@ -264,8 +277,18 @@ size_t ksize(const void *);
66204 * for general use, and so are not documented here. For a full list of
66205 * potential flags, always refer to linux/gfp.h.
66206 */
66207 +
66208 +extern void kmalloc_array_error(void)
66209 +#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66210 +__compiletime_warning("kmalloc_array called with swapped arguments?");
66211 +#else
66212 +__compiletime_error("kmalloc_array called with swapped arguments?");
66213 +#endif
66214 +
66215 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66216 {
66217 + if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66218 + kmalloc_array_error();
66219 if (size != 0 && n > SIZE_MAX / size)
66220 return NULL;
66221 return __kmalloc(n * size, flags);
66222 @@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66223 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66224 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66225 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66226 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66227 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66228 #define kmalloc_track_caller(size, flags) \
66229 __kmalloc_track_caller(size, flags, _RET_IP_)
66230 #else
66231 @@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66232 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66233 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66234 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66235 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66236 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66237 #define kmalloc_node_track_caller(size, flags, node) \
66238 __kmalloc_node_track_caller(size, flags, node, \
66239 _RET_IP_)
66240 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66241 index cc290f0..0ba60931 100644
66242 --- a/include/linux/slab_def.h
66243 +++ b/include/linux/slab_def.h
66244 @@ -52,7 +52,7 @@ struct kmem_cache {
66245 /* 4) cache creation/removal */
66246 const char *name;
66247 struct list_head list;
66248 - int refcount;
66249 + atomic_t refcount;
66250 int object_size;
66251 int align;
66252
66253 @@ -68,10 +68,10 @@ struct kmem_cache {
66254 unsigned long node_allocs;
66255 unsigned long node_frees;
66256 unsigned long node_overflow;
66257 - atomic_t allochit;
66258 - atomic_t allocmiss;
66259 - atomic_t freehit;
66260 - atomic_t freemiss;
66261 + atomic_unchecked_t allochit;
66262 + atomic_unchecked_t allocmiss;
66263 + atomic_unchecked_t freehit;
66264 + atomic_unchecked_t freemiss;
66265
66266 /*
66267 * If debugging is enabled, then the allocator can add additional
66268 @@ -104,11 +104,16 @@ struct cache_sizes {
66269 #ifdef CONFIG_ZONE_DMA
66270 struct kmem_cache *cs_dmacachep;
66271 #endif
66272 +
66273 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66274 + struct kmem_cache *cs_usercopycachep;
66275 +#endif
66276 +
66277 };
66278 extern struct cache_sizes malloc_sizes[];
66279
66280 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66281 -void *__kmalloc(size_t size, gfp_t flags);
66282 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66283
66284 #ifdef CONFIG_TRACING
66285 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66286 @@ -145,6 +150,13 @@ found:
66287 cachep = malloc_sizes[i].cs_dmacachep;
66288 else
66289 #endif
66290 +
66291 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66292 + if (flags & GFP_USERCOPY)
66293 + cachep = malloc_sizes[i].cs_usercopycachep;
66294 + else
66295 +#endif
66296 +
66297 cachep = malloc_sizes[i].cs_cachep;
66298
66299 ret = kmem_cache_alloc_trace(cachep, flags, size);
66300 @@ -155,7 +167,7 @@ found:
66301 }
66302
66303 #ifdef CONFIG_NUMA
66304 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66305 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66306 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66307
66308 #ifdef CONFIG_TRACING
66309 @@ -198,6 +210,13 @@ found:
66310 cachep = malloc_sizes[i].cs_dmacachep;
66311 else
66312 #endif
66313 +
66314 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66315 + if (flags & GFP_USERCOPY)
66316 + cachep = malloc_sizes[i].cs_usercopycachep;
66317 + else
66318 +#endif
66319 +
66320 cachep = malloc_sizes[i].cs_cachep;
66321
66322 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66323 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66324 index f28e14a..7831211 100644
66325 --- a/include/linux/slob_def.h
66326 +++ b/include/linux/slob_def.h
66327 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66328 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66329 }
66330
66331 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66332 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66333
66334 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66335 {
66336 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66337 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66338 }
66339
66340 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66341 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66342 {
66343 return kmalloc(size, flags);
66344 }
66345 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66346 index df448ad..b99e7f6 100644
66347 --- a/include/linux/slub_def.h
66348 +++ b/include/linux/slub_def.h
66349 @@ -91,7 +91,7 @@ struct kmem_cache {
66350 struct kmem_cache_order_objects max;
66351 struct kmem_cache_order_objects min;
66352 gfp_t allocflags; /* gfp flags to use on each alloc */
66353 - int refcount; /* Refcount for slab cache destroy */
66354 + atomic_t refcount; /* Refcount for slab cache destroy */
66355 void (*ctor)(void *);
66356 int inuse; /* Offset to metadata */
66357 int align; /* Alignment */
66358 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66359 * Sorry that the following has to be that ugly but some versions of GCC
66360 * have trouble with constant propagation and loops.
66361 */
66362 -static __always_inline int kmalloc_index(size_t size)
66363 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66364 {
66365 if (!size)
66366 return 0;
66367 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66368 }
66369
66370 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66371 -void *__kmalloc(size_t size, gfp_t flags);
66372 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66373
66374 static __always_inline void *
66375 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66376 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66377 }
66378 #endif
66379
66380 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66381 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66382 {
66383 unsigned int order = get_order(size);
66384 return kmalloc_order_trace(size, flags, order);
66385 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66386 }
66387
66388 #ifdef CONFIG_NUMA
66389 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66390 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66391 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66392
66393 #ifdef CONFIG_TRACING
66394 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66395 index 680f9a3..f13aeb0 100644
66396 --- a/include/linux/sonet.h
66397 +++ b/include/linux/sonet.h
66398 @@ -7,7 +7,7 @@
66399 #include <uapi/linux/sonet.h>
66400
66401 struct k_sonet_stats {
66402 -#define __HANDLE_ITEM(i) atomic_t i
66403 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66404 __SONET_ITEMS
66405 #undef __HANDLE_ITEM
66406 };
66407 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66408 index 34206b8..f019e06 100644
66409 --- a/include/linux/sunrpc/clnt.h
66410 +++ b/include/linux/sunrpc/clnt.h
66411 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66412 {
66413 switch (sap->sa_family) {
66414 case AF_INET:
66415 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
66416 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66417 case AF_INET6:
66418 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66419 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66420 }
66421 return 0;
66422 }
66423 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66424 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66425 const struct sockaddr *src)
66426 {
66427 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66428 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66429 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66430
66431 dsin->sin_family = ssin->sin_family;
66432 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66433 if (sa->sa_family != AF_INET6)
66434 return 0;
66435
66436 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66437 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66438 }
66439
66440 #endif /* __KERNEL__ */
66441 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66442 index 0b8e3e6..33e0a01 100644
66443 --- a/include/linux/sunrpc/svc_rdma.h
66444 +++ b/include/linux/sunrpc/svc_rdma.h
66445 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66446 extern unsigned int svcrdma_max_requests;
66447 extern unsigned int svcrdma_max_req_size;
66448
66449 -extern atomic_t rdma_stat_recv;
66450 -extern atomic_t rdma_stat_read;
66451 -extern atomic_t rdma_stat_write;
66452 -extern atomic_t rdma_stat_sq_starve;
66453 -extern atomic_t rdma_stat_rq_starve;
66454 -extern atomic_t rdma_stat_rq_poll;
66455 -extern atomic_t rdma_stat_rq_prod;
66456 -extern atomic_t rdma_stat_sq_poll;
66457 -extern atomic_t rdma_stat_sq_prod;
66458 +extern atomic_unchecked_t rdma_stat_recv;
66459 +extern atomic_unchecked_t rdma_stat_read;
66460 +extern atomic_unchecked_t rdma_stat_write;
66461 +extern atomic_unchecked_t rdma_stat_sq_starve;
66462 +extern atomic_unchecked_t rdma_stat_rq_starve;
66463 +extern atomic_unchecked_t rdma_stat_rq_poll;
66464 +extern atomic_unchecked_t rdma_stat_rq_prod;
66465 +extern atomic_unchecked_t rdma_stat_sq_poll;
66466 +extern atomic_unchecked_t rdma_stat_sq_prod;
66467
66468 #define RPCRDMA_VERSION 1
66469
66470 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66471 index cd844a6..3ca3592 100644
66472 --- a/include/linux/sysctl.h
66473 +++ b/include/linux/sysctl.h
66474 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66475
66476 extern int proc_dostring(struct ctl_table *, int,
66477 void __user *, size_t *, loff_t *);
66478 +extern int proc_dostring_modpriv(struct ctl_table *, int,
66479 + void __user *, size_t *, loff_t *);
66480 extern int proc_dointvec(struct ctl_table *, int,
66481 void __user *, size_t *, loff_t *);
66482 extern int proc_dointvec_minmax(struct ctl_table *, int,
66483 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66484 index 7faf933..eb6f5e3 100644
66485 --- a/include/linux/sysrq.h
66486 +++ b/include/linux/sysrq.h
66487 @@ -36,7 +36,7 @@ struct sysrq_key_op {
66488 char *help_msg;
66489 char *action_msg;
66490 int enable_mask;
66491 -};
66492 +} __do_const;
66493
66494 #ifdef CONFIG_MAGIC_SYSRQ
66495
66496 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
66497 index ccc1899..b1aaceb 100644
66498 --- a/include/linux/thread_info.h
66499 +++ b/include/linux/thread_info.h
66500 @@ -146,6 +146,15 @@ static inline bool test_and_clear_restore_sigmask(void)
66501 #error "no set_restore_sigmask() provided and default one won't work"
66502 #endif
66503
66504 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
66505 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
66506 +{
66507 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
66508 + if (!__builtin_constant_p(n))
66509 +#endif
66510 + __check_object_size(ptr, n, to);
66511 +}
66512 +
66513 #endif /* __KERNEL__ */
66514
66515 #endif /* _LINUX_THREAD_INFO_H */
66516 diff --git a/include/linux/tty.h b/include/linux/tty.h
66517 index f0b4eb4..1c4854e 100644
66518 --- a/include/linux/tty.h
66519 +++ b/include/linux/tty.h
66520 @@ -192,7 +192,7 @@ struct tty_port {
66521 const struct tty_port_operations *ops; /* Port operations */
66522 spinlock_t lock; /* Lock protecting tty field */
66523 int blocked_open; /* Waiting to open */
66524 - int count; /* Usage count */
66525 + atomic_t count; /* Usage count */
66526 wait_queue_head_t open_wait; /* Open waiters */
66527 wait_queue_head_t close_wait; /* Close waiters */
66528 wait_queue_head_t delta_msr_wait; /* Modem status change */
66529 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66530 struct tty_struct *tty, struct file *filp);
66531 static inline int tty_port_users(struct tty_port *port)
66532 {
66533 - return port->count + port->blocked_open;
66534 + return atomic_read(&port->count) + port->blocked_open;
66535 }
66536
66537 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66538 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66539 index dd976cf..e272742 100644
66540 --- a/include/linux/tty_driver.h
66541 +++ b/include/linux/tty_driver.h
66542 @@ -284,7 +284,7 @@ struct tty_operations {
66543 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66544 #endif
66545 const struct file_operations *proc_fops;
66546 -};
66547 +} __do_const;
66548
66549 struct tty_driver {
66550 int magic; /* magic number for this structure */
66551 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66552 index fb79dd8d..07d4773 100644
66553 --- a/include/linux/tty_ldisc.h
66554 +++ b/include/linux/tty_ldisc.h
66555 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66556
66557 struct module *owner;
66558
66559 - int refcount;
66560 + atomic_t refcount;
66561 };
66562
66563 struct tty_ldisc {
66564 diff --git a/include/linux/types.h b/include/linux/types.h
66565 index 1cc0e4b..0d50edf 100644
66566 --- a/include/linux/types.h
66567 +++ b/include/linux/types.h
66568 @@ -175,10 +175,26 @@ typedef struct {
66569 int counter;
66570 } atomic_t;
66571
66572 +#ifdef CONFIG_PAX_REFCOUNT
66573 +typedef struct {
66574 + int counter;
66575 +} atomic_unchecked_t;
66576 +#else
66577 +typedef atomic_t atomic_unchecked_t;
66578 +#endif
66579 +
66580 #ifdef CONFIG_64BIT
66581 typedef struct {
66582 long counter;
66583 } atomic64_t;
66584 +
66585 +#ifdef CONFIG_PAX_REFCOUNT
66586 +typedef struct {
66587 + long counter;
66588 +} atomic64_unchecked_t;
66589 +#else
66590 +typedef atomic64_t atomic64_unchecked_t;
66591 +#endif
66592 #endif
66593
66594 struct list_head {
66595 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66596 index 5ca0951..ab496a5 100644
66597 --- a/include/linux/uaccess.h
66598 +++ b/include/linux/uaccess.h
66599 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66600 long ret; \
66601 mm_segment_t old_fs = get_fs(); \
66602 \
66603 - set_fs(KERNEL_DS); \
66604 pagefault_disable(); \
66605 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66606 - pagefault_enable(); \
66607 + set_fs(KERNEL_DS); \
66608 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66609 set_fs(old_fs); \
66610 + pagefault_enable(); \
66611 ret; \
66612 })
66613
66614 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66615 index 99c1b4d..bb94261 100644
66616 --- a/include/linux/unaligned/access_ok.h
66617 +++ b/include/linux/unaligned/access_ok.h
66618 @@ -6,32 +6,32 @@
66619
66620 static inline u16 get_unaligned_le16(const void *p)
66621 {
66622 - return le16_to_cpup((__le16 *)p);
66623 + return le16_to_cpup((const __le16 *)p);
66624 }
66625
66626 static inline u32 get_unaligned_le32(const void *p)
66627 {
66628 - return le32_to_cpup((__le32 *)p);
66629 + return le32_to_cpup((const __le32 *)p);
66630 }
66631
66632 static inline u64 get_unaligned_le64(const void *p)
66633 {
66634 - return le64_to_cpup((__le64 *)p);
66635 + return le64_to_cpup((const __le64 *)p);
66636 }
66637
66638 static inline u16 get_unaligned_be16(const void *p)
66639 {
66640 - return be16_to_cpup((__be16 *)p);
66641 + return be16_to_cpup((const __be16 *)p);
66642 }
66643
66644 static inline u32 get_unaligned_be32(const void *p)
66645 {
66646 - return be32_to_cpup((__be32 *)p);
66647 + return be32_to_cpup((const __be32 *)p);
66648 }
66649
66650 static inline u64 get_unaligned_be64(const void *p)
66651 {
66652 - return be64_to_cpup((__be64 *)p);
66653 + return be64_to_cpup((const __be64 *)p);
66654 }
66655
66656 static inline void put_unaligned_le16(u16 val, void *p)
66657 diff --git a/include/linux/usb.h b/include/linux/usb.h
66658 index 10278d1..e21ec3c 100644
66659 --- a/include/linux/usb.h
66660 +++ b/include/linux/usb.h
66661 @@ -551,7 +551,7 @@ struct usb_device {
66662 int maxchild;
66663
66664 u32 quirks;
66665 - atomic_t urbnum;
66666 + atomic_unchecked_t urbnum;
66667
66668 unsigned long active_duration;
66669
66670 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66671 index c5d36c6..108f4f9 100644
66672 --- a/include/linux/usb/renesas_usbhs.h
66673 +++ b/include/linux/usb/renesas_usbhs.h
66674 @@ -39,7 +39,7 @@ enum {
66675 */
66676 struct renesas_usbhs_driver_callback {
66677 int (*notify_hotplug)(struct platform_device *pdev);
66678 -};
66679 +} __no_const;
66680
66681 /*
66682 * callback functions for platform
66683 diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
66684 index ddbbb7d..9134611 100644
66685 --- a/include/linux/usb/usbnet.h
66686 +++ b/include/linux/usb/usbnet.h
66687 @@ -33,6 +33,7 @@ struct usbnet {
66688 wait_queue_head_t *wait;
66689 struct mutex phy_mutex;
66690 unsigned char suspend_count;
66691 + unsigned char pkt_cnt, pkt_err;
66692
66693 /* i/o info: pipes etc */
66694 unsigned in, out;
66695 @@ -69,6 +70,8 @@ struct usbnet {
66696 # define EVENT_DEV_ASLEEP 6
66697 # define EVENT_DEV_OPEN 7
66698 # define EVENT_DEVICE_REPORT_IDLE 8
66699 +# define EVENT_NO_RUNTIME_PM 9
66700 +# define EVENT_RX_KILL 10
66701 };
66702
66703 static inline struct usb_driver *driver_of(struct usb_interface *intf)
66704 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66705 index 6f8fbcf..8259001 100644
66706 --- a/include/linux/vermagic.h
66707 +++ b/include/linux/vermagic.h
66708 @@ -25,9 +25,35 @@
66709 #define MODULE_ARCH_VERMAGIC ""
66710 #endif
66711
66712 +#ifdef CONFIG_PAX_REFCOUNT
66713 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66714 +#else
66715 +#define MODULE_PAX_REFCOUNT ""
66716 +#endif
66717 +
66718 +#ifdef CONSTIFY_PLUGIN
66719 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66720 +#else
66721 +#define MODULE_CONSTIFY_PLUGIN ""
66722 +#endif
66723 +
66724 +#ifdef STACKLEAK_PLUGIN
66725 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66726 +#else
66727 +#define MODULE_STACKLEAK_PLUGIN ""
66728 +#endif
66729 +
66730 +#ifdef CONFIG_GRKERNSEC
66731 +#define MODULE_GRSEC "GRSEC "
66732 +#else
66733 +#define MODULE_GRSEC ""
66734 +#endif
66735 +
66736 #define VERMAGIC_STRING \
66737 UTS_RELEASE " " \
66738 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66739 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66740 - MODULE_ARCH_VERMAGIC
66741 + MODULE_ARCH_VERMAGIC \
66742 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66743 + MODULE_GRSEC
66744
66745 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66746 index 6071e91..ca6a489 100644
66747 --- a/include/linux/vmalloc.h
66748 +++ b/include/linux/vmalloc.h
66749 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66750 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66751 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66752 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66753 +
66754 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66755 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66756 +#endif
66757 +
66758 /* bits [20..32] reserved for arch specific ioremap internals */
66759
66760 /*
66761 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66762 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66763 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66764 unsigned long start, unsigned long end, gfp_t gfp_mask,
66765 - pgprot_t prot, int node, const void *caller);
66766 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66767 extern void vfree(const void *addr);
66768
66769 extern void *vmap(struct page **pages, unsigned int count,
66770 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66771 extern void free_vm_area(struct vm_struct *area);
66772
66773 /* for /dev/kmem */
66774 -extern long vread(char *buf, char *addr, unsigned long count);
66775 -extern long vwrite(char *buf, char *addr, unsigned long count);
66776 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66777 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66778
66779 /*
66780 * Internals. Dont't use..
66781 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66782 index 92a86b2..1d9eb3c 100644
66783 --- a/include/linux/vmstat.h
66784 +++ b/include/linux/vmstat.h
66785 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66786 /*
66787 * Zone based page accounting with per cpu differentials.
66788 */
66789 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66790 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66791
66792 static inline void zone_page_state_add(long x, struct zone *zone,
66793 enum zone_stat_item item)
66794 {
66795 - atomic_long_add(x, &zone->vm_stat[item]);
66796 - atomic_long_add(x, &vm_stat[item]);
66797 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66798 + atomic_long_add_unchecked(x, &vm_stat[item]);
66799 }
66800
66801 static inline unsigned long global_page_state(enum zone_stat_item item)
66802 {
66803 - long x = atomic_long_read(&vm_stat[item]);
66804 + long x = atomic_long_read_unchecked(&vm_stat[item]);
66805 #ifdef CONFIG_SMP
66806 if (x < 0)
66807 x = 0;
66808 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66809 static inline unsigned long zone_page_state(struct zone *zone,
66810 enum zone_stat_item item)
66811 {
66812 - long x = atomic_long_read(&zone->vm_stat[item]);
66813 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66814 #ifdef CONFIG_SMP
66815 if (x < 0)
66816 x = 0;
66817 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66818 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66819 enum zone_stat_item item)
66820 {
66821 - long x = atomic_long_read(&zone->vm_stat[item]);
66822 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66823
66824 #ifdef CONFIG_SMP
66825 int cpu;
66826 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66827
66828 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66829 {
66830 - atomic_long_inc(&zone->vm_stat[item]);
66831 - atomic_long_inc(&vm_stat[item]);
66832 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
66833 + atomic_long_inc_unchecked(&vm_stat[item]);
66834 }
66835
66836 static inline void __inc_zone_page_state(struct page *page,
66837 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66838
66839 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66840 {
66841 - atomic_long_dec(&zone->vm_stat[item]);
66842 - atomic_long_dec(&vm_stat[item]);
66843 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
66844 + atomic_long_dec_unchecked(&vm_stat[item]);
66845 }
66846
66847 static inline void __dec_zone_page_state(struct page *page,
66848 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66849 index 95d1c91..6798cca 100644
66850 --- a/include/media/v4l2-dev.h
66851 +++ b/include/media/v4l2-dev.h
66852 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
66853 int (*mmap) (struct file *, struct vm_area_struct *);
66854 int (*open) (struct file *);
66855 int (*release) (struct file *);
66856 -};
66857 +} __do_const;
66858
66859 /*
66860 * Newer version of video_device, handled by videodev2.c
66861 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66862 index e48b571..7e40de4 100644
66863 --- a/include/media/v4l2-ioctl.h
66864 +++ b/include/media/v4l2-ioctl.h
66865 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66866 bool valid_prio, int cmd, void *arg);
66867 };
66868
66869 -
66870 /* v4l debugging and diagnostics */
66871
66872 /* Debug bitmask flags to be used on V4L2 */
66873 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66874 index 9e5425b..8136ffc 100644
66875 --- a/include/net/caif/cfctrl.h
66876 +++ b/include/net/caif/cfctrl.h
66877 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
66878 void (*radioset_rsp)(void);
66879 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66880 struct cflayer *client_layer);
66881 -};
66882 +} __no_const;
66883
66884 /* Link Setup Parameters for CAIF-Links. */
66885 struct cfctrl_link_param {
66886 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
66887 struct cfctrl {
66888 struct cfsrvl serv;
66889 struct cfctrl_rsp res;
66890 - atomic_t req_seq_no;
66891 - atomic_t rsp_seq_no;
66892 + atomic_unchecked_t req_seq_no;
66893 + atomic_unchecked_t rsp_seq_no;
66894 struct list_head list;
66895 /* Protects from simultaneous access to first_req list */
66896 spinlock_t info_list_lock;
66897 diff --git a/include/net/flow.h b/include/net/flow.h
66898 index 628e11b..4c475df 100644
66899 --- a/include/net/flow.h
66900 +++ b/include/net/flow.h
66901 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66902
66903 extern void flow_cache_flush(void);
66904 extern void flow_cache_flush_deferred(void);
66905 -extern atomic_t flow_cache_genid;
66906 +extern atomic_unchecked_t flow_cache_genid;
66907
66908 #endif
66909 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66910 index e5062c9..48a9a4b 100644
66911 --- a/include/net/gro_cells.h
66912 +++ b/include/net/gro_cells.h
66913 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66914 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66915
66916 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66917 - atomic_long_inc(&dev->rx_dropped);
66918 + atomic_long_inc_unchecked(&dev->rx_dropped);
66919 kfree_skb(skb);
66920 return;
66921 }
66922 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
66923 int i;
66924
66925 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
66926 - gcells->cells = kcalloc(sizeof(struct gro_cell),
66927 - gcells->gro_cells_mask + 1,
66928 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
66929 + sizeof(struct gro_cell),
66930 GFP_KERNEL);
66931 if (!gcells->cells)
66932 return -ENOMEM;
66933 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66934 index 1832927..ce39aea 100644
66935 --- a/include/net/inet_connection_sock.h
66936 +++ b/include/net/inet_connection_sock.h
66937 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66938 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66939 int (*bind_conflict)(const struct sock *sk,
66940 const struct inet_bind_bucket *tb, bool relax);
66941 -};
66942 +} __do_const;
66943
66944 /** inet_connection_sock - INET connection oriented sock
66945 *
66946 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66947 index 53f464d..ba76aaa 100644
66948 --- a/include/net/inetpeer.h
66949 +++ b/include/net/inetpeer.h
66950 @@ -47,8 +47,8 @@ struct inet_peer {
66951 */
66952 union {
66953 struct {
66954 - atomic_t rid; /* Frag reception counter */
66955 - atomic_t ip_id_count; /* IP ID for the next packet */
66956 + atomic_unchecked_t rid; /* Frag reception counter */
66957 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
66958 };
66959 struct rcu_head rcu;
66960 struct inet_peer *gc_next;
66961 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
66962 more++;
66963 inet_peer_refcheck(p);
66964 do {
66965 - old = atomic_read(&p->ip_id_count);
66966 + old = atomic_read_unchecked(&p->ip_id_count);
66967 new = old + more;
66968 if (!new)
66969 new = 1;
66970 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
66971 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
66972 return new;
66973 }
66974
66975 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
66976 index 9497be1..5a4fafe 100644
66977 --- a/include/net/ip_fib.h
66978 +++ b/include/net/ip_fib.h
66979 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
66980
66981 #define FIB_RES_SADDR(net, res) \
66982 ((FIB_RES_NH(res).nh_saddr_genid == \
66983 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
66984 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
66985 FIB_RES_NH(res).nh_saddr : \
66986 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
66987 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
66988 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
66989 index ee75ccd..2cc2b95 100644
66990 --- a/include/net/ip_vs.h
66991 +++ b/include/net/ip_vs.h
66992 @@ -510,7 +510,7 @@ struct ip_vs_conn {
66993 struct ip_vs_conn *control; /* Master control connection */
66994 atomic_t n_control; /* Number of controlled ones */
66995 struct ip_vs_dest *dest; /* real server */
66996 - atomic_t in_pkts; /* incoming packet counter */
66997 + atomic_unchecked_t in_pkts; /* incoming packet counter */
66998
66999 /* packet transmitter for different forwarding methods. If it
67000 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67001 @@ -648,7 +648,7 @@ struct ip_vs_dest {
67002 __be16 port; /* port number of the server */
67003 union nf_inet_addr addr; /* IP address of the server */
67004 volatile unsigned int flags; /* dest status flags */
67005 - atomic_t conn_flags; /* flags to copy to conn */
67006 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67007 atomic_t weight; /* server weight */
67008
67009 atomic_t refcnt; /* reference counter */
67010 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67011 index 80ffde3..968b0f4 100644
67012 --- a/include/net/irda/ircomm_tty.h
67013 +++ b/include/net/irda/ircomm_tty.h
67014 @@ -35,6 +35,7 @@
67015 #include <linux/termios.h>
67016 #include <linux/timer.h>
67017 #include <linux/tty.h> /* struct tty_struct */
67018 +#include <asm/local.h>
67019
67020 #include <net/irda/irias_object.h>
67021 #include <net/irda/ircomm_core.h>
67022 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67023 index cc7c197..9f2da2a 100644
67024 --- a/include/net/iucv/af_iucv.h
67025 +++ b/include/net/iucv/af_iucv.h
67026 @@ -141,7 +141,7 @@ struct iucv_sock {
67027 struct iucv_sock_list {
67028 struct hlist_head head;
67029 rwlock_t lock;
67030 - atomic_t autobind_name;
67031 + atomic_unchecked_t autobind_name;
67032 };
67033
67034 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67035 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67036 index 0dab173..1b76af0 100644
67037 --- a/include/net/neighbour.h
67038 +++ b/include/net/neighbour.h
67039 @@ -123,7 +123,7 @@ struct neigh_ops {
67040 void (*error_report)(struct neighbour *, struct sk_buff *);
67041 int (*output)(struct neighbour *, struct sk_buff *);
67042 int (*connected_output)(struct neighbour *, struct sk_buff *);
67043 -};
67044 +} __do_const;
67045
67046 struct pneigh_entry {
67047 struct pneigh_entry *next;
67048 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67049 index 95e6466..251016d 100644
67050 --- a/include/net/net_namespace.h
67051 +++ b/include/net/net_namespace.h
67052 @@ -110,7 +110,7 @@ struct net {
67053 #endif
67054 struct netns_ipvs *ipvs;
67055 struct sock *diag_nlsk;
67056 - atomic_t rt_genid;
67057 + atomic_unchecked_t rt_genid;
67058 };
67059
67060 /*
67061 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67062
67063 static inline int rt_genid(struct net *net)
67064 {
67065 - return atomic_read(&net->rt_genid);
67066 + return atomic_read_unchecked(&net->rt_genid);
67067 }
67068
67069 static inline void rt_genid_bump(struct net *net)
67070 {
67071 - atomic_inc(&net->rt_genid);
67072 + atomic_inc_unchecked(&net->rt_genid);
67073 }
67074
67075 #endif /* __NET_NET_NAMESPACE_H */
67076 diff --git a/include/net/netdma.h b/include/net/netdma.h
67077 index 8ba8ce2..99b7fff 100644
67078 --- a/include/net/netdma.h
67079 +++ b/include/net/netdma.h
67080 @@ -24,7 +24,7 @@
67081 #include <linux/dmaengine.h>
67082 #include <linux/skbuff.h>
67083
67084 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67085 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67086 struct sk_buff *skb, int offset, struct iovec *to,
67087 size_t len, struct dma_pinned_list *pinned_list);
67088
67089 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67090 index 252fd10..aa1421f 100644
67091 --- a/include/net/netfilter/nf_queue.h
67092 +++ b/include/net/netfilter/nf_queue.h
67093 @@ -22,7 +22,7 @@ struct nf_queue_handler {
67094 int (*outfn)(struct nf_queue_entry *entry,
67095 unsigned int queuenum);
67096 char *name;
67097 -};
67098 +} __do_const;
67099
67100 extern int nf_register_queue_handler(u_int8_t pf,
67101 const struct nf_queue_handler *qh);
67102 diff --git a/include/net/netlink.h b/include/net/netlink.h
67103 index 9690b0f..87aded7 100644
67104 --- a/include/net/netlink.h
67105 +++ b/include/net/netlink.h
67106 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67107 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67108 {
67109 if (mark)
67110 - skb_trim(skb, (unsigned char *) mark - skb->data);
67111 + skb_trim(skb, (const unsigned char *) mark - skb->data);
67112 }
67113
67114 /**
67115 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67116 index 2ae2b83..dbdc85e 100644
67117 --- a/include/net/netns/ipv4.h
67118 +++ b/include/net/netns/ipv4.h
67119 @@ -64,7 +64,7 @@ struct netns_ipv4 {
67120 kgid_t sysctl_ping_group_range[2];
67121 long sysctl_tcp_mem[3];
67122
67123 - atomic_t dev_addr_genid;
67124 + atomic_unchecked_t dev_addr_genid;
67125
67126 #ifdef CONFIG_IP_MROUTE
67127 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67128 diff --git a/include/net/protocol.h b/include/net/protocol.h
67129 index 929528c..c84d4f6 100644
67130 --- a/include/net/protocol.h
67131 +++ b/include/net/protocol.h
67132 @@ -48,7 +48,7 @@ struct net_protocol {
67133 int (*gro_complete)(struct sk_buff *skb);
67134 unsigned int no_policy:1,
67135 netns_ok:1;
67136 -};
67137 +} __do_const;
67138
67139 #if IS_ENABLED(CONFIG_IPV6)
67140 struct inet6_protocol {
67141 @@ -69,7 +69,7 @@ struct inet6_protocol {
67142 int (*gro_complete)(struct sk_buff *skb);
67143
67144 unsigned int flags; /* INET6_PROTO_xxx */
67145 -};
67146 +} __do_const;
67147
67148 #define INET6_PROTO_NOPOLICY 0x1
67149 #define INET6_PROTO_FINAL 0x2
67150 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67151 index 9c6414f..fbd0524 100644
67152 --- a/include/net/sctp/sctp.h
67153 +++ b/include/net/sctp/sctp.h
67154 @@ -318,9 +318,9 @@ do { \
67155
67156 #else /* SCTP_DEBUG */
67157
67158 -#define SCTP_DEBUG_PRINTK(whatever...)
67159 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67160 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67161 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67162 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67163 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67164 #define SCTP_ENABLE_DEBUG
67165 #define SCTP_DISABLE_DEBUG
67166 #define SCTP_ASSERT(expr, str, func)
67167 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67168 index 64158aa..b65533c 100644
67169 --- a/include/net/sctp/structs.h
67170 +++ b/include/net/sctp/structs.h
67171 @@ -496,7 +496,7 @@ struct sctp_af {
67172 int sockaddr_len;
67173 sa_family_t sa_family;
67174 struct list_head list;
67175 -};
67176 +} __do_const;
67177
67178 struct sctp_af *sctp_get_af_specific(sa_family_t);
67179 int sctp_register_af(struct sctp_af *);
67180 @@ -516,7 +516,7 @@ struct sctp_pf {
67181 struct sctp_association *asoc);
67182 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67183 struct sctp_af *af;
67184 -};
67185 +} __do_const;
67186
67187
67188 /* Structure to track chunk fragments that have been acked, but peer
67189 diff --git a/include/net/sock.h b/include/net/sock.h
67190 index c945fba..e162e56 100644
67191 --- a/include/net/sock.h
67192 +++ b/include/net/sock.h
67193 @@ -304,7 +304,7 @@ struct sock {
67194 #ifdef CONFIG_RPS
67195 __u32 sk_rxhash;
67196 #endif
67197 - atomic_t sk_drops;
67198 + atomic_unchecked_t sk_drops;
67199 int sk_rcvbuf;
67200
67201 struct sk_filter __rcu *sk_filter;
67202 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67203 }
67204
67205 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67206 - char __user *from, char *to,
67207 + char __user *from, unsigned char *to,
67208 int copy, int offset)
67209 {
67210 if (skb->ip_summed == CHECKSUM_NONE) {
67211 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67212 }
67213 }
67214
67215 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67216 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67217
67218 /**
67219 * sk_page_frag - return an appropriate page_frag
67220 diff --git a/include/net/tcp.h b/include/net/tcp.h
67221 index 4af45e3..af97861 100644
67222 --- a/include/net/tcp.h
67223 +++ b/include/net/tcp.h
67224 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67225 extern void tcp_xmit_retransmit_queue(struct sock *);
67226 extern void tcp_simple_retransmit(struct sock *);
67227 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67228 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67229 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67230
67231 extern void tcp_send_probe0(struct sock *);
67232 extern void tcp_send_partial(struct sock *);
67233 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
67234 struct inet6_skb_parm h6;
67235 #endif
67236 } header; /* For incoming frames */
67237 - __u32 seq; /* Starting sequence number */
67238 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67239 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
67240 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67241 __u32 when; /* used to compute rtt's */
67242 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67243
67244 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
67245
67246 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67247 /* 1 byte hole */
67248 - __u32 ack_seq; /* Sequence number ACK'd */
67249 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67250 };
67251
67252 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67253 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67254 index 63445ed..74ef61d 100644
67255 --- a/include/net/xfrm.h
67256 +++ b/include/net/xfrm.h
67257 @@ -423,7 +423,7 @@ struct xfrm_mode {
67258 struct module *owner;
67259 unsigned int encap;
67260 int flags;
67261 -};
67262 +} __do_const;
67263
67264 /* Flags for xfrm_mode. */
67265 enum {
67266 @@ -514,7 +514,7 @@ struct xfrm_policy {
67267 struct timer_list timer;
67268
67269 struct flow_cache_object flo;
67270 - atomic_t genid;
67271 + atomic_unchecked_t genid;
67272 u32 priority;
67273 u32 index;
67274 struct xfrm_mark mark;
67275 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67276 index 1a046b1..ee0bef0 100644
67277 --- a/include/rdma/iw_cm.h
67278 +++ b/include/rdma/iw_cm.h
67279 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
67280 int backlog);
67281
67282 int (*destroy_listen)(struct iw_cm_id *cm_id);
67283 -};
67284 +} __no_const;
67285
67286 /**
67287 * iw_create_cm_id - Create an IW CM identifier.
67288 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67289 index 399162b..b337f1a 100644
67290 --- a/include/scsi/libfc.h
67291 +++ b/include/scsi/libfc.h
67292 @@ -762,6 +762,7 @@ struct libfc_function_template {
67293 */
67294 void (*disc_stop_final) (struct fc_lport *);
67295 };
67296 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67297
67298 /**
67299 * struct fc_disc - Discovery context
67300 @@ -866,7 +867,7 @@ struct fc_lport {
67301 struct fc_vport *vport;
67302
67303 /* Operational Information */
67304 - struct libfc_function_template tt;
67305 + libfc_function_template_no_const tt;
67306 u8 link_up;
67307 u8 qfull;
67308 enum fc_lport_state state;
67309 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67310 index 55367b0..d97bd2a 100644
67311 --- a/include/scsi/scsi_device.h
67312 +++ b/include/scsi/scsi_device.h
67313 @@ -169,9 +169,9 @@ struct scsi_device {
67314 unsigned int max_device_blocked; /* what device_blocked counts down from */
67315 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67316
67317 - atomic_t iorequest_cnt;
67318 - atomic_t iodone_cnt;
67319 - atomic_t ioerr_cnt;
67320 + atomic_unchecked_t iorequest_cnt;
67321 + atomic_unchecked_t iodone_cnt;
67322 + atomic_unchecked_t ioerr_cnt;
67323
67324 struct device sdev_gendev,
67325 sdev_dev;
67326 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67327 index b797e8f..8e2c3aa 100644
67328 --- a/include/scsi/scsi_transport_fc.h
67329 +++ b/include/scsi/scsi_transport_fc.h
67330 @@ -751,7 +751,8 @@ struct fc_function_template {
67331 unsigned long show_host_system_hostname:1;
67332
67333 unsigned long disable_target_scan:1;
67334 -};
67335 +} __do_const;
67336 +typedef struct fc_function_template __no_const fc_function_template_no_const;
67337
67338
67339 /**
67340 diff --git a/include/sound/soc.h b/include/sound/soc.h
67341 index 91244a0..89ca1a7 100644
67342 --- a/include/sound/soc.h
67343 +++ b/include/sound/soc.h
67344 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67345 /* probe ordering - for components with runtime dependencies */
67346 int probe_order;
67347 int remove_order;
67348 -};
67349 +} __do_const;
67350
67351 /* SoC platform interface */
67352 struct snd_soc_platform_driver {
67353 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67354 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67355 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67356 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67357 -};
67358 +} __do_const;
67359
67360 struct snd_soc_platform {
67361 const char *name;
67362 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67363 index fca8bbe..c0242ea 100644
67364 --- a/include/target/target_core_base.h
67365 +++ b/include/target/target_core_base.h
67366 @@ -760,7 +760,7 @@ struct se_device {
67367 spinlock_t stats_lock;
67368 /* Active commands on this virtual SE device */
67369 atomic_t simple_cmds;
67370 - atomic_t dev_ordered_id;
67371 + atomic_unchecked_t dev_ordered_id;
67372 atomic_t dev_ordered_sync;
67373 atomic_t dev_qf_count;
67374 struct se_obj dev_obj;
67375 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67376 new file mode 100644
67377 index 0000000..fb634b7
67378 --- /dev/null
67379 +++ b/include/trace/events/fs.h
67380 @@ -0,0 +1,53 @@
67381 +#undef TRACE_SYSTEM
67382 +#define TRACE_SYSTEM fs
67383 +
67384 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67385 +#define _TRACE_FS_H
67386 +
67387 +#include <linux/fs.h>
67388 +#include <linux/tracepoint.h>
67389 +
67390 +TRACE_EVENT(do_sys_open,
67391 +
67392 + TP_PROTO(const char *filename, int flags, int mode),
67393 +
67394 + TP_ARGS(filename, flags, mode),
67395 +
67396 + TP_STRUCT__entry(
67397 + __string( filename, filename )
67398 + __field( int, flags )
67399 + __field( int, mode )
67400 + ),
67401 +
67402 + TP_fast_assign(
67403 + __assign_str(filename, filename);
67404 + __entry->flags = flags;
67405 + __entry->mode = mode;
67406 + ),
67407 +
67408 + TP_printk("\"%s\" %x %o",
67409 + __get_str(filename), __entry->flags, __entry->mode)
67410 +);
67411 +
67412 +TRACE_EVENT(open_exec,
67413 +
67414 + TP_PROTO(const char *filename),
67415 +
67416 + TP_ARGS(filename),
67417 +
67418 + TP_STRUCT__entry(
67419 + __string( filename, filename )
67420 + ),
67421 +
67422 + TP_fast_assign(
67423 + __assign_str(filename, filename);
67424 + ),
67425 +
67426 + TP_printk("\"%s\"",
67427 + __get_str(filename))
67428 +);
67429 +
67430 +#endif /* _TRACE_FS_H */
67431 +
67432 +/* This part must be outside protection */
67433 +#include <trace/define_trace.h>
67434 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67435 index 1c09820..7f5ec79 100644
67436 --- a/include/trace/events/irq.h
67437 +++ b/include/trace/events/irq.h
67438 @@ -36,7 +36,7 @@ struct softirq_action;
67439 */
67440 TRACE_EVENT(irq_handler_entry,
67441
67442 - TP_PROTO(int irq, struct irqaction *action),
67443 + TP_PROTO(int irq, const struct irqaction *action),
67444
67445 TP_ARGS(irq, action),
67446
67447 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67448 */
67449 TRACE_EVENT(irq_handler_exit,
67450
67451 - TP_PROTO(int irq, struct irqaction *action, int ret),
67452 + TP_PROTO(int irq, const struct irqaction *action, int ret),
67453
67454 TP_ARGS(irq, action, ret),
67455
67456 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67457 index 7caf44c..23c6f27 100644
67458 --- a/include/uapi/linux/a.out.h
67459 +++ b/include/uapi/linux/a.out.h
67460 @@ -39,6 +39,14 @@ enum machine_type {
67461 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67462 };
67463
67464 +/* Constants for the N_FLAGS field */
67465 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67466 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67467 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67468 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67469 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67470 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67471 +
67472 #if !defined (N_MAGIC)
67473 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67474 #endif
67475 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67476 index d876736..b36014e 100644
67477 --- a/include/uapi/linux/byteorder/little_endian.h
67478 +++ b/include/uapi/linux/byteorder/little_endian.h
67479 @@ -42,51 +42,51 @@
67480
67481 static inline __le64 __cpu_to_le64p(const __u64 *p)
67482 {
67483 - return (__force __le64)*p;
67484 + return (__force const __le64)*p;
67485 }
67486 static inline __u64 __le64_to_cpup(const __le64 *p)
67487 {
67488 - return (__force __u64)*p;
67489 + return (__force const __u64)*p;
67490 }
67491 static inline __le32 __cpu_to_le32p(const __u32 *p)
67492 {
67493 - return (__force __le32)*p;
67494 + return (__force const __le32)*p;
67495 }
67496 static inline __u32 __le32_to_cpup(const __le32 *p)
67497 {
67498 - return (__force __u32)*p;
67499 + return (__force const __u32)*p;
67500 }
67501 static inline __le16 __cpu_to_le16p(const __u16 *p)
67502 {
67503 - return (__force __le16)*p;
67504 + return (__force const __le16)*p;
67505 }
67506 static inline __u16 __le16_to_cpup(const __le16 *p)
67507 {
67508 - return (__force __u16)*p;
67509 + return (__force const __u16)*p;
67510 }
67511 static inline __be64 __cpu_to_be64p(const __u64 *p)
67512 {
67513 - return (__force __be64)__swab64p(p);
67514 + return (__force const __be64)__swab64p(p);
67515 }
67516 static inline __u64 __be64_to_cpup(const __be64 *p)
67517 {
67518 - return __swab64p((__u64 *)p);
67519 + return __swab64p((const __u64 *)p);
67520 }
67521 static inline __be32 __cpu_to_be32p(const __u32 *p)
67522 {
67523 - return (__force __be32)__swab32p(p);
67524 + return (__force const __be32)__swab32p(p);
67525 }
67526 static inline __u32 __be32_to_cpup(const __be32 *p)
67527 {
67528 - return __swab32p((__u32 *)p);
67529 + return __swab32p((const __u32 *)p);
67530 }
67531 static inline __be16 __cpu_to_be16p(const __u16 *p)
67532 {
67533 - return (__force __be16)__swab16p(p);
67534 + return (__force const __be16)__swab16p(p);
67535 }
67536 static inline __u16 __be16_to_cpup(const __be16 *p)
67537 {
67538 - return __swab16p((__u16 *)p);
67539 + return __swab16p((const __u16 *)p);
67540 }
67541 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67542 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67543 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67544 index 126a817..d522bd1 100644
67545 --- a/include/uapi/linux/elf.h
67546 +++ b/include/uapi/linux/elf.h
67547 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67548 #define PT_GNU_EH_FRAME 0x6474e550
67549
67550 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67551 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67552 +
67553 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67554 +
67555 +/* Constants for the e_flags field */
67556 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67557 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67558 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67559 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67560 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67561 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67562
67563 /*
67564 * Extended Numbering
67565 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67566 #define DT_DEBUG 21
67567 #define DT_TEXTREL 22
67568 #define DT_JMPREL 23
67569 +#define DT_FLAGS 30
67570 + #define DF_TEXTREL 0x00000004
67571 #define DT_ENCODING 32
67572 #define OLD_DT_LOOS 0x60000000
67573 #define DT_LOOS 0x6000000d
67574 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67575 #define PF_W 0x2
67576 #define PF_X 0x1
67577
67578 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67579 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67580 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67581 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67582 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67583 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67584 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67585 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67586 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67587 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67588 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67589 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67590 +
67591 typedef struct elf32_phdr{
67592 Elf32_Word p_type;
67593 Elf32_Off p_offset;
67594 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67595 #define EI_OSABI 7
67596 #define EI_PAD 8
67597
67598 +#define EI_PAX 14
67599 +
67600 #define ELFMAG0 0x7f /* EI_MAG */
67601 #define ELFMAG1 'E'
67602 #define ELFMAG2 'L'
67603 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67604 index aa169c4..6a2771d 100644
67605 --- a/include/uapi/linux/personality.h
67606 +++ b/include/uapi/linux/personality.h
67607 @@ -30,6 +30,7 @@ enum {
67608 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67609 ADDR_NO_RANDOMIZE | \
67610 ADDR_COMPAT_LAYOUT | \
67611 + ADDR_LIMIT_3GB | \
67612 MMAP_PAGE_ZERO)
67613
67614 /*
67615 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67616 index 7530e74..e714828 100644
67617 --- a/include/uapi/linux/screen_info.h
67618 +++ b/include/uapi/linux/screen_info.h
67619 @@ -43,7 +43,8 @@ struct screen_info {
67620 __u16 pages; /* 0x32 */
67621 __u16 vesa_attributes; /* 0x34 */
67622 __u32 capabilities; /* 0x36 */
67623 - __u8 _reserved[6]; /* 0x3a */
67624 + __u16 vesapm_size; /* 0x3a */
67625 + __u8 _reserved[4]; /* 0x3c */
67626 } __attribute__((packed));
67627
67628 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67629 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67630 index 6d67213..8dab561 100644
67631 --- a/include/uapi/linux/sysctl.h
67632 +++ b/include/uapi/linux/sysctl.h
67633 @@ -155,7 +155,11 @@ enum
67634 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67635 };
67636
67637 -
67638 +#ifdef CONFIG_PAX_SOFTMODE
67639 +enum {
67640 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67641 +};
67642 +#endif
67643
67644 /* CTL_VM names: */
67645 enum
67646 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67647 index 26607bd..588b65f 100644
67648 --- a/include/uapi/linux/xattr.h
67649 +++ b/include/uapi/linux/xattr.h
67650 @@ -60,5 +60,9 @@
67651 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67652 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67653
67654 +/* User namespace */
67655 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67656 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67657 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67658
67659 #endif /* _UAPI_LINUX_XATTR_H */
67660 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67661 index f9466fa..f4e2b81 100644
67662 --- a/include/video/udlfb.h
67663 +++ b/include/video/udlfb.h
67664 @@ -53,10 +53,10 @@ struct dlfb_data {
67665 u32 pseudo_palette[256];
67666 int blank_mode; /*one of FB_BLANK_ */
67667 /* blit-only rendering path metrics, exposed through sysfs */
67668 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67669 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67670 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67671 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67672 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67673 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67674 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67675 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67676 };
67677
67678 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67679 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67680 index 0993a22..32ba2fe 100644
67681 --- a/include/video/uvesafb.h
67682 +++ b/include/video/uvesafb.h
67683 @@ -177,6 +177,7 @@ struct uvesafb_par {
67684 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67685 u8 pmi_setpal; /* PMI for palette changes */
67686 u16 *pmi_base; /* protected mode interface location */
67687 + u8 *pmi_code; /* protected mode code location */
67688 void *pmi_start;
67689 void *pmi_pal;
67690 u8 *vbe_state_orig; /*
67691 diff --git a/init/Kconfig b/init/Kconfig
67692 index 6fdd6e3..5b01610 100644
67693 --- a/init/Kconfig
67694 +++ b/init/Kconfig
67695 @@ -925,6 +925,7 @@ endif # CGROUPS
67696
67697 config CHECKPOINT_RESTORE
67698 bool "Checkpoint/restore support" if EXPERT
67699 + depends on !GRKERNSEC
67700 default n
67701 help
67702 Enables additional kernel features in a sake of checkpoint/restore.
67703 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67704 depends on OCFS2_FS = n
67705 depends on XFS_FS = n
67706
67707 + depends on GRKERNSEC = n
67708 +
67709 config UIDGID_STRICT_TYPE_CHECKS
67710 bool "Require conversions between uid/gids and their internal representation"
67711 depends on UIDGID_CONVERTED
67712 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67713
67714 config COMPAT_BRK
67715 bool "Disable heap randomization"
67716 - default y
67717 + default n
67718 help
67719 Randomizing heap placement makes heap exploits harder, but it
67720 also breaks ancient binaries (including anything libc5 based).
67721 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67722 config STOP_MACHINE
67723 bool
67724 default y
67725 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67726 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67727 help
67728 Need stop_machine() primitive.
67729
67730 diff --git a/init/Makefile b/init/Makefile
67731 index 7bc47ee..6da2dc7 100644
67732 --- a/init/Makefile
67733 +++ b/init/Makefile
67734 @@ -2,6 +2,9 @@
67735 # Makefile for the linux kernel.
67736 #
67737
67738 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67739 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67740 +
67741 obj-y := main.o version.o mounts.o
67742 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67743 obj-y += noinitramfs.o
67744 diff --git a/init/do_mounts.c b/init/do_mounts.c
67745 index f8a6642..4e5ee1b 100644
67746 --- a/init/do_mounts.c
67747 +++ b/init/do_mounts.c
67748 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67749 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67750 {
67751 struct super_block *s;
67752 - int err = sys_mount(name, "/root", fs, flags, data);
67753 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67754 if (err)
67755 return err;
67756
67757 - sys_chdir("/root");
67758 + sys_chdir((const char __force_user *)"/root");
67759 s = current->fs->pwd.dentry->d_sb;
67760 ROOT_DEV = s->s_dev;
67761 printk(KERN_INFO
67762 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67763 va_start(args, fmt);
67764 vsprintf(buf, fmt, args);
67765 va_end(args);
67766 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67767 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67768 if (fd >= 0) {
67769 sys_ioctl(fd, FDEJECT, 0);
67770 sys_close(fd);
67771 }
67772 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67773 - fd = sys_open("/dev/console", O_RDWR, 0);
67774 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67775 if (fd >= 0) {
67776 sys_ioctl(fd, TCGETS, (long)&termios);
67777 termios.c_lflag &= ~ICANON;
67778 sys_ioctl(fd, TCSETSF, (long)&termios);
67779 - sys_read(fd, &c, 1);
67780 + sys_read(fd, (char __user *)&c, 1);
67781 termios.c_lflag |= ICANON;
67782 sys_ioctl(fd, TCSETSF, (long)&termios);
67783 sys_close(fd);
67784 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67785 mount_root();
67786 out:
67787 devtmpfs_mount("dev");
67788 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
67789 - sys_chroot(".");
67790 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67791 + sys_chroot((const char __force_user *)".");
67792 }
67793 diff --git a/init/do_mounts.h b/init/do_mounts.h
67794 index f5b978a..69dbfe8 100644
67795 --- a/init/do_mounts.h
67796 +++ b/init/do_mounts.h
67797 @@ -15,15 +15,15 @@ extern int root_mountflags;
67798
67799 static inline int create_dev(char *name, dev_t dev)
67800 {
67801 - sys_unlink(name);
67802 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67803 + sys_unlink((char __force_user *)name);
67804 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67805 }
67806
67807 #if BITS_PER_LONG == 32
67808 static inline u32 bstat(char *name)
67809 {
67810 struct stat64 stat;
67811 - if (sys_stat64(name, &stat) != 0)
67812 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67813 return 0;
67814 if (!S_ISBLK(stat.st_mode))
67815 return 0;
67816 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67817 static inline u32 bstat(char *name)
67818 {
67819 struct stat stat;
67820 - if (sys_newstat(name, &stat) != 0)
67821 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67822 return 0;
67823 if (!S_ISBLK(stat.st_mode))
67824 return 0;
67825 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67826 index f9acf71..1e19144 100644
67827 --- a/init/do_mounts_initrd.c
67828 +++ b/init/do_mounts_initrd.c
67829 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67830 create_dev("/dev/root.old", Root_RAM0);
67831 /* mount initrd on rootfs' /root */
67832 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67833 - sys_mkdir("/old", 0700);
67834 - sys_chdir("/old");
67835 + sys_mkdir((const char __force_user *)"/old", 0700);
67836 + sys_chdir((const char __force_user *)"/old");
67837
67838 /*
67839 * In case that a resume from disk is carried out by linuxrc or one of
67840 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67841 current->flags &= ~PF_FREEZER_SKIP;
67842
67843 /* move initrd to rootfs' /old */
67844 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
67845 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67846 /* switch root and cwd back to / of rootfs */
67847 - sys_chroot("..");
67848 + sys_chroot((const char __force_user *)"..");
67849
67850 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67851 - sys_chdir("/old");
67852 + sys_chdir((const char __force_user *)"/old");
67853 return;
67854 }
67855
67856 - sys_chdir("/");
67857 + sys_chdir((const char __force_user *)"/");
67858 ROOT_DEV = new_decode_dev(real_root_dev);
67859 mount_root();
67860
67861 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67862 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67863 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67864 if (!error)
67865 printk("okay\n");
67866 else {
67867 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
67868 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67869 if (error == -ENOENT)
67870 printk("/initrd does not exist. Ignored.\n");
67871 else
67872 printk("failed\n");
67873 printk(KERN_NOTICE "Unmounting old root\n");
67874 - sys_umount("/old", MNT_DETACH);
67875 + sys_umount((char __force_user *)"/old", MNT_DETACH);
67876 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
67877 if (fd < 0) {
67878 error = fd;
67879 @@ -120,11 +120,11 @@ int __init initrd_load(void)
67880 * mounted in the normal path.
67881 */
67882 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
67883 - sys_unlink("/initrd.image");
67884 + sys_unlink((const char __force_user *)"/initrd.image");
67885 handle_initrd();
67886 return 1;
67887 }
67888 }
67889 - sys_unlink("/initrd.image");
67890 + sys_unlink((const char __force_user *)"/initrd.image");
67891 return 0;
67892 }
67893 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
67894 index 8cb6db5..d729f50 100644
67895 --- a/init/do_mounts_md.c
67896 +++ b/init/do_mounts_md.c
67897 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
67898 partitioned ? "_d" : "", minor,
67899 md_setup_args[ent].device_names);
67900
67901 - fd = sys_open(name, 0, 0);
67902 + fd = sys_open((char __force_user *)name, 0, 0);
67903 if (fd < 0) {
67904 printk(KERN_ERR "md: open failed - cannot start "
67905 "array %s\n", name);
67906 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
67907 * array without it
67908 */
67909 sys_close(fd);
67910 - fd = sys_open(name, 0, 0);
67911 + fd = sys_open((char __force_user *)name, 0, 0);
67912 sys_ioctl(fd, BLKRRPART, 0);
67913 }
67914 sys_close(fd);
67915 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
67916
67917 wait_for_device_probe();
67918
67919 - fd = sys_open("/dev/md0", 0, 0);
67920 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
67921 if (fd >= 0) {
67922 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
67923 sys_close(fd);
67924 diff --git a/init/init_task.c b/init/init_task.c
67925 index 8b2f399..f0797c9 100644
67926 --- a/init/init_task.c
67927 +++ b/init/init_task.c
67928 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
67929 * Initial thread structure. Alignment of this is handled by a special
67930 * linker map entry.
67931 */
67932 +#ifdef CONFIG_X86
67933 +union thread_union init_thread_union __init_task_data;
67934 +#else
67935 union thread_union init_thread_union __init_task_data =
67936 { INIT_THREAD_INFO(init_task) };
67937 +#endif
67938 diff --git a/init/initramfs.c b/init/initramfs.c
67939 index 84c6bf1..8899338 100644
67940 --- a/init/initramfs.c
67941 +++ b/init/initramfs.c
67942 @@ -84,7 +84,7 @@ static void __init free_hash(void)
67943 }
67944 }
67945
67946 -static long __init do_utime(char *filename, time_t mtime)
67947 +static long __init do_utime(char __force_user *filename, time_t mtime)
67948 {
67949 struct timespec t[2];
67950
67951 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
67952 struct dir_entry *de, *tmp;
67953 list_for_each_entry_safe(de, tmp, &dir_list, list) {
67954 list_del(&de->list);
67955 - do_utime(de->name, de->mtime);
67956 + do_utime((char __force_user *)de->name, de->mtime);
67957 kfree(de->name);
67958 kfree(de);
67959 }
67960 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
67961 if (nlink >= 2) {
67962 char *old = find_link(major, minor, ino, mode, collected);
67963 if (old)
67964 - return (sys_link(old, collected) < 0) ? -1 : 1;
67965 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
67966 }
67967 return 0;
67968 }
67969 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
67970 {
67971 struct stat st;
67972
67973 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
67974 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
67975 if (S_ISDIR(st.st_mode))
67976 - sys_rmdir(path);
67977 + sys_rmdir((char __force_user *)path);
67978 else
67979 - sys_unlink(path);
67980 + sys_unlink((char __force_user *)path);
67981 }
67982 }
67983
67984 @@ -315,7 +315,7 @@ static int __init do_name(void)
67985 int openflags = O_WRONLY|O_CREAT;
67986 if (ml != 1)
67987 openflags |= O_TRUNC;
67988 - wfd = sys_open(collected, openflags, mode);
67989 + wfd = sys_open((char __force_user *)collected, openflags, mode);
67990
67991 if (wfd >= 0) {
67992 sys_fchown(wfd, uid, gid);
67993 @@ -327,17 +327,17 @@ static int __init do_name(void)
67994 }
67995 }
67996 } else if (S_ISDIR(mode)) {
67997 - sys_mkdir(collected, mode);
67998 - sys_chown(collected, uid, gid);
67999 - sys_chmod(collected, mode);
68000 + sys_mkdir((char __force_user *)collected, mode);
68001 + sys_chown((char __force_user *)collected, uid, gid);
68002 + sys_chmod((char __force_user *)collected, mode);
68003 dir_add(collected, mtime);
68004 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68005 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68006 if (maybe_link() == 0) {
68007 - sys_mknod(collected, mode, rdev);
68008 - sys_chown(collected, uid, gid);
68009 - sys_chmod(collected, mode);
68010 - do_utime(collected, mtime);
68011 + sys_mknod((char __force_user *)collected, mode, rdev);
68012 + sys_chown((char __force_user *)collected, uid, gid);
68013 + sys_chmod((char __force_user *)collected, mode);
68014 + do_utime((char __force_user *)collected, mtime);
68015 }
68016 }
68017 return 0;
68018 @@ -346,15 +346,15 @@ static int __init do_name(void)
68019 static int __init do_copy(void)
68020 {
68021 if (count >= body_len) {
68022 - sys_write(wfd, victim, body_len);
68023 + sys_write(wfd, (char __force_user *)victim, body_len);
68024 sys_close(wfd);
68025 - do_utime(vcollected, mtime);
68026 + do_utime((char __force_user *)vcollected, mtime);
68027 kfree(vcollected);
68028 eat(body_len);
68029 state = SkipIt;
68030 return 0;
68031 } else {
68032 - sys_write(wfd, victim, count);
68033 + sys_write(wfd, (char __force_user *)victim, count);
68034 body_len -= count;
68035 eat(count);
68036 return 1;
68037 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
68038 {
68039 collected[N_ALIGN(name_len) + body_len] = '\0';
68040 clean_path(collected, 0);
68041 - sys_symlink(collected + N_ALIGN(name_len), collected);
68042 - sys_lchown(collected, uid, gid);
68043 - do_utime(collected, mtime);
68044 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68045 + sys_lchown((char __force_user *)collected, uid, gid);
68046 + do_utime((char __force_user *)collected, mtime);
68047 state = SkipIt;
68048 next_state = Reset;
68049 return 0;
68050 diff --git a/init/main.c b/init/main.c
68051 index 857166f..9df1d8e 100644
68052 --- a/init/main.c
68053 +++ b/init/main.c
68054 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68055 extern void tc_init(void);
68056 #endif
68057
68058 +extern void grsecurity_init(void);
68059 +
68060 /*
68061 * Debug helper: via this flag we know that we are in 'early bootup code'
68062 * where only the boot processor is running with IRQ disabled. This means
68063 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68064
68065 __setup("reset_devices", set_reset_devices);
68066
68067 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68068 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68069 +static int __init setup_grsec_proc_gid(char *str)
68070 +{
68071 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68072 + return 1;
68073 +}
68074 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68075 +#endif
68076 +
68077 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68078 +extern char pax_enter_kernel_user[];
68079 +extern char pax_exit_kernel_user[];
68080 +extern pgdval_t clone_pgd_mask;
68081 +#endif
68082 +
68083 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68084 +static int __init setup_pax_nouderef(char *str)
68085 +{
68086 +#ifdef CONFIG_X86_32
68087 + unsigned int cpu;
68088 + struct desc_struct *gdt;
68089 +
68090 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68091 + gdt = get_cpu_gdt_table(cpu);
68092 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68093 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68094 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68095 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68096 + }
68097 + loadsegment(ds, __KERNEL_DS);
68098 + loadsegment(es, __KERNEL_DS);
68099 + loadsegment(ss, __KERNEL_DS);
68100 +#else
68101 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68102 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68103 + clone_pgd_mask = ~(pgdval_t)0UL;
68104 +#endif
68105 +
68106 + return 0;
68107 +}
68108 +early_param("pax_nouderef", setup_pax_nouderef);
68109 +#endif
68110 +
68111 +#ifdef CONFIG_PAX_SOFTMODE
68112 +int pax_softmode;
68113 +
68114 +static int __init setup_pax_softmode(char *str)
68115 +{
68116 + get_option(&str, &pax_softmode);
68117 + return 1;
68118 +}
68119 +__setup("pax_softmode=", setup_pax_softmode);
68120 +#endif
68121 +
68122 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68123 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68124 static const char *panic_later, *panic_param;
68125 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68126 {
68127 int count = preempt_count();
68128 int ret;
68129 + const char *msg1 = "", *msg2 = "";
68130
68131 if (initcall_debug)
68132 ret = do_one_initcall_debug(fn);
68133 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68134 sprintf(msgbuf, "error code %d ", ret);
68135
68136 if (preempt_count() != count) {
68137 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68138 + msg1 = " preemption imbalance";
68139 preempt_count() = count;
68140 }
68141 if (irqs_disabled()) {
68142 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68143 + msg2 = " disabled interrupts";
68144 local_irq_enable();
68145 }
68146 - if (msgbuf[0]) {
68147 - printk("initcall %pF returned with %s\n", fn, msgbuf);
68148 + if (msgbuf[0] || *msg1 || *msg2) {
68149 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68150 }
68151
68152 return ret;
68153 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68154 "late",
68155 };
68156
68157 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68158 +u64 latent_entropy;
68159 +#endif
68160 +
68161 static void __init do_initcall_level(int level)
68162 {
68163 extern const struct kernel_param __start___param[], __stop___param[];
68164 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68165 level, level,
68166 &repair_env_string);
68167
68168 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68169 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68170 do_one_initcall(*fn);
68171 +
68172 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68173 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68174 +#endif
68175 +
68176 + }
68177 }
68178
68179 static void __init do_initcalls(void)
68180 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68181 {
68182 initcall_t *fn;
68183
68184 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
68185 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68186 do_one_initcall(*fn);
68187 +
68188 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68189 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68190 +#endif
68191 +
68192 + }
68193 }
68194
68195 static int run_init_process(const char *init_filename)
68196 @@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68197 do_basic_setup();
68198
68199 /* Open the /dev/console on the rootfs, this should never fail */
68200 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68201 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68202 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68203
68204 (void) sys_dup(0);
68205 @@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68206 if (!ramdisk_execute_command)
68207 ramdisk_execute_command = "/init";
68208
68209 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68210 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68211 ramdisk_execute_command = NULL;
68212 prepare_namespace();
68213 }
68214
68215 + grsecurity_init();
68216 +
68217 /*
68218 * Ok, we have completed the initial bootup, and
68219 * we're essentially up and running. Get rid of the
68220 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68221 index 71a3ca1..cc330ee 100644
68222 --- a/ipc/mqueue.c
68223 +++ b/ipc/mqueue.c
68224 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68225 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68226 info->attr.mq_msgsize);
68227
68228 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68229 spin_lock(&mq_lock);
68230 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68231 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68232 diff --git a/ipc/msg.c b/ipc/msg.c
68233 index a71af5a..a90a110 100644
68234 --- a/ipc/msg.c
68235 +++ b/ipc/msg.c
68236 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68237 return security_msg_queue_associate(msq, msgflg);
68238 }
68239
68240 +static struct ipc_ops msg_ops = {
68241 + .getnew = newque,
68242 + .associate = msg_security,
68243 + .more_checks = NULL
68244 +};
68245 +
68246 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68247 {
68248 struct ipc_namespace *ns;
68249 - struct ipc_ops msg_ops;
68250 struct ipc_params msg_params;
68251
68252 ns = current->nsproxy->ipc_ns;
68253
68254 - msg_ops.getnew = newque;
68255 - msg_ops.associate = msg_security;
68256 - msg_ops.more_checks = NULL;
68257 -
68258 msg_params.key = key;
68259 msg_params.flg = msgflg;
68260
68261 diff --git a/ipc/sem.c b/ipc/sem.c
68262 index 58d31f1..cce7a55 100644
68263 --- a/ipc/sem.c
68264 +++ b/ipc/sem.c
68265 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68266 return 0;
68267 }
68268
68269 +static struct ipc_ops sem_ops = {
68270 + .getnew = newary,
68271 + .associate = sem_security,
68272 + .more_checks = sem_more_checks
68273 +};
68274 +
68275 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68276 {
68277 struct ipc_namespace *ns;
68278 - struct ipc_ops sem_ops;
68279 struct ipc_params sem_params;
68280
68281 ns = current->nsproxy->ipc_ns;
68282 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68283 if (nsems < 0 || nsems > ns->sc_semmsl)
68284 return -EINVAL;
68285
68286 - sem_ops.getnew = newary;
68287 - sem_ops.associate = sem_security;
68288 - sem_ops.more_checks = sem_more_checks;
68289 -
68290 sem_params.key = key;
68291 sem_params.flg = semflg;
68292 sem_params.u.nsems = nsems;
68293 diff --git a/ipc/shm.c b/ipc/shm.c
68294 index dff40c9..9450e27 100644
68295 --- a/ipc/shm.c
68296 +++ b/ipc/shm.c
68297 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68298 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68299 #endif
68300
68301 +#ifdef CONFIG_GRKERNSEC
68302 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68303 + const time_t shm_createtime, const uid_t cuid,
68304 + const int shmid);
68305 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68306 + const time_t shm_createtime);
68307 +#endif
68308 +
68309 void shm_init_ns(struct ipc_namespace *ns)
68310 {
68311 ns->shm_ctlmax = SHMMAX;
68312 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68313 shp->shm_lprid = 0;
68314 shp->shm_atim = shp->shm_dtim = 0;
68315 shp->shm_ctim = get_seconds();
68316 +#ifdef CONFIG_GRKERNSEC
68317 + {
68318 + struct timespec timeval;
68319 + do_posix_clock_monotonic_gettime(&timeval);
68320 +
68321 + shp->shm_createtime = timeval.tv_sec;
68322 + }
68323 +#endif
68324 shp->shm_segsz = size;
68325 shp->shm_nattch = 0;
68326 shp->shm_file = file;
68327 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68328 return 0;
68329 }
68330
68331 +static struct ipc_ops shm_ops = {
68332 + .getnew = newseg,
68333 + .associate = shm_security,
68334 + .more_checks = shm_more_checks
68335 +};
68336 +
68337 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68338 {
68339 struct ipc_namespace *ns;
68340 - struct ipc_ops shm_ops;
68341 struct ipc_params shm_params;
68342
68343 ns = current->nsproxy->ipc_ns;
68344
68345 - shm_ops.getnew = newseg;
68346 - shm_ops.associate = shm_security;
68347 - shm_ops.more_checks = shm_more_checks;
68348 -
68349 shm_params.key = key;
68350 shm_params.flg = shmflg;
68351 shm_params.u.size = size;
68352 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68353 f_mode = FMODE_READ | FMODE_WRITE;
68354 }
68355 if (shmflg & SHM_EXEC) {
68356 +
68357 +#ifdef CONFIG_PAX_MPROTECT
68358 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
68359 + goto out;
68360 +#endif
68361 +
68362 prot |= PROT_EXEC;
68363 acc_mode |= S_IXUGO;
68364 }
68365 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68366 if (err)
68367 goto out_unlock;
68368
68369 +#ifdef CONFIG_GRKERNSEC
68370 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68371 + shp->shm_perm.cuid, shmid) ||
68372 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68373 + err = -EACCES;
68374 + goto out_unlock;
68375 + }
68376 +#endif
68377 +
68378 path = shp->shm_file->f_path;
68379 path_get(&path);
68380 shp->shm_nattch++;
68381 +#ifdef CONFIG_GRKERNSEC
68382 + shp->shm_lapid = current->pid;
68383 +#endif
68384 size = i_size_read(path.dentry->d_inode);
68385 shm_unlock(shp);
68386
68387 diff --git a/kernel/acct.c b/kernel/acct.c
68388 index 051e071..15e0920 100644
68389 --- a/kernel/acct.c
68390 +++ b/kernel/acct.c
68391 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68392 */
68393 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68394 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68395 - file->f_op->write(file, (char *)&ac,
68396 + file->f_op->write(file, (char __force_user *)&ac,
68397 sizeof(acct_t), &file->f_pos);
68398 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68399 set_fs(fs);
68400 diff --git a/kernel/audit.c b/kernel/audit.c
68401 index 40414e9..c920b72 100644
68402 --- a/kernel/audit.c
68403 +++ b/kernel/audit.c
68404 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68405 3) suppressed due to audit_rate_limit
68406 4) suppressed due to audit_backlog_limit
68407 */
68408 -static atomic_t audit_lost = ATOMIC_INIT(0);
68409 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68410
68411 /* The netlink socket. */
68412 static struct sock *audit_sock;
68413 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68414 unsigned long now;
68415 int print;
68416
68417 - atomic_inc(&audit_lost);
68418 + atomic_inc_unchecked(&audit_lost);
68419
68420 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68421
68422 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68423 printk(KERN_WARNING
68424 "audit: audit_lost=%d audit_rate_limit=%d "
68425 "audit_backlog_limit=%d\n",
68426 - atomic_read(&audit_lost),
68427 + atomic_read_unchecked(&audit_lost),
68428 audit_rate_limit,
68429 audit_backlog_limit);
68430 audit_panic(message);
68431 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68432 status_set.pid = audit_pid;
68433 status_set.rate_limit = audit_rate_limit;
68434 status_set.backlog_limit = audit_backlog_limit;
68435 - status_set.lost = atomic_read(&audit_lost);
68436 + status_set.lost = atomic_read_unchecked(&audit_lost);
68437 status_set.backlog = skb_queue_len(&audit_skb_queue);
68438 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68439 &status_set, sizeof(status_set));
68440 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68441 index 157e989..b28b365 100644
68442 --- a/kernel/auditsc.c
68443 +++ b/kernel/auditsc.c
68444 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68445 }
68446
68447 /* global counter which is incremented every time something logs in */
68448 -static atomic_t session_id = ATOMIC_INIT(0);
68449 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68450
68451 /**
68452 * audit_set_loginuid - set current task's audit_context loginuid
68453 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68454 return -EPERM;
68455 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68456
68457 - sessionid = atomic_inc_return(&session_id);
68458 + sessionid = atomic_inc_return_unchecked(&session_id);
68459 if (context && context->in_syscall) {
68460 struct audit_buffer *ab;
68461
68462 diff --git a/kernel/capability.c b/kernel/capability.c
68463 index 493d972..f87dfbd 100644
68464 --- a/kernel/capability.c
68465 +++ b/kernel/capability.c
68466 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68467 * before modification is attempted and the application
68468 * fails.
68469 */
68470 + if (tocopy > ARRAY_SIZE(kdata))
68471 + return -EFAULT;
68472 +
68473 if (copy_to_user(dataptr, kdata, tocopy
68474 * sizeof(struct __user_cap_data_struct))) {
68475 return -EFAULT;
68476 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68477 int ret;
68478
68479 rcu_read_lock();
68480 - ret = security_capable(__task_cred(t), ns, cap);
68481 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68482 + gr_task_is_capable(t, __task_cred(t), cap);
68483 rcu_read_unlock();
68484
68485 - return (ret == 0);
68486 + return ret;
68487 }
68488
68489 /**
68490 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68491 int ret;
68492
68493 rcu_read_lock();
68494 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
68495 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68496 rcu_read_unlock();
68497
68498 - return (ret == 0);
68499 + return ret;
68500 }
68501
68502 /**
68503 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68504 BUG();
68505 }
68506
68507 - if (security_capable(current_cred(), ns, cap) == 0) {
68508 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68509 current->flags |= PF_SUPERPRIV;
68510 return true;
68511 }
68512 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68513 }
68514 EXPORT_SYMBOL(ns_capable);
68515
68516 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
68517 +{
68518 + if (unlikely(!cap_valid(cap))) {
68519 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
68520 + BUG();
68521 + }
68522 +
68523 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68524 + current->flags |= PF_SUPERPRIV;
68525 + return true;
68526 + }
68527 + return false;
68528 +}
68529 +EXPORT_SYMBOL(ns_capable_nolog);
68530 +
68531 /**
68532 * capable - Determine if the current task has a superior capability in effect
68533 * @cap: The capability to be tested for
68534 @@ -408,6 +427,12 @@ bool capable(int cap)
68535 }
68536 EXPORT_SYMBOL(capable);
68537
68538 +bool capable_nolog(int cap)
68539 +{
68540 + return ns_capable_nolog(&init_user_ns, cap);
68541 +}
68542 +EXPORT_SYMBOL(capable_nolog);
68543 +
68544 /**
68545 * nsown_capable - Check superior capability to one's own user_ns
68546 * @cap: The capability in question
68547 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68548
68549 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68550 }
68551 +
68552 +bool inode_capable_nolog(const struct inode *inode, int cap)
68553 +{
68554 + struct user_namespace *ns = current_user_ns();
68555 +
68556 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68557 +}
68558 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68559 index ad99830..992d8a7 100644
68560 --- a/kernel/cgroup.c
68561 +++ b/kernel/cgroup.c
68562 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68563 struct css_set *cg = link->cg;
68564 struct task_struct *task;
68565 int count = 0;
68566 - seq_printf(seq, "css_set %p\n", cg);
68567 + seq_printf(seq, "css_set %pK\n", cg);
68568 list_for_each_entry(task, &cg->tasks, cg_list) {
68569 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68570 seq_puts(seq, " ...\n");
68571 diff --git a/kernel/compat.c b/kernel/compat.c
68572 index c28a306..b4d0cf3 100644
68573 --- a/kernel/compat.c
68574 +++ b/kernel/compat.c
68575 @@ -13,6 +13,7 @@
68576
68577 #include <linux/linkage.h>
68578 #include <linux/compat.h>
68579 +#include <linux/module.h>
68580 #include <linux/errno.h>
68581 #include <linux/time.h>
68582 #include <linux/signal.h>
68583 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68584 mm_segment_t oldfs;
68585 long ret;
68586
68587 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68588 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68589 oldfs = get_fs();
68590 set_fs(KERNEL_DS);
68591 ret = hrtimer_nanosleep_restart(restart);
68592 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68593 oldfs = get_fs();
68594 set_fs(KERNEL_DS);
68595 ret = hrtimer_nanosleep(&tu,
68596 - rmtp ? (struct timespec __user *)&rmt : NULL,
68597 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
68598 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68599 set_fs(oldfs);
68600
68601 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68602 mm_segment_t old_fs = get_fs();
68603
68604 set_fs(KERNEL_DS);
68605 - ret = sys_sigpending((old_sigset_t __user *) &s);
68606 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
68607 set_fs(old_fs);
68608 if (ret == 0)
68609 ret = put_user(s, set);
68610 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68611 mm_segment_t old_fs = get_fs();
68612
68613 set_fs(KERNEL_DS);
68614 - ret = sys_old_getrlimit(resource, &r);
68615 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68616 set_fs(old_fs);
68617
68618 if (!ret) {
68619 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68620 mm_segment_t old_fs = get_fs();
68621
68622 set_fs(KERNEL_DS);
68623 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68624 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68625 set_fs(old_fs);
68626
68627 if (ret)
68628 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68629 set_fs (KERNEL_DS);
68630 ret = sys_wait4(pid,
68631 (stat_addr ?
68632 - (unsigned int __user *) &status : NULL),
68633 - options, (struct rusage __user *) &r);
68634 + (unsigned int __force_user *) &status : NULL),
68635 + options, (struct rusage __force_user *) &r);
68636 set_fs (old_fs);
68637
68638 if (ret > 0) {
68639 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68640 memset(&info, 0, sizeof(info));
68641
68642 set_fs(KERNEL_DS);
68643 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68644 - uru ? (struct rusage __user *)&ru : NULL);
68645 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68646 + uru ? (struct rusage __force_user *)&ru : NULL);
68647 set_fs(old_fs);
68648
68649 if ((ret < 0) || (info.si_signo == 0))
68650 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68651 oldfs = get_fs();
68652 set_fs(KERNEL_DS);
68653 err = sys_timer_settime(timer_id, flags,
68654 - (struct itimerspec __user *) &newts,
68655 - (struct itimerspec __user *) &oldts);
68656 + (struct itimerspec __force_user *) &newts,
68657 + (struct itimerspec __force_user *) &oldts);
68658 set_fs(oldfs);
68659 if (!err && old && put_compat_itimerspec(old, &oldts))
68660 return -EFAULT;
68661 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68662 oldfs = get_fs();
68663 set_fs(KERNEL_DS);
68664 err = sys_timer_gettime(timer_id,
68665 - (struct itimerspec __user *) &ts);
68666 + (struct itimerspec __force_user *) &ts);
68667 set_fs(oldfs);
68668 if (!err && put_compat_itimerspec(setting, &ts))
68669 return -EFAULT;
68670 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68671 oldfs = get_fs();
68672 set_fs(KERNEL_DS);
68673 err = sys_clock_settime(which_clock,
68674 - (struct timespec __user *) &ts);
68675 + (struct timespec __force_user *) &ts);
68676 set_fs(oldfs);
68677 return err;
68678 }
68679 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68680 oldfs = get_fs();
68681 set_fs(KERNEL_DS);
68682 err = sys_clock_gettime(which_clock,
68683 - (struct timespec __user *) &ts);
68684 + (struct timespec __force_user *) &ts);
68685 set_fs(oldfs);
68686 if (!err && put_compat_timespec(&ts, tp))
68687 return -EFAULT;
68688 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68689
68690 oldfs = get_fs();
68691 set_fs(KERNEL_DS);
68692 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68693 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68694 set_fs(oldfs);
68695
68696 err = compat_put_timex(utp, &txc);
68697 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68698 oldfs = get_fs();
68699 set_fs(KERNEL_DS);
68700 err = sys_clock_getres(which_clock,
68701 - (struct timespec __user *) &ts);
68702 + (struct timespec __force_user *) &ts);
68703 set_fs(oldfs);
68704 if (!err && tp && put_compat_timespec(&ts, tp))
68705 return -EFAULT;
68706 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68707 long err;
68708 mm_segment_t oldfs;
68709 struct timespec tu;
68710 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68711 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68712
68713 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68714 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68715 oldfs = get_fs();
68716 set_fs(KERNEL_DS);
68717 err = clock_nanosleep_restart(restart);
68718 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68719 oldfs = get_fs();
68720 set_fs(KERNEL_DS);
68721 err = sys_clock_nanosleep(which_clock, flags,
68722 - (struct timespec __user *) &in,
68723 - (struct timespec __user *) &out);
68724 + (struct timespec __force_user *) &in,
68725 + (struct timespec __force_user *) &out);
68726 set_fs(oldfs);
68727
68728 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68729 diff --git a/kernel/configs.c b/kernel/configs.c
68730 index 42e8fa0..9e7406b 100644
68731 --- a/kernel/configs.c
68732 +++ b/kernel/configs.c
68733 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68734 struct proc_dir_entry *entry;
68735
68736 /* create the current config file */
68737 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68738 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68739 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68740 + &ikconfig_file_ops);
68741 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68742 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68743 + &ikconfig_file_ops);
68744 +#endif
68745 +#else
68746 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68747 &ikconfig_file_ops);
68748 +#endif
68749 +
68750 if (!entry)
68751 return -ENOMEM;
68752
68753 diff --git a/kernel/cred.c b/kernel/cred.c
68754 index 48cea3d..3476734 100644
68755 --- a/kernel/cred.c
68756 +++ b/kernel/cred.c
68757 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68758 validate_creds(cred);
68759 alter_cred_subscribers(cred, -1);
68760 put_cred(cred);
68761 +
68762 +#ifdef CONFIG_GRKERNSEC_SETXID
68763 + cred = (struct cred *) tsk->delayed_cred;
68764 + if (cred != NULL) {
68765 + tsk->delayed_cred = NULL;
68766 + validate_creds(cred);
68767 + alter_cred_subscribers(cred, -1);
68768 + put_cred(cred);
68769 + }
68770 +#endif
68771 }
68772
68773 /**
68774 @@ -469,7 +479,7 @@ error_put:
68775 * Always returns 0 thus allowing this function to be tail-called at the end
68776 * of, say, sys_setgid().
68777 */
68778 -int commit_creds(struct cred *new)
68779 +static int __commit_creds(struct cred *new)
68780 {
68781 struct task_struct *task = current;
68782 const struct cred *old = task->real_cred;
68783 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68784
68785 get_cred(new); /* we will require a ref for the subj creds too */
68786
68787 + gr_set_role_label(task, new->uid, new->gid);
68788 +
68789 /* dumpability changes */
68790 if (!uid_eq(old->euid, new->euid) ||
68791 !gid_eq(old->egid, new->egid) ||
68792 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68793 put_cred(old);
68794 return 0;
68795 }
68796 +#ifdef CONFIG_GRKERNSEC_SETXID
68797 +extern int set_user(struct cred *new);
68798 +
68799 +void gr_delayed_cred_worker(void)
68800 +{
68801 + const struct cred *new = current->delayed_cred;
68802 + struct cred *ncred;
68803 +
68804 + current->delayed_cred = NULL;
68805 +
68806 + if (current_uid() && new != NULL) {
68807 + // from doing get_cred on it when queueing this
68808 + put_cred(new);
68809 + return;
68810 + } else if (new == NULL)
68811 + return;
68812 +
68813 + ncred = prepare_creds();
68814 + if (!ncred)
68815 + goto die;
68816 + // uids
68817 + ncred->uid = new->uid;
68818 + ncred->euid = new->euid;
68819 + ncred->suid = new->suid;
68820 + ncred->fsuid = new->fsuid;
68821 + // gids
68822 + ncred->gid = new->gid;
68823 + ncred->egid = new->egid;
68824 + ncred->sgid = new->sgid;
68825 + ncred->fsgid = new->fsgid;
68826 + // groups
68827 + if (set_groups(ncred, new->group_info) < 0) {
68828 + abort_creds(ncred);
68829 + goto die;
68830 + }
68831 + // caps
68832 + ncred->securebits = new->securebits;
68833 + ncred->cap_inheritable = new->cap_inheritable;
68834 + ncred->cap_permitted = new->cap_permitted;
68835 + ncred->cap_effective = new->cap_effective;
68836 + ncred->cap_bset = new->cap_bset;
68837 +
68838 + if (set_user(ncred)) {
68839 + abort_creds(ncred);
68840 + goto die;
68841 + }
68842 +
68843 + // from doing get_cred on it when queueing this
68844 + put_cred(new);
68845 +
68846 + __commit_creds(ncred);
68847 + return;
68848 +die:
68849 + // from doing get_cred on it when queueing this
68850 + put_cred(new);
68851 + do_group_exit(SIGKILL);
68852 +}
68853 +#endif
68854 +
68855 +int commit_creds(struct cred *new)
68856 +{
68857 +#ifdef CONFIG_GRKERNSEC_SETXID
68858 + int ret;
68859 + int schedule_it = 0;
68860 + struct task_struct *t;
68861 +
68862 + /* we won't get called with tasklist_lock held for writing
68863 + and interrupts disabled as the cred struct in that case is
68864 + init_cred
68865 + */
68866 + if (grsec_enable_setxid && !current_is_single_threaded() &&
68867 + !current_uid() && new->uid) {
68868 + schedule_it = 1;
68869 + }
68870 + ret = __commit_creds(new);
68871 + if (schedule_it) {
68872 + rcu_read_lock();
68873 + read_lock(&tasklist_lock);
68874 + for (t = next_thread(current); t != current;
68875 + t = next_thread(t)) {
68876 + if (t->delayed_cred == NULL) {
68877 + t->delayed_cred = get_cred(new);
68878 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
68879 + set_tsk_need_resched(t);
68880 + }
68881 + }
68882 + read_unlock(&tasklist_lock);
68883 + rcu_read_unlock();
68884 + }
68885 + return ret;
68886 +#else
68887 + return __commit_creds(new);
68888 +#endif
68889 +}
68890 +
68891 EXPORT_SYMBOL(commit_creds);
68892
68893 /**
68894 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
68895 index 9a61738..c5c8f3a 100644
68896 --- a/kernel/debug/debug_core.c
68897 +++ b/kernel/debug/debug_core.c
68898 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
68899 */
68900 static atomic_t masters_in_kgdb;
68901 static atomic_t slaves_in_kgdb;
68902 -static atomic_t kgdb_break_tasklet_var;
68903 +static atomic_unchecked_t kgdb_break_tasklet_var;
68904 atomic_t kgdb_setting_breakpoint;
68905
68906 struct task_struct *kgdb_usethread;
68907 @@ -132,7 +132,7 @@ int kgdb_single_step;
68908 static pid_t kgdb_sstep_pid;
68909
68910 /* to keep track of the CPU which is doing the single stepping*/
68911 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68912 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68913
68914 /*
68915 * If you are debugging a problem where roundup (the collection of
68916 @@ -540,7 +540,7 @@ return_normal:
68917 * kernel will only try for the value of sstep_tries before
68918 * giving up and continuing on.
68919 */
68920 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
68921 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
68922 (kgdb_info[cpu].task &&
68923 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
68924 atomic_set(&kgdb_active, -1);
68925 @@ -634,8 +634,8 @@ cpu_master_loop:
68926 }
68927
68928 kgdb_restore:
68929 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
68930 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
68931 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
68932 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
68933 if (kgdb_info[sstep_cpu].task)
68934 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
68935 else
68936 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
68937 static void kgdb_tasklet_bpt(unsigned long ing)
68938 {
68939 kgdb_breakpoint();
68940 - atomic_set(&kgdb_break_tasklet_var, 0);
68941 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
68942 }
68943
68944 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
68945
68946 void kgdb_schedule_breakpoint(void)
68947 {
68948 - if (atomic_read(&kgdb_break_tasklet_var) ||
68949 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
68950 atomic_read(&kgdb_active) != -1 ||
68951 atomic_read(&kgdb_setting_breakpoint))
68952 return;
68953 - atomic_inc(&kgdb_break_tasklet_var);
68954 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
68955 tasklet_schedule(&kgdb_tasklet_breakpoint);
68956 }
68957 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
68958 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
68959 index 8875254..7cf4928 100644
68960 --- a/kernel/debug/kdb/kdb_main.c
68961 +++ b/kernel/debug/kdb/kdb_main.c
68962 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
68963 continue;
68964
68965 kdb_printf("%-20s%8u 0x%p ", mod->name,
68966 - mod->core_size, (void *)mod);
68967 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
68968 #ifdef CONFIG_MODULE_UNLOAD
68969 kdb_printf("%4ld ", module_refcount(mod));
68970 #endif
68971 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
68972 kdb_printf(" (Loading)");
68973 else
68974 kdb_printf(" (Live)");
68975 - kdb_printf(" 0x%p", mod->module_core);
68976 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
68977
68978 #ifdef CONFIG_MODULE_UNLOAD
68979 {
68980 diff --git a/kernel/events/core.c b/kernel/events/core.c
68981 index dbccf83..8c66482 100644
68982 --- a/kernel/events/core.c
68983 +++ b/kernel/events/core.c
68984 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
68985 return 0;
68986 }
68987
68988 -static atomic64_t perf_event_id;
68989 +static atomic64_unchecked_t perf_event_id;
68990
68991 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68992 enum event_type_t event_type);
68993 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
68994
68995 static inline u64 perf_event_count(struct perf_event *event)
68996 {
68997 - return local64_read(&event->count) + atomic64_read(&event->child_count);
68998 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68999 }
69000
69001 static u64 perf_event_read(struct perf_event *event)
69002 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69003 mutex_lock(&event->child_mutex);
69004 total += perf_event_read(event);
69005 *enabled += event->total_time_enabled +
69006 - atomic64_read(&event->child_total_time_enabled);
69007 + atomic64_read_unchecked(&event->child_total_time_enabled);
69008 *running += event->total_time_running +
69009 - atomic64_read(&event->child_total_time_running);
69010 + atomic64_read_unchecked(&event->child_total_time_running);
69011
69012 list_for_each_entry(child, &event->child_list, child_list) {
69013 total += perf_event_read(child);
69014 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69015 userpg->offset -= local64_read(&event->hw.prev_count);
69016
69017 userpg->time_enabled = enabled +
69018 - atomic64_read(&event->child_total_time_enabled);
69019 + atomic64_read_unchecked(&event->child_total_time_enabled);
69020
69021 userpg->time_running = running +
69022 - atomic64_read(&event->child_total_time_running);
69023 + atomic64_read_unchecked(&event->child_total_time_running);
69024
69025 arch_perf_update_userpage(userpg, now);
69026
69027 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69028 values[n++] = perf_event_count(event);
69029 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69030 values[n++] = enabled +
69031 - atomic64_read(&event->child_total_time_enabled);
69032 + atomic64_read_unchecked(&event->child_total_time_enabled);
69033 }
69034 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69035 values[n++] = running +
69036 - atomic64_read(&event->child_total_time_running);
69037 + atomic64_read_unchecked(&event->child_total_time_running);
69038 }
69039 if (read_format & PERF_FORMAT_ID)
69040 values[n++] = primary_event_id(event);
69041 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69042 * need to add enough zero bytes after the string to handle
69043 * the 64bit alignment we do later.
69044 */
69045 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69046 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
69047 if (!buf) {
69048 name = strncpy(tmp, "//enomem", sizeof(tmp));
69049 goto got_name;
69050 }
69051 - name = d_path(&file->f_path, buf, PATH_MAX);
69052 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69053 if (IS_ERR(name)) {
69054 name = strncpy(tmp, "//toolong", sizeof(tmp));
69055 goto got_name;
69056 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69057 event->parent = parent_event;
69058
69059 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69060 - event->id = atomic64_inc_return(&perf_event_id);
69061 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69062
69063 event->state = PERF_EVENT_STATE_INACTIVE;
69064
69065 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69066 /*
69067 * Add back the child's count to the parent's count:
69068 */
69069 - atomic64_add(child_val, &parent_event->child_count);
69070 - atomic64_add(child_event->total_time_enabled,
69071 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69072 + atomic64_add_unchecked(child_event->total_time_enabled,
69073 &parent_event->child_total_time_enabled);
69074 - atomic64_add(child_event->total_time_running,
69075 + atomic64_add_unchecked(child_event->total_time_running,
69076 &parent_event->child_total_time_running);
69077
69078 /*
69079 diff --git a/kernel/exit.c b/kernel/exit.c
69080 index 346616c..f103b28 100644
69081 --- a/kernel/exit.c
69082 +++ b/kernel/exit.c
69083 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69084 struct task_struct *leader;
69085 int zap_leader;
69086 repeat:
69087 +#ifdef CONFIG_NET
69088 + gr_del_task_from_ip_table(p);
69089 +#endif
69090 +
69091 /* don't need to get the RCU readlock here - the process is dead and
69092 * can't be modifying its own credentials. But shut RCU-lockdep up */
69093 rcu_read_lock();
69094 @@ -394,7 +398,7 @@ int allow_signal(int sig)
69095 * know it'll be handled, so that they don't get converted to
69096 * SIGKILL or just silently dropped.
69097 */
69098 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69099 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69100 recalc_sigpending();
69101 spin_unlock_irq(&current->sighand->siglock);
69102 return 0;
69103 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
69104 vsnprintf(current->comm, sizeof(current->comm), name, args);
69105 va_end(args);
69106
69107 + gr_put_exec_file(current);
69108 + gr_set_kernel_label(current);
69109 +
69110 /*
69111 * If we were started as result of loading a module, close all of the
69112 * user space pages. We don't need them, and if we didn't close them
69113 @@ -812,6 +819,8 @@ void do_exit(long code)
69114 struct task_struct *tsk = current;
69115 int group_dead;
69116
69117 + set_fs(USER_DS);
69118 +
69119 profile_task_exit(tsk);
69120
69121 WARN_ON(blk_needs_flush_plug(tsk));
69122 @@ -828,7 +837,6 @@ void do_exit(long code)
69123 * mm_release()->clear_child_tid() from writing to a user-controlled
69124 * kernel address.
69125 */
69126 - set_fs(USER_DS);
69127
69128 ptrace_event(PTRACE_EVENT_EXIT, code);
69129
69130 @@ -887,6 +895,9 @@ void do_exit(long code)
69131 tsk->exit_code = code;
69132 taskstats_exit(tsk, group_dead);
69133
69134 + gr_acl_handle_psacct(tsk, code);
69135 + gr_acl_handle_exit();
69136 +
69137 exit_mm(tsk);
69138
69139 if (group_dead)
69140 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69141 * Take down every thread in the group. This is called by fatal signals
69142 * as well as by sys_exit_group (below).
69143 */
69144 -void
69145 +__noreturn void
69146 do_group_exit(int exit_code)
69147 {
69148 struct signal_struct *sig = current->signal;
69149 diff --git a/kernel/fork.c b/kernel/fork.c
69150 index acc4cb6..b524cb5 100644
69151 --- a/kernel/fork.c
69152 +++ b/kernel/fork.c
69153 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69154 *stackend = STACK_END_MAGIC; /* for overflow detection */
69155
69156 #ifdef CONFIG_CC_STACKPROTECTOR
69157 - tsk->stack_canary = get_random_int();
69158 + tsk->stack_canary = pax_get_random_long();
69159 #endif
69160
69161 /*
69162 @@ -344,13 +344,81 @@ free_tsk:
69163 }
69164
69165 #ifdef CONFIG_MMU
69166 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69167 +{
69168 + struct vm_area_struct *tmp;
69169 + unsigned long charge;
69170 + struct mempolicy *pol;
69171 + struct file *file;
69172 +
69173 + charge = 0;
69174 + if (mpnt->vm_flags & VM_ACCOUNT) {
69175 + unsigned long len = vma_pages(mpnt);
69176 +
69177 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69178 + goto fail_nomem;
69179 + charge = len;
69180 + }
69181 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69182 + if (!tmp)
69183 + goto fail_nomem;
69184 + *tmp = *mpnt;
69185 + tmp->vm_mm = mm;
69186 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
69187 + pol = mpol_dup(vma_policy(mpnt));
69188 + if (IS_ERR(pol))
69189 + goto fail_nomem_policy;
69190 + vma_set_policy(tmp, pol);
69191 + if (anon_vma_fork(tmp, mpnt))
69192 + goto fail_nomem_anon_vma_fork;
69193 + tmp->vm_flags &= ~VM_LOCKED;
69194 + tmp->vm_next = tmp->vm_prev = NULL;
69195 + tmp->vm_mirror = NULL;
69196 + file = tmp->vm_file;
69197 + if (file) {
69198 + struct inode *inode = file->f_path.dentry->d_inode;
69199 + struct address_space *mapping = file->f_mapping;
69200 +
69201 + get_file(file);
69202 + if (tmp->vm_flags & VM_DENYWRITE)
69203 + atomic_dec(&inode->i_writecount);
69204 + mutex_lock(&mapping->i_mmap_mutex);
69205 + if (tmp->vm_flags & VM_SHARED)
69206 + mapping->i_mmap_writable++;
69207 + flush_dcache_mmap_lock(mapping);
69208 + /* insert tmp into the share list, just after mpnt */
69209 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69210 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69211 + else
69212 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69213 + flush_dcache_mmap_unlock(mapping);
69214 + mutex_unlock(&mapping->i_mmap_mutex);
69215 + }
69216 +
69217 + /*
69218 + * Clear hugetlb-related page reserves for children. This only
69219 + * affects MAP_PRIVATE mappings. Faults generated by the child
69220 + * are not guaranteed to succeed, even if read-only
69221 + */
69222 + if (is_vm_hugetlb_page(tmp))
69223 + reset_vma_resv_huge_pages(tmp);
69224 +
69225 + return tmp;
69226 +
69227 +fail_nomem_anon_vma_fork:
69228 + mpol_put(pol);
69229 +fail_nomem_policy:
69230 + kmem_cache_free(vm_area_cachep, tmp);
69231 +fail_nomem:
69232 + vm_unacct_memory(charge);
69233 + return NULL;
69234 +}
69235 +
69236 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69237 {
69238 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69239 struct rb_node **rb_link, *rb_parent;
69240 int retval;
69241 - unsigned long charge;
69242 - struct mempolicy *pol;
69243
69244 down_write(&oldmm->mmap_sem);
69245 flush_cache_dup_mm(oldmm);
69246 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69247 mm->locked_vm = 0;
69248 mm->mmap = NULL;
69249 mm->mmap_cache = NULL;
69250 - mm->free_area_cache = oldmm->mmap_base;
69251 - mm->cached_hole_size = ~0UL;
69252 + mm->free_area_cache = oldmm->free_area_cache;
69253 + mm->cached_hole_size = oldmm->cached_hole_size;
69254 mm->map_count = 0;
69255 cpumask_clear(mm_cpumask(mm));
69256 mm->mm_rb = RB_ROOT;
69257 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69258
69259 prev = NULL;
69260 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69261 - struct file *file;
69262 -
69263 if (mpnt->vm_flags & VM_DONTCOPY) {
69264 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69265 -vma_pages(mpnt));
69266 continue;
69267 }
69268 - charge = 0;
69269 - if (mpnt->vm_flags & VM_ACCOUNT) {
69270 - unsigned long len = vma_pages(mpnt);
69271 -
69272 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69273 - goto fail_nomem;
69274 - charge = len;
69275 - }
69276 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69277 - if (!tmp)
69278 - goto fail_nomem;
69279 - *tmp = *mpnt;
69280 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
69281 - pol = mpol_dup(vma_policy(mpnt));
69282 - retval = PTR_ERR(pol);
69283 - if (IS_ERR(pol))
69284 - goto fail_nomem_policy;
69285 - vma_set_policy(tmp, pol);
69286 - tmp->vm_mm = mm;
69287 - if (anon_vma_fork(tmp, mpnt))
69288 - goto fail_nomem_anon_vma_fork;
69289 - tmp->vm_flags &= ~VM_LOCKED;
69290 - tmp->vm_next = tmp->vm_prev = NULL;
69291 - file = tmp->vm_file;
69292 - if (file) {
69293 - struct inode *inode = file->f_path.dentry->d_inode;
69294 - struct address_space *mapping = file->f_mapping;
69295 -
69296 - get_file(file);
69297 - if (tmp->vm_flags & VM_DENYWRITE)
69298 - atomic_dec(&inode->i_writecount);
69299 - mutex_lock(&mapping->i_mmap_mutex);
69300 - if (tmp->vm_flags & VM_SHARED)
69301 - mapping->i_mmap_writable++;
69302 - flush_dcache_mmap_lock(mapping);
69303 - /* insert tmp into the share list, just after mpnt */
69304 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69305 - vma_nonlinear_insert(tmp,
69306 - &mapping->i_mmap_nonlinear);
69307 - else
69308 - vma_interval_tree_insert_after(tmp, mpnt,
69309 - &mapping->i_mmap);
69310 - flush_dcache_mmap_unlock(mapping);
69311 - mutex_unlock(&mapping->i_mmap_mutex);
69312 + tmp = dup_vma(mm, oldmm, mpnt);
69313 + if (!tmp) {
69314 + retval = -ENOMEM;
69315 + goto out;
69316 }
69317
69318 /*
69319 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69320 if (retval)
69321 goto out;
69322 }
69323 +
69324 +#ifdef CONFIG_PAX_SEGMEXEC
69325 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69326 + struct vm_area_struct *mpnt_m;
69327 +
69328 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69329 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69330 +
69331 + if (!mpnt->vm_mirror)
69332 + continue;
69333 +
69334 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69335 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69336 + mpnt->vm_mirror = mpnt_m;
69337 + } else {
69338 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69339 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69340 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69341 + mpnt->vm_mirror->vm_mirror = mpnt;
69342 + }
69343 + }
69344 + BUG_ON(mpnt_m);
69345 + }
69346 +#endif
69347 +
69348 /* a new mm has just been created */
69349 arch_dup_mmap(oldmm, mm);
69350 retval = 0;
69351 @@ -470,14 +521,6 @@ out:
69352 flush_tlb_mm(oldmm);
69353 up_write(&oldmm->mmap_sem);
69354 return retval;
69355 -fail_nomem_anon_vma_fork:
69356 - mpol_put(pol);
69357 -fail_nomem_policy:
69358 - kmem_cache_free(vm_area_cachep, tmp);
69359 -fail_nomem:
69360 - retval = -ENOMEM;
69361 - vm_unacct_memory(charge);
69362 - goto out;
69363 }
69364
69365 static inline int mm_alloc_pgd(struct mm_struct *mm)
69366 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69367 return ERR_PTR(err);
69368
69369 mm = get_task_mm(task);
69370 - if (mm && mm != current->mm &&
69371 - !ptrace_may_access(task, mode)) {
69372 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69373 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69374 mmput(mm);
69375 mm = ERR_PTR(-EACCES);
69376 }
69377 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69378 spin_unlock(&fs->lock);
69379 return -EAGAIN;
69380 }
69381 - fs->users++;
69382 + atomic_inc(&fs->users);
69383 spin_unlock(&fs->lock);
69384 return 0;
69385 }
69386 tsk->fs = copy_fs_struct(fs);
69387 if (!tsk->fs)
69388 return -ENOMEM;
69389 + /* Carry through gr_chroot_dentry and is_chrooted instead
69390 + of recomputing it here. Already copied when the task struct
69391 + is duplicated. This allows pivot_root to not be treated as
69392 + a chroot
69393 + */
69394 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
69395 +
69396 return 0;
69397 }
69398
69399 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69400 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69401 #endif
69402 retval = -EAGAIN;
69403 +
69404 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69405 +
69406 if (atomic_read(&p->real_cred->user->processes) >=
69407 task_rlimit(p, RLIMIT_NPROC)) {
69408 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69409 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69410 goto bad_fork_free_pid;
69411 }
69412
69413 + /* synchronizes with gr_set_acls()
69414 + we need to call this past the point of no return for fork()
69415 + */
69416 + gr_copy_label(p);
69417 +
69418 if (clone_flags & CLONE_THREAD) {
69419 current->signal->nr_threads++;
69420 atomic_inc(&current->signal->live);
69421 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69422 bad_fork_free:
69423 free_task(p);
69424 fork_out:
69425 + gr_log_forkfail(retval);
69426 +
69427 return ERR_PTR(retval);
69428 }
69429
69430 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69431 if (clone_flags & CLONE_PARENT_SETTID)
69432 put_user(nr, parent_tidptr);
69433
69434 + gr_handle_brute_check();
69435 +
69436 if (clone_flags & CLONE_VFORK) {
69437 p->vfork_done = &vfork;
69438 init_completion(&vfork);
69439 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69440 return 0;
69441
69442 /* don't need lock here; in the worst case we'll do useless copy */
69443 - if (fs->users == 1)
69444 + if (atomic_read(&fs->users) == 1)
69445 return 0;
69446
69447 *new_fsp = copy_fs_struct(fs);
69448 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69449 fs = current->fs;
69450 spin_lock(&fs->lock);
69451 current->fs = new_fs;
69452 - if (--fs->users)
69453 + gr_set_chroot_entries(current, &current->fs->root);
69454 + if (atomic_dec_return(&fs->users))
69455 new_fs = NULL;
69456 else
69457 new_fs = fs;
69458 diff --git a/kernel/futex.c b/kernel/futex.c
69459 index 19eb089..b8c65ea 100644
69460 --- a/kernel/futex.c
69461 +++ b/kernel/futex.c
69462 @@ -54,6 +54,7 @@
69463 #include <linux/mount.h>
69464 #include <linux/pagemap.h>
69465 #include <linux/syscalls.h>
69466 +#include <linux/ptrace.h>
69467 #include <linux/signal.h>
69468 #include <linux/export.h>
69469 #include <linux/magic.h>
69470 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69471 struct page *page, *page_head;
69472 int err, ro = 0;
69473
69474 +#ifdef CONFIG_PAX_SEGMEXEC
69475 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69476 + return -EFAULT;
69477 +#endif
69478 +
69479 /*
69480 * The futex address must be "naturally" aligned.
69481 */
69482 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69483 {
69484 u32 curval;
69485 int i;
69486 + mm_segment_t oldfs;
69487
69488 /*
69489 * This will fail and we want it. Some arch implementations do
69490 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69491 * implementation, the non-functional ones will return
69492 * -ENOSYS.
69493 */
69494 + oldfs = get_fs();
69495 + set_fs(USER_DS);
69496 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69497 futex_cmpxchg_enabled = 1;
69498 + set_fs(oldfs);
69499
69500 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69501 plist_head_init(&futex_queues[i].chain);
69502 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69503 index 9b22d03..6295b62 100644
69504 --- a/kernel/gcov/base.c
69505 +++ b/kernel/gcov/base.c
69506 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
69507 }
69508
69509 #ifdef CONFIG_MODULES
69510 -static inline int within(void *addr, void *start, unsigned long size)
69511 -{
69512 - return ((addr >= start) && (addr < start + size));
69513 -}
69514 -
69515 /* Update list and generate events when modules are unloaded. */
69516 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69517 void *data)
69518 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69519 prev = NULL;
69520 /* Remove entries located in module from linked list. */
69521 for (info = gcov_info_head; info; info = info->next) {
69522 - if (within(info, mod->module_core, mod->core_size)) {
69523 + if (within_module_core_rw((unsigned long)info, mod)) {
69524 if (prev)
69525 prev->next = info->next;
69526 else
69527 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69528 index 6db7a5e..25b6648 100644
69529 --- a/kernel/hrtimer.c
69530 +++ b/kernel/hrtimer.c
69531 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69532 local_irq_restore(flags);
69533 }
69534
69535 -static void run_hrtimer_softirq(struct softirq_action *h)
69536 +static void run_hrtimer_softirq(void)
69537 {
69538 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69539
69540 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69541 index 60f48fa..7f3a770 100644
69542 --- a/kernel/jump_label.c
69543 +++ b/kernel/jump_label.c
69544 @@ -13,6 +13,7 @@
69545 #include <linux/sort.h>
69546 #include <linux/err.h>
69547 #include <linux/static_key.h>
69548 +#include <linux/mm.h>
69549
69550 #ifdef HAVE_JUMP_LABEL
69551
69552 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69553
69554 size = (((unsigned long)stop - (unsigned long)start)
69555 / sizeof(struct jump_entry));
69556 + pax_open_kernel();
69557 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69558 + pax_close_kernel();
69559 }
69560
69561 static void jump_label_update(struct static_key *key, int enable);
69562 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69563 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69564 struct jump_entry *iter;
69565
69566 + pax_open_kernel();
69567 for (iter = iter_start; iter < iter_stop; iter++) {
69568 if (within_module_init(iter->code, mod))
69569 iter->code = 0;
69570 }
69571 + pax_close_kernel();
69572 }
69573
69574 static int
69575 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69576 index 2169fee..45c017a 100644
69577 --- a/kernel/kallsyms.c
69578 +++ b/kernel/kallsyms.c
69579 @@ -11,6 +11,9 @@
69580 * Changed the compression method from stem compression to "table lookup"
69581 * compression (see scripts/kallsyms.c for a more complete description)
69582 */
69583 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69584 +#define __INCLUDED_BY_HIDESYM 1
69585 +#endif
69586 #include <linux/kallsyms.h>
69587 #include <linux/module.h>
69588 #include <linux/init.h>
69589 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69590
69591 static inline int is_kernel_inittext(unsigned long addr)
69592 {
69593 + if (system_state != SYSTEM_BOOTING)
69594 + return 0;
69595 +
69596 if (addr >= (unsigned long)_sinittext
69597 && addr <= (unsigned long)_einittext)
69598 return 1;
69599 return 0;
69600 }
69601
69602 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69603 +#ifdef CONFIG_MODULES
69604 +static inline int is_module_text(unsigned long addr)
69605 +{
69606 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69607 + return 1;
69608 +
69609 + addr = ktla_ktva(addr);
69610 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69611 +}
69612 +#else
69613 +static inline int is_module_text(unsigned long addr)
69614 +{
69615 + return 0;
69616 +}
69617 +#endif
69618 +#endif
69619 +
69620 static inline int is_kernel_text(unsigned long addr)
69621 {
69622 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69623 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69624
69625 static inline int is_kernel(unsigned long addr)
69626 {
69627 +
69628 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69629 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69630 + return 1;
69631 +
69632 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69633 +#else
69634 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69635 +#endif
69636 +
69637 return 1;
69638 return in_gate_area_no_mm(addr);
69639 }
69640
69641 static int is_ksym_addr(unsigned long addr)
69642 {
69643 +
69644 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69645 + if (is_module_text(addr))
69646 + return 0;
69647 +#endif
69648 +
69649 if (all_var)
69650 return is_kernel(addr);
69651
69652 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69653
69654 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69655 {
69656 - iter->name[0] = '\0';
69657 iter->nameoff = get_symbol_offset(new_pos);
69658 iter->pos = new_pos;
69659 }
69660 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69661 {
69662 struct kallsym_iter *iter = m->private;
69663
69664 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69665 + if (current_uid())
69666 + return 0;
69667 +#endif
69668 +
69669 /* Some debugging symbols have no name. Ignore them. */
69670 if (!iter->name[0])
69671 return 0;
69672 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69673 */
69674 type = iter->exported ? toupper(iter->type) :
69675 tolower(iter->type);
69676 +
69677 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69678 type, iter->name, iter->module_name);
69679 } else
69680 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69681 struct kallsym_iter *iter;
69682 int ret;
69683
69684 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69685 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69686 if (!iter)
69687 return -ENOMEM;
69688 reset_iter(iter, 0);
69689 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69690 index 30b7b22..c726387 100644
69691 --- a/kernel/kcmp.c
69692 +++ b/kernel/kcmp.c
69693 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69694 struct task_struct *task1, *task2;
69695 int ret;
69696
69697 +#ifdef CONFIG_GRKERNSEC
69698 + return -ENOSYS;
69699 +#endif
69700 +
69701 rcu_read_lock();
69702
69703 /*
69704 diff --git a/kernel/kexec.c b/kernel/kexec.c
69705 index 5e4bd78..00c5b91 100644
69706 --- a/kernel/kexec.c
69707 +++ b/kernel/kexec.c
69708 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69709 unsigned long flags)
69710 {
69711 struct compat_kexec_segment in;
69712 - struct kexec_segment out, __user *ksegments;
69713 + struct kexec_segment out;
69714 + struct kexec_segment __user *ksegments;
69715 unsigned long i, result;
69716
69717 /* Don't allow clients that don't understand the native
69718 diff --git a/kernel/kmod.c b/kernel/kmod.c
69719 index 1c317e3..4a92a55 100644
69720 --- a/kernel/kmod.c
69721 +++ b/kernel/kmod.c
69722 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69723 kfree(info->argv);
69724 }
69725
69726 -static int call_modprobe(char *module_name, int wait)
69727 +static int call_modprobe(char *module_name, char *module_param, int wait)
69728 {
69729 static char *envp[] = {
69730 "HOME=/",
69731 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69732 NULL
69733 };
69734
69735 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69736 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69737 if (!argv)
69738 goto out;
69739
69740 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69741 argv[1] = "-q";
69742 argv[2] = "--";
69743 argv[3] = module_name; /* check free_modprobe_argv() */
69744 - argv[4] = NULL;
69745 + argv[4] = module_param;
69746 + argv[5] = NULL;
69747
69748 return call_usermodehelper_fns(modprobe_path, argv, envp,
69749 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69750 @@ -120,9 +121,8 @@ out:
69751 * If module auto-loading support is disabled then this function
69752 * becomes a no-operation.
69753 */
69754 -int __request_module(bool wait, const char *fmt, ...)
69755 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69756 {
69757 - va_list args;
69758 char module_name[MODULE_NAME_LEN];
69759 unsigned int max_modprobes;
69760 int ret;
69761 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69762 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69763 static int kmod_loop_msg;
69764
69765 - va_start(args, fmt);
69766 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69767 - va_end(args);
69768 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69769 if (ret >= MODULE_NAME_LEN)
69770 return -ENAMETOOLONG;
69771
69772 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69773 if (ret)
69774 return ret;
69775
69776 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69777 + if (!current_uid()) {
69778 + /* hack to workaround consolekit/udisks stupidity */
69779 + read_lock(&tasklist_lock);
69780 + if (!strcmp(current->comm, "mount") &&
69781 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69782 + read_unlock(&tasklist_lock);
69783 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69784 + return -EPERM;
69785 + }
69786 + read_unlock(&tasklist_lock);
69787 + }
69788 +#endif
69789 +
69790 /* If modprobe needs a service that is in a module, we get a recursive
69791 * loop. Limit the number of running kmod threads to max_threads/2 or
69792 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69793 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69794
69795 trace_module_request(module_name, wait, _RET_IP_);
69796
69797 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69798 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69799
69800 atomic_dec(&kmod_concurrent);
69801 return ret;
69802 }
69803 +
69804 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69805 +{
69806 + va_list args;
69807 + int ret;
69808 +
69809 + va_start(args, fmt);
69810 + ret = ____request_module(wait, module_param, fmt, args);
69811 + va_end(args);
69812 +
69813 + return ret;
69814 +}
69815 +
69816 +int __request_module(bool wait, const char *fmt, ...)
69817 +{
69818 + va_list args;
69819 + int ret;
69820 +
69821 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69822 + if (current_uid()) {
69823 + char module_param[MODULE_NAME_LEN];
69824 +
69825 + memset(module_param, 0, sizeof(module_param));
69826 +
69827 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69828 +
69829 + va_start(args, fmt);
69830 + ret = ____request_module(wait, module_param, fmt, args);
69831 + va_end(args);
69832 +
69833 + return ret;
69834 + }
69835 +#endif
69836 +
69837 + va_start(args, fmt);
69838 + ret = ____request_module(wait, NULL, fmt, args);
69839 + va_end(args);
69840 +
69841 + return ret;
69842 +}
69843 +
69844 EXPORT_SYMBOL(__request_module);
69845 #endif /* CONFIG_MODULES */
69846
69847 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69848 *
69849 * Thus the __user pointer cast is valid here.
69850 */
69851 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
69852 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69853
69854 /*
69855 * If ret is 0, either ____call_usermodehelper failed and the
69856 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69857 index 098f396..fe85ff1 100644
69858 --- a/kernel/kprobes.c
69859 +++ b/kernel/kprobes.c
69860 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69861 * kernel image and loaded module images reside. This is required
69862 * so x86_64 can correctly handle the %rip-relative fixups.
69863 */
69864 - kip->insns = module_alloc(PAGE_SIZE);
69865 + kip->insns = module_alloc_exec(PAGE_SIZE);
69866 if (!kip->insns) {
69867 kfree(kip);
69868 return NULL;
69869 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69870 */
69871 if (!list_is_singular(&kip->list)) {
69872 list_del(&kip->list);
69873 - module_free(NULL, kip->insns);
69874 + module_free_exec(NULL, kip->insns);
69875 kfree(kip);
69876 }
69877 return 1;
69878 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
69879 {
69880 int i, err = 0;
69881 unsigned long offset = 0, size = 0;
69882 - char *modname, namebuf[128];
69883 + char *modname, namebuf[KSYM_NAME_LEN];
69884 const char *symbol_name;
69885 void *addr;
69886 struct kprobe_blackpoint *kb;
69887 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
69888 kprobe_type = "k";
69889
69890 if (sym)
69891 - seq_printf(pi, "%p %s %s+0x%x %s ",
69892 + seq_printf(pi, "%pK %s %s+0x%x %s ",
69893 p->addr, kprobe_type, sym, offset,
69894 (modname ? modname : " "));
69895 else
69896 - seq_printf(pi, "%p %s %p ",
69897 + seq_printf(pi, "%pK %s %pK ",
69898 p->addr, kprobe_type, p->addr);
69899
69900 if (!pp)
69901 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
69902 const char *sym = NULL;
69903 unsigned int i = *(loff_t *) v;
69904 unsigned long offset = 0;
69905 - char *modname, namebuf[128];
69906 + char *modname, namebuf[KSYM_NAME_LEN];
69907
69908 head = &kprobe_table[i];
69909 preempt_disable();
69910 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
69911 index 4e316e1..5501eef 100644
69912 --- a/kernel/ksysfs.c
69913 +++ b/kernel/ksysfs.c
69914 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
69915 {
69916 if (count+1 > UEVENT_HELPER_PATH_LEN)
69917 return -ENOENT;
69918 + if (!capable(CAP_SYS_ADMIN))
69919 + return -EPERM;
69920 memcpy(uevent_helper, buf, count);
69921 uevent_helper[count] = '\0';
69922 if (count && uevent_helper[count-1] == '\n')
69923 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
69924 index 7981e5b..7f2105c 100644
69925 --- a/kernel/lockdep.c
69926 +++ b/kernel/lockdep.c
69927 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
69928 end = (unsigned long) &_end,
69929 addr = (unsigned long) obj;
69930
69931 +#ifdef CONFIG_PAX_KERNEXEC
69932 + start = ktla_ktva(start);
69933 +#endif
69934 +
69935 /*
69936 * static variable?
69937 */
69938 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
69939 if (!static_obj(lock->key)) {
69940 debug_locks_off();
69941 printk("INFO: trying to register non-static key.\n");
69942 + printk("lock:%pS key:%pS.\n", lock, lock->key);
69943 printk("the code is fine but needs lockdep annotation.\n");
69944 printk("turning off the locking correctness validator.\n");
69945 dump_stack();
69946 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
69947 if (!class)
69948 return 0;
69949 }
69950 - atomic_inc((atomic_t *)&class->ops);
69951 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
69952 if (very_verbose(class)) {
69953 printk("\nacquire class [%p] %s", class->key, class->name);
69954 if (class->name_version > 1)
69955 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
69956 index 91c32a0..7b88d63 100644
69957 --- a/kernel/lockdep_proc.c
69958 +++ b/kernel/lockdep_proc.c
69959 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
69960
69961 static void print_name(struct seq_file *m, struct lock_class *class)
69962 {
69963 - char str[128];
69964 + char str[KSYM_NAME_LEN];
69965 const char *name = class->name;
69966
69967 if (!name) {
69968 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
69969 return 0;
69970 }
69971
69972 - seq_printf(m, "%p", class->key);
69973 + seq_printf(m, "%pK", class->key);
69974 #ifdef CONFIG_DEBUG_LOCKDEP
69975 seq_printf(m, " OPS:%8ld", class->ops);
69976 #endif
69977 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
69978
69979 list_for_each_entry(entry, &class->locks_after, entry) {
69980 if (entry->distance == 1) {
69981 - seq_printf(m, " -> [%p] ", entry->class->key);
69982 + seq_printf(m, " -> [%pK] ", entry->class->key);
69983 print_name(m, entry->class);
69984 seq_puts(m, "\n");
69985 }
69986 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
69987 if (!class->key)
69988 continue;
69989
69990 - seq_printf(m, "[%p] ", class->key);
69991 + seq_printf(m, "[%pK] ", class->key);
69992 print_name(m, class);
69993 seq_puts(m, "\n");
69994 }
69995 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69996 if (!i)
69997 seq_line(m, '-', 40-namelen, namelen);
69998
69999 - snprintf(ip, sizeof(ip), "[<%p>]",
70000 + snprintf(ip, sizeof(ip), "[<%pK>]",
70001 (void *)class->contention_point[i]);
70002 seq_printf(m, "%40s %14lu %29s %pS\n",
70003 name, stats->contention_point[i],
70004 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70005 if (!i)
70006 seq_line(m, '-', 40-namelen, namelen);
70007
70008 - snprintf(ip, sizeof(ip), "[<%p>]",
70009 + snprintf(ip, sizeof(ip), "[<%pK>]",
70010 (void *)class->contending_point[i]);
70011 seq_printf(m, "%40s %14lu %29s %pS\n",
70012 name, stats->contending_point[i],
70013 diff --git a/kernel/module.c b/kernel/module.c
70014 index 3e544f4..34c3008 100644
70015 --- a/kernel/module.c
70016 +++ b/kernel/module.c
70017 @@ -59,6 +59,7 @@
70018 #include <linux/pfn.h>
70019 #include <linux/bsearch.h>
70020 #include <linux/fips.h>
70021 +#include <linux/grsecurity.h>
70022 #include "module-internal.h"
70023
70024 #define CREATE_TRACE_POINTS
70025 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70026
70027 /* Bounds of module allocation, for speeding __module_address.
70028 * Protected by module_mutex. */
70029 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70030 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70031 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70032
70033 int register_module_notifier(struct notifier_block * nb)
70034 {
70035 @@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70036 return true;
70037
70038 list_for_each_entry_rcu(mod, &modules, list) {
70039 - struct symsearch arr[] = {
70040 + struct symsearch modarr[] = {
70041 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70042 NOT_GPL_ONLY, false },
70043 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70044 @@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70045 if (mod->state == MODULE_STATE_UNFORMED)
70046 continue;
70047
70048 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70049 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70050 return true;
70051 }
70052 return false;
70053 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70054 static int percpu_modalloc(struct module *mod,
70055 unsigned long size, unsigned long align)
70056 {
70057 - if (align > PAGE_SIZE) {
70058 + if (align-1 >= PAGE_SIZE) {
70059 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70060 mod->name, align, PAGE_SIZE);
70061 align = PAGE_SIZE;
70062 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70063 static ssize_t show_coresize(struct module_attribute *mattr,
70064 struct module_kobject *mk, char *buffer)
70065 {
70066 - return sprintf(buffer, "%u\n", mk->mod->core_size);
70067 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70068 }
70069
70070 static struct module_attribute modinfo_coresize =
70071 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70072 static ssize_t show_initsize(struct module_attribute *mattr,
70073 struct module_kobject *mk, char *buffer)
70074 {
70075 - return sprintf(buffer, "%u\n", mk->mod->init_size);
70076 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70077 }
70078
70079 static struct module_attribute modinfo_initsize =
70080 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70081 */
70082 #ifdef CONFIG_SYSFS
70083
70084 -#ifdef CONFIG_KALLSYMS
70085 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70086 static inline bool sect_empty(const Elf_Shdr *sect)
70087 {
70088 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70089 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70090
70091 static void unset_module_core_ro_nx(struct module *mod)
70092 {
70093 - set_page_attributes(mod->module_core + mod->core_text_size,
70094 - mod->module_core + mod->core_size,
70095 + set_page_attributes(mod->module_core_rw,
70096 + mod->module_core_rw + mod->core_size_rw,
70097 set_memory_x);
70098 - set_page_attributes(mod->module_core,
70099 - mod->module_core + mod->core_ro_size,
70100 + set_page_attributes(mod->module_core_rx,
70101 + mod->module_core_rx + mod->core_size_rx,
70102 set_memory_rw);
70103 }
70104
70105 static void unset_module_init_ro_nx(struct module *mod)
70106 {
70107 - set_page_attributes(mod->module_init + mod->init_text_size,
70108 - mod->module_init + mod->init_size,
70109 + set_page_attributes(mod->module_init_rw,
70110 + mod->module_init_rw + mod->init_size_rw,
70111 set_memory_x);
70112 - set_page_attributes(mod->module_init,
70113 - mod->module_init + mod->init_ro_size,
70114 + set_page_attributes(mod->module_init_rx,
70115 + mod->module_init_rx + mod->init_size_rx,
70116 set_memory_rw);
70117 }
70118
70119 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
70120 list_for_each_entry_rcu(mod, &modules, list) {
70121 if (mod->state == MODULE_STATE_UNFORMED)
70122 continue;
70123 - if ((mod->module_core) && (mod->core_text_size)) {
70124 - set_page_attributes(mod->module_core,
70125 - mod->module_core + mod->core_text_size,
70126 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70127 + set_page_attributes(mod->module_core_rx,
70128 + mod->module_core_rx + mod->core_size_rx,
70129 set_memory_rw);
70130 }
70131 - if ((mod->module_init) && (mod->init_text_size)) {
70132 - set_page_attributes(mod->module_init,
70133 - mod->module_init + mod->init_text_size,
70134 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70135 + set_page_attributes(mod->module_init_rx,
70136 + mod->module_init_rx + mod->init_size_rx,
70137 set_memory_rw);
70138 }
70139 }
70140 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
70141 list_for_each_entry_rcu(mod, &modules, list) {
70142 if (mod->state == MODULE_STATE_UNFORMED)
70143 continue;
70144 - if ((mod->module_core) && (mod->core_text_size)) {
70145 - set_page_attributes(mod->module_core,
70146 - mod->module_core + mod->core_text_size,
70147 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70148 + set_page_attributes(mod->module_core_rx,
70149 + mod->module_core_rx + mod->core_size_rx,
70150 set_memory_ro);
70151 }
70152 - if ((mod->module_init) && (mod->init_text_size)) {
70153 - set_page_attributes(mod->module_init,
70154 - mod->module_init + mod->init_text_size,
70155 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70156 + set_page_attributes(mod->module_init_rx,
70157 + mod->module_init_rx + mod->init_size_rx,
70158 set_memory_ro);
70159 }
70160 }
70161 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
70162
70163 /* This may be NULL, but that's OK */
70164 unset_module_init_ro_nx(mod);
70165 - module_free(mod, mod->module_init);
70166 + module_free(mod, mod->module_init_rw);
70167 + module_free_exec(mod, mod->module_init_rx);
70168 kfree(mod->args);
70169 percpu_modfree(mod);
70170
70171 /* Free lock-classes: */
70172 - lockdep_free_key_range(mod->module_core, mod->core_size);
70173 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70174 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70175
70176 /* Finally, free the core (containing the module structure) */
70177 unset_module_core_ro_nx(mod);
70178 - module_free(mod, mod->module_core);
70179 + module_free_exec(mod, mod->module_core_rx);
70180 + module_free(mod, mod->module_core_rw);
70181
70182 #ifdef CONFIG_MPU
70183 update_protections(current->mm);
70184 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70185 int ret = 0;
70186 const struct kernel_symbol *ksym;
70187
70188 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70189 + int is_fs_load = 0;
70190 + int register_filesystem_found = 0;
70191 + char *p;
70192 +
70193 + p = strstr(mod->args, "grsec_modharden_fs");
70194 + if (p) {
70195 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70196 + /* copy \0 as well */
70197 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70198 + is_fs_load = 1;
70199 + }
70200 +#endif
70201 +
70202 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70203 const char *name = info->strtab + sym[i].st_name;
70204
70205 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70206 + /* it's a real shame this will never get ripped and copied
70207 + upstream! ;(
70208 + */
70209 + if (is_fs_load && !strcmp(name, "register_filesystem"))
70210 + register_filesystem_found = 1;
70211 +#endif
70212 +
70213 switch (sym[i].st_shndx) {
70214 case SHN_COMMON:
70215 /* We compiled with -fno-common. These are not
70216 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70217 ksym = resolve_symbol_wait(mod, info, name);
70218 /* Ok if resolved. */
70219 if (ksym && !IS_ERR(ksym)) {
70220 + pax_open_kernel();
70221 sym[i].st_value = ksym->value;
70222 + pax_close_kernel();
70223 break;
70224 }
70225
70226 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70227 secbase = (unsigned long)mod_percpu(mod);
70228 else
70229 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70230 + pax_open_kernel();
70231 sym[i].st_value += secbase;
70232 + pax_close_kernel();
70233 break;
70234 }
70235 }
70236
70237 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70238 + if (is_fs_load && !register_filesystem_found) {
70239 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70240 + ret = -EPERM;
70241 + }
70242 +#endif
70243 +
70244 return ret;
70245 }
70246
70247 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70248 || s->sh_entsize != ~0UL
70249 || strstarts(sname, ".init"))
70250 continue;
70251 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70252 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70253 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70254 + else
70255 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70256 pr_debug("\t%s\n", sname);
70257 }
70258 - switch (m) {
70259 - case 0: /* executable */
70260 - mod->core_size = debug_align(mod->core_size);
70261 - mod->core_text_size = mod->core_size;
70262 - break;
70263 - case 1: /* RO: text and ro-data */
70264 - mod->core_size = debug_align(mod->core_size);
70265 - mod->core_ro_size = mod->core_size;
70266 - break;
70267 - case 3: /* whole core */
70268 - mod->core_size = debug_align(mod->core_size);
70269 - break;
70270 - }
70271 }
70272
70273 pr_debug("Init section allocation order:\n");
70274 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70275 || s->sh_entsize != ~0UL
70276 || !strstarts(sname, ".init"))
70277 continue;
70278 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70279 - | INIT_OFFSET_MASK);
70280 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70281 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70282 + else
70283 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70284 + s->sh_entsize |= INIT_OFFSET_MASK;
70285 pr_debug("\t%s\n", sname);
70286 }
70287 - switch (m) {
70288 - case 0: /* executable */
70289 - mod->init_size = debug_align(mod->init_size);
70290 - mod->init_text_size = mod->init_size;
70291 - break;
70292 - case 1: /* RO: text and ro-data */
70293 - mod->init_size = debug_align(mod->init_size);
70294 - mod->init_ro_size = mod->init_size;
70295 - break;
70296 - case 3: /* whole init */
70297 - mod->init_size = debug_align(mod->init_size);
70298 - break;
70299 - }
70300 }
70301 }
70302
70303 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70304
70305 /* Put symbol section at end of init part of module. */
70306 symsect->sh_flags |= SHF_ALLOC;
70307 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70308 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70309 info->index.sym) | INIT_OFFSET_MASK;
70310 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70311
70312 @@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70313 }
70314
70315 /* Append room for core symbols at end of core part. */
70316 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70317 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70318 - mod->core_size += strtab_size;
70319 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70320 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70321 + mod->core_size_rx += strtab_size;
70322
70323 /* Put string table section at end of init part of module. */
70324 strsect->sh_flags |= SHF_ALLOC;
70325 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70326 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70327 info->index.str) | INIT_OFFSET_MASK;
70328 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70329 }
70330 @@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70331 /* Make sure we get permanent strtab: don't use info->strtab. */
70332 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70333
70334 + pax_open_kernel();
70335 +
70336 /* Set types up while we still have access to sections. */
70337 for (i = 0; i < mod->num_symtab; i++)
70338 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70339
70340 - mod->core_symtab = dst = mod->module_core + info->symoffs;
70341 - mod->core_strtab = s = mod->module_core + info->stroffs;
70342 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70343 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70344 src = mod->symtab;
70345 *s++ = 0;
70346 for (ndst = i = 0; i < mod->num_symtab; i++) {
70347 @@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70348 }
70349 }
70350 mod->core_num_syms = ndst;
70351 +
70352 + pax_close_kernel();
70353 }
70354 #else
70355 static inline void layout_symtab(struct module *mod, struct load_info *info)
70356 @@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70357 return size == 0 ? NULL : vmalloc_exec(size);
70358 }
70359
70360 -static void *module_alloc_update_bounds(unsigned long size)
70361 +static void *module_alloc_update_bounds_rw(unsigned long size)
70362 {
70363 void *ret = module_alloc(size);
70364
70365 if (ret) {
70366 mutex_lock(&module_mutex);
70367 /* Update module bounds. */
70368 - if ((unsigned long)ret < module_addr_min)
70369 - module_addr_min = (unsigned long)ret;
70370 - if ((unsigned long)ret + size > module_addr_max)
70371 - module_addr_max = (unsigned long)ret + size;
70372 + if ((unsigned long)ret < module_addr_min_rw)
70373 + module_addr_min_rw = (unsigned long)ret;
70374 + if ((unsigned long)ret + size > module_addr_max_rw)
70375 + module_addr_max_rw = (unsigned long)ret + size;
70376 + mutex_unlock(&module_mutex);
70377 + }
70378 + return ret;
70379 +}
70380 +
70381 +static void *module_alloc_update_bounds_rx(unsigned long size)
70382 +{
70383 + void *ret = module_alloc_exec(size);
70384 +
70385 + if (ret) {
70386 + mutex_lock(&module_mutex);
70387 + /* Update module bounds. */
70388 + if ((unsigned long)ret < module_addr_min_rx)
70389 + module_addr_min_rx = (unsigned long)ret;
70390 + if ((unsigned long)ret + size > module_addr_max_rx)
70391 + module_addr_max_rx = (unsigned long)ret + size;
70392 mutex_unlock(&module_mutex);
70393 }
70394 return ret;
70395 @@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70396 static int check_modinfo(struct module *mod, struct load_info *info)
70397 {
70398 const char *modmagic = get_modinfo(info, "vermagic");
70399 + const char *license = get_modinfo(info, "license");
70400 int err;
70401
70402 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70403 + if (!license || !license_is_gpl_compatible(license))
70404 + return -ENOEXEC;
70405 +#endif
70406 +
70407 /* This is allowed: modprobe --force will invalidate it. */
70408 if (!modmagic) {
70409 err = try_to_force_load(mod, "bad vermagic");
70410 @@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70411 }
70412
70413 /* Set up license info based on the info section */
70414 - set_license(mod, get_modinfo(info, "license"));
70415 + set_license(mod, license);
70416
70417 return 0;
70418 }
70419 @@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70420 void *ptr;
70421
70422 /* Do the allocs. */
70423 - ptr = module_alloc_update_bounds(mod->core_size);
70424 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70425 /*
70426 * The pointer to this block is stored in the module structure
70427 * which is inside the block. Just mark it as not being a
70428 @@ -2758,10 +2802,10 @@ static int move_module(struct module *mod, struct load_info *info)
70429 if (!ptr)
70430 return -ENOMEM;
70431
70432 - memset(ptr, 0, mod->core_size);
70433 - mod->module_core = ptr;
70434 + memset(ptr, 0, mod->core_size_rw);
70435 + mod->module_core_rw = ptr;
70436
70437 - ptr = module_alloc_update_bounds(mod->init_size);
70438 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70439 /*
70440 * The pointer to this block is stored in the module structure
70441 * which is inside the block. This block doesn't need to be
70442 @@ -2769,12 +2813,39 @@ static int move_module(struct module *mod, struct load_info *info)
70443 * after the module is initialized.
70444 */
70445 kmemleak_ignore(ptr);
70446 - if (!ptr && mod->init_size) {
70447 - module_free(mod, mod->module_core);
70448 + if (!ptr && mod->init_size_rw) {
70449 + module_free(mod, mod->module_core_rw);
70450 return -ENOMEM;
70451 }
70452 - memset(ptr, 0, mod->init_size);
70453 - mod->module_init = ptr;
70454 + memset(ptr, 0, mod->init_size_rw);
70455 + mod->module_init_rw = ptr;
70456 +
70457 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70458 + kmemleak_not_leak(ptr);
70459 + if (!ptr) {
70460 + module_free(mod, mod->module_init_rw);
70461 + module_free(mod, mod->module_core_rw);
70462 + return -ENOMEM;
70463 + }
70464 +
70465 + pax_open_kernel();
70466 + memset(ptr, 0, mod->core_size_rx);
70467 + pax_close_kernel();
70468 + mod->module_core_rx = ptr;
70469 +
70470 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70471 + kmemleak_ignore(ptr);
70472 + if (!ptr && mod->init_size_rx) {
70473 + module_free_exec(mod, mod->module_core_rx);
70474 + module_free(mod, mod->module_init_rw);
70475 + module_free(mod, mod->module_core_rw);
70476 + return -ENOMEM;
70477 + }
70478 +
70479 + pax_open_kernel();
70480 + memset(ptr, 0, mod->init_size_rx);
70481 + pax_close_kernel();
70482 + mod->module_init_rx = ptr;
70483
70484 /* Transfer each section which specifies SHF_ALLOC */
70485 pr_debug("final section addresses:\n");
70486 @@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70487 if (!(shdr->sh_flags & SHF_ALLOC))
70488 continue;
70489
70490 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
70491 - dest = mod->module_init
70492 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70493 - else
70494 - dest = mod->module_core + shdr->sh_entsize;
70495 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70496 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70497 + dest = mod->module_init_rw
70498 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70499 + else
70500 + dest = mod->module_init_rx
70501 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70502 + } else {
70503 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70504 + dest = mod->module_core_rw + shdr->sh_entsize;
70505 + else
70506 + dest = mod->module_core_rx + shdr->sh_entsize;
70507 + }
70508 +
70509 + if (shdr->sh_type != SHT_NOBITS) {
70510 +
70511 +#ifdef CONFIG_PAX_KERNEXEC
70512 +#ifdef CONFIG_X86_64
70513 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70514 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70515 +#endif
70516 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70517 + pax_open_kernel();
70518 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70519 + pax_close_kernel();
70520 + } else
70521 +#endif
70522
70523 - if (shdr->sh_type != SHT_NOBITS)
70524 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70525 + }
70526 /* Update sh_addr to point to copy in image. */
70527 - shdr->sh_addr = (unsigned long)dest;
70528 +
70529 +#ifdef CONFIG_PAX_KERNEXEC
70530 + if (shdr->sh_flags & SHF_EXECINSTR)
70531 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
70532 + else
70533 +#endif
70534 +
70535 + shdr->sh_addr = (unsigned long)dest;
70536 pr_debug("\t0x%lx %s\n",
70537 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70538 }
70539 @@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70540 * Do it before processing of module parameters, so the module
70541 * can provide parameter accessor functions of its own.
70542 */
70543 - if (mod->module_init)
70544 - flush_icache_range((unsigned long)mod->module_init,
70545 - (unsigned long)mod->module_init
70546 - + mod->init_size);
70547 - flush_icache_range((unsigned long)mod->module_core,
70548 - (unsigned long)mod->module_core + mod->core_size);
70549 + if (mod->module_init_rx)
70550 + flush_icache_range((unsigned long)mod->module_init_rx,
70551 + (unsigned long)mod->module_init_rx
70552 + + mod->init_size_rx);
70553 + flush_icache_range((unsigned long)mod->module_core_rx,
70554 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
70555
70556 set_fs(old_fs);
70557 }
70558 @@ -2924,8 +3024,10 @@ out:
70559 static void module_deallocate(struct module *mod, struct load_info *info)
70560 {
70561 percpu_modfree(mod);
70562 - module_free(mod, mod->module_init);
70563 - module_free(mod, mod->module_core);
70564 + module_free_exec(mod, mod->module_init_rx);
70565 + module_free_exec(mod, mod->module_core_rx);
70566 + module_free(mod, mod->module_init_rw);
70567 + module_free(mod, mod->module_core_rw);
70568 }
70569
70570 int __weak module_finalize(const Elf_Ehdr *hdr,
70571 @@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70572 static int post_relocation(struct module *mod, const struct load_info *info)
70573 {
70574 /* Sort exception table now relocations are done. */
70575 + pax_open_kernel();
70576 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70577 + pax_close_kernel();
70578
70579 /* Copy relocated percpu area over. */
70580 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70581 @@ -3036,9 +3140,38 @@ again:
70582 if (err)
70583 goto free_unload;
70584
70585 + /* Now copy in args */
70586 + mod->args = strndup_user(uargs, ~0UL >> 1);
70587 + if (IS_ERR(mod->args)) {
70588 + err = PTR_ERR(mod->args);
70589 + goto free_unload;
70590 + }
70591 +
70592 /* Set up MODINFO_ATTR fields */
70593 setup_modinfo(mod, &info);
70594
70595 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70596 + {
70597 + char *p, *p2;
70598 +
70599 + if (strstr(mod->args, "grsec_modharden_netdev")) {
70600 + 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);
70601 + err = -EPERM;
70602 + goto free_modinfo;
70603 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70604 + p += sizeof("grsec_modharden_normal") - 1;
70605 + p2 = strstr(p, "_");
70606 + if (p2) {
70607 + *p2 = '\0';
70608 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70609 + *p2 = '_';
70610 + }
70611 + err = -EPERM;
70612 + goto free_modinfo;
70613 + }
70614 + }
70615 +#endif
70616 +
70617 /* Fix up syms, so that st_value is a pointer to location. */
70618 err = simplify_symbols(mod, &info);
70619 if (err < 0)
70620 @@ -3104,11 +3237,11 @@ again:
70621 mutex_unlock(&module_mutex);
70622 dynamic_debug_remove(info.debug);
70623 synchronize_sched();
70624 - kfree(mod->args);
70625 free_arch_cleanup:
70626 module_arch_cleanup(mod);
70627 free_modinfo:
70628 free_modinfo(mod);
70629 + kfree(mod->args);
70630 free_unload:
70631 module_unload_free(mod);
70632 unlink_mod:
70633 @@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70634 MODULE_STATE_COMING, mod);
70635
70636 /* Set RO and NX regions for core */
70637 - set_section_ro_nx(mod->module_core,
70638 - mod->core_text_size,
70639 - mod->core_ro_size,
70640 - mod->core_size);
70641 + set_section_ro_nx(mod->module_core_rx,
70642 + mod->core_size_rx,
70643 + mod->core_size_rx,
70644 + mod->core_size_rx);
70645
70646 /* Set RO and NX regions for init */
70647 - set_section_ro_nx(mod->module_init,
70648 - mod->init_text_size,
70649 - mod->init_ro_size,
70650 - mod->init_size);
70651 + set_section_ro_nx(mod->module_init_rx,
70652 + mod->init_size_rx,
70653 + mod->init_size_rx,
70654 + mod->init_size_rx);
70655
70656 do_mod_ctors(mod);
70657 /* Start the module */
70658 @@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70659 mod->strtab = mod->core_strtab;
70660 #endif
70661 unset_module_init_ro_nx(mod);
70662 - module_free(mod, mod->module_init);
70663 - mod->module_init = NULL;
70664 - mod->init_size = 0;
70665 - mod->init_ro_size = 0;
70666 - mod->init_text_size = 0;
70667 + module_free(mod, mod->module_init_rw);
70668 + module_free_exec(mod, mod->module_init_rx);
70669 + mod->module_init_rw = NULL;
70670 + mod->module_init_rx = NULL;
70671 + mod->init_size_rw = 0;
70672 + mod->init_size_rx = 0;
70673 mutex_unlock(&module_mutex);
70674 wake_up_all(&module_wq);
70675
70676 @@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70677 unsigned long nextval;
70678
70679 /* At worse, next value is at end of module */
70680 - if (within_module_init(addr, mod))
70681 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70682 + if (within_module_init_rx(addr, mod))
70683 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70684 + else if (within_module_init_rw(addr, mod))
70685 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70686 + else if (within_module_core_rx(addr, mod))
70687 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70688 + else if (within_module_core_rw(addr, mod))
70689 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70690 else
70691 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70692 + return NULL;
70693
70694 /* Scan for closest preceding symbol, and next symbol. (ELF
70695 starts real symbols at 1). */
70696 @@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70697 return 0;
70698
70699 seq_printf(m, "%s %u",
70700 - mod->name, mod->init_size + mod->core_size);
70701 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70702 print_unload_info(m, mod);
70703
70704 /* Informative for users. */
70705 @@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70706 mod->state == MODULE_STATE_COMING ? "Loading":
70707 "Live");
70708 /* Used by oprofile and other similar tools. */
70709 - seq_printf(m, " 0x%pK", mod->module_core);
70710 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70711
70712 /* Taints info */
70713 if (mod->taints)
70714 @@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70715
70716 static int __init proc_modules_init(void)
70717 {
70718 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70719 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70720 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70721 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70722 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70723 +#else
70724 proc_create("modules", 0, NULL, &proc_modules_operations);
70725 +#endif
70726 +#else
70727 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70728 +#endif
70729 return 0;
70730 }
70731 module_init(proc_modules_init);
70732 @@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70733 {
70734 struct module *mod;
70735
70736 - if (addr < module_addr_min || addr > module_addr_max)
70737 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70738 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70739 return NULL;
70740
70741 list_for_each_entry_rcu(mod, &modules, list) {
70742 if (mod->state == MODULE_STATE_UNFORMED)
70743 continue;
70744 - if (within_module_core(addr, mod)
70745 - || within_module_init(addr, mod))
70746 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70747 return mod;
70748 }
70749 return NULL;
70750 @@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70751 */
70752 struct module *__module_text_address(unsigned long addr)
70753 {
70754 - struct module *mod = __module_address(addr);
70755 + struct module *mod;
70756 +
70757 +#ifdef CONFIG_X86_32
70758 + addr = ktla_ktva(addr);
70759 +#endif
70760 +
70761 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70762 + return NULL;
70763 +
70764 + mod = __module_address(addr);
70765 +
70766 if (mod) {
70767 /* Make sure it's within the text section. */
70768 - if (!within(addr, mod->module_init, mod->init_text_size)
70769 - && !within(addr, mod->module_core, mod->core_text_size))
70770 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70771 mod = NULL;
70772 }
70773 return mod;
70774 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70775 index 7e3443f..b2a1e6b 100644
70776 --- a/kernel/mutex-debug.c
70777 +++ b/kernel/mutex-debug.c
70778 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70779 }
70780
70781 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70782 - struct thread_info *ti)
70783 + struct task_struct *task)
70784 {
70785 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70786
70787 /* Mark the current thread as blocked on the lock: */
70788 - ti->task->blocked_on = waiter;
70789 + task->blocked_on = waiter;
70790 }
70791
70792 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70793 - struct thread_info *ti)
70794 + struct task_struct *task)
70795 {
70796 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70797 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70798 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70799 - ti->task->blocked_on = NULL;
70800 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
70801 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70802 + task->blocked_on = NULL;
70803
70804 list_del_init(&waiter->list);
70805 waiter->task = NULL;
70806 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70807 index 0799fd3..d06ae3b 100644
70808 --- a/kernel/mutex-debug.h
70809 +++ b/kernel/mutex-debug.h
70810 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70811 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70812 extern void debug_mutex_add_waiter(struct mutex *lock,
70813 struct mutex_waiter *waiter,
70814 - struct thread_info *ti);
70815 + struct task_struct *task);
70816 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70817 - struct thread_info *ti);
70818 + struct task_struct *task);
70819 extern void debug_mutex_unlock(struct mutex *lock);
70820 extern void debug_mutex_init(struct mutex *lock, const char *name,
70821 struct lock_class_key *key);
70822 diff --git a/kernel/mutex.c b/kernel/mutex.c
70823 index a307cc9..27fd2e9 100644
70824 --- a/kernel/mutex.c
70825 +++ b/kernel/mutex.c
70826 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70827 spin_lock_mutex(&lock->wait_lock, flags);
70828
70829 debug_mutex_lock_common(lock, &waiter);
70830 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70831 + debug_mutex_add_waiter(lock, &waiter, task);
70832
70833 /* add waiting tasks to the end of the waitqueue (FIFO): */
70834 list_add_tail(&waiter.list, &lock->wait_list);
70835 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70836 * TASK_UNINTERRUPTIBLE case.)
70837 */
70838 if (unlikely(signal_pending_state(state, task))) {
70839 - mutex_remove_waiter(lock, &waiter,
70840 - task_thread_info(task));
70841 + mutex_remove_waiter(lock, &waiter, task);
70842 mutex_release(&lock->dep_map, 1, ip);
70843 spin_unlock_mutex(&lock->wait_lock, flags);
70844
70845 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70846 done:
70847 lock_acquired(&lock->dep_map, ip);
70848 /* got the lock - rejoice! */
70849 - mutex_remove_waiter(lock, &waiter, current_thread_info());
70850 + mutex_remove_waiter(lock, &waiter, task);
70851 mutex_set_owner(lock);
70852
70853 /* set it to 0 if there are no waiters left: */
70854 diff --git a/kernel/notifier.c b/kernel/notifier.c
70855 index 2d5cc4c..d9ea600 100644
70856 --- a/kernel/notifier.c
70857 +++ b/kernel/notifier.c
70858 @@ -5,6 +5,7 @@
70859 #include <linux/rcupdate.h>
70860 #include <linux/vmalloc.h>
70861 #include <linux/reboot.h>
70862 +#include <linux/mm.h>
70863
70864 /*
70865 * Notifier list for kernel code which wants to be called
70866 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70867 while ((*nl) != NULL) {
70868 if (n->priority > (*nl)->priority)
70869 break;
70870 - nl = &((*nl)->next);
70871 + nl = (struct notifier_block **)&((*nl)->next);
70872 }
70873 - n->next = *nl;
70874 + pax_open_kernel();
70875 + *(const void **)&n->next = *nl;
70876 rcu_assign_pointer(*nl, n);
70877 + pax_close_kernel();
70878 return 0;
70879 }
70880
70881 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
70882 return 0;
70883 if (n->priority > (*nl)->priority)
70884 break;
70885 - nl = &((*nl)->next);
70886 + nl = (struct notifier_block **)&((*nl)->next);
70887 }
70888 - n->next = *nl;
70889 + pax_open_kernel();
70890 + *(const void **)&n->next = *nl;
70891 rcu_assign_pointer(*nl, n);
70892 + pax_close_kernel();
70893 return 0;
70894 }
70895
70896 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
70897 {
70898 while ((*nl) != NULL) {
70899 if ((*nl) == n) {
70900 + pax_open_kernel();
70901 rcu_assign_pointer(*nl, n->next);
70902 + pax_close_kernel();
70903 return 0;
70904 }
70905 - nl = &((*nl)->next);
70906 + nl = (struct notifier_block **)&((*nl)->next);
70907 }
70908 return -ENOENT;
70909 }
70910 diff --git a/kernel/panic.c b/kernel/panic.c
70911 index e1b2822..5edc1d9 100644
70912 --- a/kernel/panic.c
70913 +++ b/kernel/panic.c
70914 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
70915 const char *board;
70916
70917 printk(KERN_WARNING "------------[ cut here ]------------\n");
70918 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
70919 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
70920 board = dmi_get_system_info(DMI_PRODUCT_NAME);
70921 if (board)
70922 printk(KERN_WARNING "Hardware name: %s\n", board);
70923 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
70924 */
70925 void __stack_chk_fail(void)
70926 {
70927 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
70928 + dump_stack();
70929 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
70930 __builtin_return_address(0));
70931 }
70932 EXPORT_SYMBOL(__stack_chk_fail);
70933 diff --git a/kernel/pid.c b/kernel/pid.c
70934 index aebd4f5..1693c13 100644
70935 --- a/kernel/pid.c
70936 +++ b/kernel/pid.c
70937 @@ -33,6 +33,7 @@
70938 #include <linux/rculist.h>
70939 #include <linux/bootmem.h>
70940 #include <linux/hash.h>
70941 +#include <linux/security.h>
70942 #include <linux/pid_namespace.h>
70943 #include <linux/init_task.h>
70944 #include <linux/syscalls.h>
70945 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
70946
70947 int pid_max = PID_MAX_DEFAULT;
70948
70949 -#define RESERVED_PIDS 300
70950 +#define RESERVED_PIDS 500
70951
70952 int pid_max_min = RESERVED_PIDS + 1;
70953 int pid_max_max = PID_MAX_LIMIT;
70954 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
70955 */
70956 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
70957 {
70958 + struct task_struct *task;
70959 +
70960 rcu_lockdep_assert(rcu_read_lock_held(),
70961 "find_task_by_pid_ns() needs rcu_read_lock()"
70962 " protection");
70963 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70964 +
70965 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70966 +
70967 + if (gr_pid_is_chrooted(task))
70968 + return NULL;
70969 +
70970 + return task;
70971 }
70972
70973 struct task_struct *find_task_by_vpid(pid_t vnr)
70974 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
70975 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
70976 }
70977
70978 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
70979 +{
70980 + rcu_lockdep_assert(rcu_read_lock_held(),
70981 + "find_task_by_pid_ns() needs rcu_read_lock()"
70982 + " protection");
70983 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
70984 +}
70985 +
70986 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
70987 {
70988 struct pid *pid;
70989 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
70990 index 125cb67..2e5c8ad 100644
70991 --- a/kernel/posix-cpu-timers.c
70992 +++ b/kernel/posix-cpu-timers.c
70993 @@ -6,9 +6,11 @@
70994 #include <linux/posix-timers.h>
70995 #include <linux/errno.h>
70996 #include <linux/math64.h>
70997 +#include <linux/security.h>
70998 #include <asm/uaccess.h>
70999 #include <linux/kernel_stat.h>
71000 #include <trace/events/timer.h>
71001 +#include <linux/random.h>
71002
71003 /*
71004 * Called after updating RLIMIT_CPU to run cpu timer and update
71005 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71006 */
71007 void posix_cpu_timers_exit(struct task_struct *tsk)
71008 {
71009 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71010 + sizeof(unsigned long long));
71011 cleanup_timers(tsk->cpu_timers,
71012 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71013
71014 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71015
71016 static __init int init_posix_cpu_timers(void)
71017 {
71018 - struct k_clock process = {
71019 + static struct k_clock process = {
71020 .clock_getres = process_cpu_clock_getres,
71021 .clock_get = process_cpu_clock_get,
71022 .timer_create = process_cpu_timer_create,
71023 .nsleep = process_cpu_nsleep,
71024 .nsleep_restart = process_cpu_nsleep_restart,
71025 };
71026 - struct k_clock thread = {
71027 + static struct k_clock thread = {
71028 .clock_getres = thread_cpu_clock_getres,
71029 .clock_get = thread_cpu_clock_get,
71030 .timer_create = thread_cpu_timer_create,
71031 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71032 index 69185ae..cc2847a 100644
71033 --- a/kernel/posix-timers.c
71034 +++ b/kernel/posix-timers.c
71035 @@ -43,6 +43,7 @@
71036 #include <linux/idr.h>
71037 #include <linux/posix-clock.h>
71038 #include <linux/posix-timers.h>
71039 +#include <linux/grsecurity.h>
71040 #include <linux/syscalls.h>
71041 #include <linux/wait.h>
71042 #include <linux/workqueue.h>
71043 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71044 * which we beg off on and pass to do_sys_settimeofday().
71045 */
71046
71047 -static struct k_clock posix_clocks[MAX_CLOCKS];
71048 +static struct k_clock *posix_clocks[MAX_CLOCKS];
71049
71050 /*
71051 * These ones are defined below.
71052 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71053 */
71054 static __init int init_posix_timers(void)
71055 {
71056 - struct k_clock clock_realtime = {
71057 + static struct k_clock clock_realtime = {
71058 .clock_getres = hrtimer_get_res,
71059 .clock_get = posix_clock_realtime_get,
71060 .clock_set = posix_clock_realtime_set,
71061 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71062 .timer_get = common_timer_get,
71063 .timer_del = common_timer_del,
71064 };
71065 - struct k_clock clock_monotonic = {
71066 + static struct k_clock clock_monotonic = {
71067 .clock_getres = hrtimer_get_res,
71068 .clock_get = posix_ktime_get_ts,
71069 .nsleep = common_nsleep,
71070 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71071 .timer_get = common_timer_get,
71072 .timer_del = common_timer_del,
71073 };
71074 - struct k_clock clock_monotonic_raw = {
71075 + static struct k_clock clock_monotonic_raw = {
71076 .clock_getres = hrtimer_get_res,
71077 .clock_get = posix_get_monotonic_raw,
71078 };
71079 - struct k_clock clock_realtime_coarse = {
71080 + static struct k_clock clock_realtime_coarse = {
71081 .clock_getres = posix_get_coarse_res,
71082 .clock_get = posix_get_realtime_coarse,
71083 };
71084 - struct k_clock clock_monotonic_coarse = {
71085 + static struct k_clock clock_monotonic_coarse = {
71086 .clock_getres = posix_get_coarse_res,
71087 .clock_get = posix_get_monotonic_coarse,
71088 };
71089 - struct k_clock clock_boottime = {
71090 + static struct k_clock clock_boottime = {
71091 .clock_getres = hrtimer_get_res,
71092 .clock_get = posix_get_boottime,
71093 .nsleep = common_nsleep,
71094 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71095 return;
71096 }
71097
71098 - posix_clocks[clock_id] = *new_clock;
71099 + posix_clocks[clock_id] = new_clock;
71100 }
71101 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71102
71103 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71104 return (id & CLOCKFD_MASK) == CLOCKFD ?
71105 &clock_posix_dynamic : &clock_posix_cpu;
71106
71107 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71108 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71109 return NULL;
71110 - return &posix_clocks[id];
71111 + return posix_clocks[id];
71112 }
71113
71114 static int common_timer_create(struct k_itimer *new_timer)
71115 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71116 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71117 return -EFAULT;
71118
71119 + /* only the CLOCK_REALTIME clock can be set, all other clocks
71120 + have their clock_set fptr set to a nosettime dummy function
71121 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71122 + call common_clock_set, which calls do_sys_settimeofday, which
71123 + we hook
71124 + */
71125 +
71126 return kc->clock_set(which_clock, &new_tp);
71127 }
71128
71129 diff --git a/kernel/power/process.c b/kernel/power/process.c
71130 index 87da817..30ddd13 100644
71131 --- a/kernel/power/process.c
71132 +++ b/kernel/power/process.c
71133 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71134 u64 elapsed_csecs64;
71135 unsigned int elapsed_csecs;
71136 bool wakeup = false;
71137 + bool timedout = false;
71138
71139 do_gettimeofday(&start);
71140
71141 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71142
71143 while (true) {
71144 todo = 0;
71145 + if (time_after(jiffies, end_time))
71146 + timedout = true;
71147 read_lock(&tasklist_lock);
71148 do_each_thread(g, p) {
71149 if (p == current || !freeze_task(p))
71150 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71151 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71152 * transition can't race with task state testing here.
71153 */
71154 - if (!task_is_stopped_or_traced(p) &&
71155 - !freezer_should_skip(p))
71156 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71157 todo++;
71158 + if (timedout) {
71159 + printk(KERN_ERR "Task refusing to freeze:\n");
71160 + sched_show_task(p);
71161 + }
71162 + }
71163 } while_each_thread(g, p);
71164 read_unlock(&tasklist_lock);
71165
71166 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71167 todo += wq_busy;
71168 }
71169
71170 - if (!todo || time_after(jiffies, end_time))
71171 + if (!todo || timedout)
71172 break;
71173
71174 if (pm_wakeup_pending()) {
71175 diff --git a/kernel/printk.c b/kernel/printk.c
71176 index f8e0b5a..dda2a5c 100644
71177 --- a/kernel/printk.c
71178 +++ b/kernel/printk.c
71179 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71180 if (from_file && type != SYSLOG_ACTION_OPEN)
71181 return 0;
71182
71183 +#ifdef CONFIG_GRKERNSEC_DMESG
71184 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71185 + return -EPERM;
71186 +#endif
71187 +
71188 if (syslog_action_restricted(type)) {
71189 if (capable(CAP_SYSLOG))
71190 return 0;
71191 diff --git a/kernel/profile.c b/kernel/profile.c
71192 index 76b8e77..a2930e8 100644
71193 --- a/kernel/profile.c
71194 +++ b/kernel/profile.c
71195 @@ -39,7 +39,7 @@ struct profile_hit {
71196 /* Oprofile timer tick hook */
71197 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71198
71199 -static atomic_t *prof_buffer;
71200 +static atomic_unchecked_t *prof_buffer;
71201 static unsigned long prof_len, prof_shift;
71202
71203 int prof_on __read_mostly;
71204 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71205 hits[i].pc = 0;
71206 continue;
71207 }
71208 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71209 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71210 hits[i].hits = hits[i].pc = 0;
71211 }
71212 }
71213 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71214 * Add the current hit(s) and flush the write-queue out
71215 * to the global buffer:
71216 */
71217 - atomic_add(nr_hits, &prof_buffer[pc]);
71218 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71219 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71220 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71221 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71222 hits[i].pc = hits[i].hits = 0;
71223 }
71224 out:
71225 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71226 {
71227 unsigned long pc;
71228 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71229 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71230 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71231 }
71232 #endif /* !CONFIG_SMP */
71233
71234 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71235 return -EFAULT;
71236 buf++; p++; count--; read++;
71237 }
71238 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71239 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71240 if (copy_to_user(buf, (void *)pnt, count))
71241 return -EFAULT;
71242 read += count;
71243 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71244 }
71245 #endif
71246 profile_discard_flip_buffers();
71247 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71248 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71249 return count;
71250 }
71251
71252 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71253 index fbea91d..9bf15e8 100644
71254 --- a/kernel/ptrace.c
71255 +++ b/kernel/ptrace.c
71256 @@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71257
71258 if (seize)
71259 flags |= PT_SEIZED;
71260 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71261 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71262 flags |= PT_PTRACE_CAP;
71263 task->ptrace = flags;
71264
71265 @@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71266 break;
71267 return -EIO;
71268 }
71269 - if (copy_to_user(dst, buf, retval))
71270 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71271 return -EFAULT;
71272 copied += retval;
71273 src += retval;
71274 @@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71275 bool seized = child->ptrace & PT_SEIZED;
71276 int ret = -EIO;
71277 siginfo_t siginfo, *si;
71278 - void __user *datavp = (void __user *) data;
71279 + void __user *datavp = (__force void __user *) data;
71280 unsigned long __user *datalp = datavp;
71281 unsigned long flags;
71282
71283 @@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71284 goto out;
71285 }
71286
71287 + if (gr_handle_ptrace(child, request)) {
71288 + ret = -EPERM;
71289 + goto out_put_task_struct;
71290 + }
71291 +
71292 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71293 ret = ptrace_attach(child, request, addr, data);
71294 /*
71295 * Some architectures need to do book-keeping after
71296 * a ptrace attach.
71297 */
71298 - if (!ret)
71299 + if (!ret) {
71300 arch_ptrace_attach(child);
71301 + gr_audit_ptrace(child);
71302 + }
71303 goto out_put_task_struct;
71304 }
71305
71306 @@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71307 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71308 if (copied != sizeof(tmp))
71309 return -EIO;
71310 - return put_user(tmp, (unsigned long __user *)data);
71311 + return put_user(tmp, (__force unsigned long __user *)data);
71312 }
71313
71314 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71315 @@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71316 goto out;
71317 }
71318
71319 + if (gr_handle_ptrace(child, request)) {
71320 + ret = -EPERM;
71321 + goto out_put_task_struct;
71322 + }
71323 +
71324 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71325 ret = ptrace_attach(child, request, addr, data);
71326 /*
71327 * Some architectures need to do book-keeping after
71328 * a ptrace attach.
71329 */
71330 - if (!ret)
71331 + if (!ret) {
71332 arch_ptrace_attach(child);
71333 + gr_audit_ptrace(child);
71334 + }
71335 goto out_put_task_struct;
71336 }
71337
71338 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71339 index e4c6a59..c86621a 100644
71340 --- a/kernel/rcutiny.c
71341 +++ b/kernel/rcutiny.c
71342 @@ -46,7 +46,7 @@
71343 struct rcu_ctrlblk;
71344 static void invoke_rcu_callbacks(void);
71345 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71346 -static void rcu_process_callbacks(struct softirq_action *unused);
71347 +static void rcu_process_callbacks(void);
71348 static void __call_rcu(struct rcu_head *head,
71349 void (*func)(struct rcu_head *rcu),
71350 struct rcu_ctrlblk *rcp);
71351 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71352 rcu_is_callbacks_kthread()));
71353 }
71354
71355 -static void rcu_process_callbacks(struct softirq_action *unused)
71356 +static void rcu_process_callbacks(void)
71357 {
71358 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71359 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71360 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71361 index 3d01902..afbf46e 100644
71362 --- a/kernel/rcutiny_plugin.h
71363 +++ b/kernel/rcutiny_plugin.h
71364 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71365 have_rcu_kthread_work = morework;
71366 local_irq_restore(flags);
71367 if (work)
71368 - rcu_process_callbacks(NULL);
71369 + rcu_process_callbacks();
71370 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71371 }
71372
71373 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71374 index aaa7b9f..055ff1e 100644
71375 --- a/kernel/rcutorture.c
71376 +++ b/kernel/rcutorture.c
71377 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71378 { 0 };
71379 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71380 { 0 };
71381 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71382 -static atomic_t n_rcu_torture_alloc;
71383 -static atomic_t n_rcu_torture_alloc_fail;
71384 -static atomic_t n_rcu_torture_free;
71385 -static atomic_t n_rcu_torture_mberror;
71386 -static atomic_t n_rcu_torture_error;
71387 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71388 +static atomic_unchecked_t n_rcu_torture_alloc;
71389 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
71390 +static atomic_unchecked_t n_rcu_torture_free;
71391 +static atomic_unchecked_t n_rcu_torture_mberror;
71392 +static atomic_unchecked_t n_rcu_torture_error;
71393 static long n_rcu_torture_barrier_error;
71394 static long n_rcu_torture_boost_ktrerror;
71395 static long n_rcu_torture_boost_rterror;
71396 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71397
71398 spin_lock_bh(&rcu_torture_lock);
71399 if (list_empty(&rcu_torture_freelist)) {
71400 - atomic_inc(&n_rcu_torture_alloc_fail);
71401 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71402 spin_unlock_bh(&rcu_torture_lock);
71403 return NULL;
71404 }
71405 - atomic_inc(&n_rcu_torture_alloc);
71406 + atomic_inc_unchecked(&n_rcu_torture_alloc);
71407 p = rcu_torture_freelist.next;
71408 list_del_init(p);
71409 spin_unlock_bh(&rcu_torture_lock);
71410 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71411 static void
71412 rcu_torture_free(struct rcu_torture *p)
71413 {
71414 - atomic_inc(&n_rcu_torture_free);
71415 + atomic_inc_unchecked(&n_rcu_torture_free);
71416 spin_lock_bh(&rcu_torture_lock);
71417 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71418 spin_unlock_bh(&rcu_torture_lock);
71419 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71420 i = rp->rtort_pipe_count;
71421 if (i > RCU_TORTURE_PIPE_LEN)
71422 i = RCU_TORTURE_PIPE_LEN;
71423 - atomic_inc(&rcu_torture_wcount[i]);
71424 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71425 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71426 rp->rtort_mbtest = 0;
71427 rcu_torture_free(rp);
71428 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71429 i = rp->rtort_pipe_count;
71430 if (i > RCU_TORTURE_PIPE_LEN)
71431 i = RCU_TORTURE_PIPE_LEN;
71432 - atomic_inc(&rcu_torture_wcount[i]);
71433 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71434 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71435 rp->rtort_mbtest = 0;
71436 list_del(&rp->rtort_free);
71437 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71438 i = old_rp->rtort_pipe_count;
71439 if (i > RCU_TORTURE_PIPE_LEN)
71440 i = RCU_TORTURE_PIPE_LEN;
71441 - atomic_inc(&rcu_torture_wcount[i]);
71442 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71443 old_rp->rtort_pipe_count++;
71444 cur_ops->deferred_free(old_rp);
71445 }
71446 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71447 }
71448 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71449 if (p->rtort_mbtest == 0)
71450 - atomic_inc(&n_rcu_torture_mberror);
71451 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71452 spin_lock(&rand_lock);
71453 cur_ops->read_delay(&rand);
71454 n_rcu_torture_timers++;
71455 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71456 }
71457 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71458 if (p->rtort_mbtest == 0)
71459 - atomic_inc(&n_rcu_torture_mberror);
71460 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71461 cur_ops->read_delay(&rand);
71462 preempt_disable();
71463 pipe_count = p->rtort_pipe_count;
71464 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71465 rcu_torture_current,
71466 rcu_torture_current_version,
71467 list_empty(&rcu_torture_freelist),
71468 - atomic_read(&n_rcu_torture_alloc),
71469 - atomic_read(&n_rcu_torture_alloc_fail),
71470 - atomic_read(&n_rcu_torture_free));
71471 + atomic_read_unchecked(&n_rcu_torture_alloc),
71472 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71473 + atomic_read_unchecked(&n_rcu_torture_free));
71474 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71475 - atomic_read(&n_rcu_torture_mberror),
71476 + atomic_read_unchecked(&n_rcu_torture_mberror),
71477 n_rcu_torture_boost_ktrerror,
71478 n_rcu_torture_boost_rterror);
71479 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71480 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71481 n_barrier_attempts,
71482 n_rcu_torture_barrier_error);
71483 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71484 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71485 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71486 n_rcu_torture_barrier_error != 0 ||
71487 n_rcu_torture_boost_ktrerror != 0 ||
71488 n_rcu_torture_boost_rterror != 0 ||
71489 n_rcu_torture_boost_failure != 0 ||
71490 i > 1) {
71491 cnt += sprintf(&page[cnt], "!!! ");
71492 - atomic_inc(&n_rcu_torture_error);
71493 + atomic_inc_unchecked(&n_rcu_torture_error);
71494 WARN_ON_ONCE(1);
71495 }
71496 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71497 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71498 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71499 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71500 cnt += sprintf(&page[cnt], " %d",
71501 - atomic_read(&rcu_torture_wcount[i]));
71502 + atomic_read_unchecked(&rcu_torture_wcount[i]));
71503 }
71504 cnt += sprintf(&page[cnt], "\n");
71505 if (cur_ops->stats)
71506 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71507
71508 if (cur_ops->cleanup)
71509 cur_ops->cleanup();
71510 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71511 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71512 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71513 else if (n_online_successes != n_online_attempts ||
71514 n_offline_successes != n_offline_attempts)
71515 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71516
71517 rcu_torture_current = NULL;
71518 rcu_torture_current_version = 0;
71519 - atomic_set(&n_rcu_torture_alloc, 0);
71520 - atomic_set(&n_rcu_torture_alloc_fail, 0);
71521 - atomic_set(&n_rcu_torture_free, 0);
71522 - atomic_set(&n_rcu_torture_mberror, 0);
71523 - atomic_set(&n_rcu_torture_error, 0);
71524 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71525 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71526 + atomic_set_unchecked(&n_rcu_torture_free, 0);
71527 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71528 + atomic_set_unchecked(&n_rcu_torture_error, 0);
71529 n_rcu_torture_barrier_error = 0;
71530 n_rcu_torture_boost_ktrerror = 0;
71531 n_rcu_torture_boost_rterror = 0;
71532 n_rcu_torture_boost_failure = 0;
71533 n_rcu_torture_boosts = 0;
71534 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71535 - atomic_set(&rcu_torture_wcount[i], 0);
71536 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71537 for_each_possible_cpu(cpu) {
71538 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71539 per_cpu(rcu_torture_count, cpu)[i] = 0;
71540 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71541 index 2682295..0f2297e 100644
71542 --- a/kernel/rcutree.c
71543 +++ b/kernel/rcutree.c
71544 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71545 rcu_prepare_for_idle(smp_processor_id());
71546 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71547 smp_mb__before_atomic_inc(); /* See above. */
71548 - atomic_inc(&rdtp->dynticks);
71549 + atomic_inc_unchecked(&rdtp->dynticks);
71550 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71551 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71552 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71553
71554 /*
71555 * It is illegal to enter an extended quiescent state while
71556 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71557 int user)
71558 {
71559 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71560 - atomic_inc(&rdtp->dynticks);
71561 + atomic_inc_unchecked(&rdtp->dynticks);
71562 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71563 smp_mb__after_atomic_inc(); /* See above. */
71564 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71565 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71566 rcu_cleanup_after_idle(smp_processor_id());
71567 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71568 if (!user && !is_idle_task(current)) {
71569 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71570 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71571
71572 if (rdtp->dynticks_nmi_nesting == 0 &&
71573 - (atomic_read(&rdtp->dynticks) & 0x1))
71574 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71575 return;
71576 rdtp->dynticks_nmi_nesting++;
71577 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71578 - atomic_inc(&rdtp->dynticks);
71579 + atomic_inc_unchecked(&rdtp->dynticks);
71580 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71581 smp_mb__after_atomic_inc(); /* See above. */
71582 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71583 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71584 }
71585
71586 /**
71587 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71588 return;
71589 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71590 smp_mb__before_atomic_inc(); /* See above. */
71591 - atomic_inc(&rdtp->dynticks);
71592 + atomic_inc_unchecked(&rdtp->dynticks);
71593 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71594 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71595 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71596 }
71597
71598 /**
71599 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71600 int ret;
71601
71602 preempt_disable();
71603 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71604 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71605 preempt_enable();
71606 return ret;
71607 }
71608 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71609 */
71610 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71611 {
71612 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71613 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71614 return (rdp->dynticks_snap & 0x1) == 0;
71615 }
71616
71617 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71618 unsigned int curr;
71619 unsigned int snap;
71620
71621 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71622 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71623 snap = (unsigned int)rdp->dynticks_snap;
71624
71625 /*
71626 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71627 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71628 */
71629 if (till_stall_check < 3) {
71630 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71631 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71632 till_stall_check = 3;
71633 } else if (till_stall_check > 300) {
71634 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71635 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71636 till_stall_check = 300;
71637 }
71638 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71639 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71640 rsp->qlen += rdp->qlen;
71641 rdp->n_cbs_orphaned += rdp->qlen;
71642 rdp->qlen_lazy = 0;
71643 - ACCESS_ONCE(rdp->qlen) = 0;
71644 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71645 }
71646
71647 /*
71648 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71649 }
71650 smp_mb(); /* List handling before counting for rcu_barrier(). */
71651 rdp->qlen_lazy -= count_lazy;
71652 - ACCESS_ONCE(rdp->qlen) -= count;
71653 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71654 rdp->n_cbs_invoked += count;
71655
71656 /* Reinstate batch limit if we have worked down the excess. */
71657 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71658 /*
71659 * Do RCU core processing for the current CPU.
71660 */
71661 -static void rcu_process_callbacks(struct softirq_action *unused)
71662 +static void rcu_process_callbacks(void)
71663 {
71664 struct rcu_state *rsp;
71665
71666 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71667 local_irq_restore(flags);
71668 return;
71669 }
71670 - ACCESS_ONCE(rdp->qlen)++;
71671 + ACCESS_ONCE_RW(rdp->qlen)++;
71672 if (lazy)
71673 rdp->qlen_lazy++;
71674 else
71675 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71676 }
71677 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71678
71679 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71680 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71681 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71682 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71683
71684 static int synchronize_sched_expedited_cpu_stop(void *data)
71685 {
71686 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71687 int firstsnap, s, snap, trycount = 0;
71688
71689 /* Note that atomic_inc_return() implies full memory barrier. */
71690 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71691 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71692 get_online_cpus();
71693 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71694
71695 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71696 }
71697
71698 /* Check to see if someone else did our work for us. */
71699 - s = atomic_read(&sync_sched_expedited_done);
71700 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71701 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71702 smp_mb(); /* ensure test happens before caller kfree */
71703 return;
71704 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71705 * grace period works for us.
71706 */
71707 get_online_cpus();
71708 - snap = atomic_read(&sync_sched_expedited_started);
71709 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71710 smp_mb(); /* ensure read is before try_stop_cpus(). */
71711 }
71712
71713 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71714 * than we did beat us to the punch.
71715 */
71716 do {
71717 - s = atomic_read(&sync_sched_expedited_done);
71718 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71719 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71720 smp_mb(); /* ensure test happens before caller kfree */
71721 break;
71722 }
71723 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71724 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71725
71726 put_online_cpus();
71727 }
71728 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71729 * ACCESS_ONCE() to prevent the compiler from speculating
71730 * the increment to precede the early-exit check.
71731 */
71732 - ACCESS_ONCE(rsp->n_barrier_done)++;
71733 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71734 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71735 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71736 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71737 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71738
71739 /* Increment ->n_barrier_done to prevent duplicate work. */
71740 smp_mb(); /* Keep increment after above mechanism. */
71741 - ACCESS_ONCE(rsp->n_barrier_done)++;
71742 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71743 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71744 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71745 smp_mb(); /* Keep increment before caller's subsequent code. */
71746 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71747 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71748 init_callback_list(rdp);
71749 rdp->qlen_lazy = 0;
71750 - ACCESS_ONCE(rdp->qlen) = 0;
71751 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71752 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71753 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71754 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71755 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71756 #ifdef CONFIG_RCU_USER_QS
71757 WARN_ON_ONCE(rdp->dynticks->in_user);
71758 #endif
71759 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71760 rdp->blimit = blimit;
71761 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71762 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71763 - atomic_set(&rdp->dynticks->dynticks,
71764 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71765 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71766 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71767 rcu_prepare_for_idle_init(cpu);
71768 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71769
71770 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71771 index a240f03..d469618 100644
71772 --- a/kernel/rcutree.h
71773 +++ b/kernel/rcutree.h
71774 @@ -86,7 +86,7 @@ struct rcu_dynticks {
71775 long long dynticks_nesting; /* Track irq/process nesting level. */
71776 /* Process level is worth LLONG_MAX/2. */
71777 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71778 - atomic_t dynticks; /* Even value for idle, else odd. */
71779 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71780 #ifdef CONFIG_RCU_FAST_NO_HZ
71781 int dyntick_drain; /* Prepare-for-idle state variable. */
71782 unsigned long dyntick_holdoff;
71783 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71784 index f921154..34c4873 100644
71785 --- a/kernel/rcutree_plugin.h
71786 +++ b/kernel/rcutree_plugin.h
71787 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71788
71789 /* Clean up and exit. */
71790 smp_mb(); /* ensure expedited GP seen before counter increment. */
71791 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71792 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71793 unlock_mb_ret:
71794 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71795 mb_ret:
71796 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71797 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71798 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71799 cpu, ticks_value, ticks_title,
71800 - atomic_read(&rdtp->dynticks) & 0xfff,
71801 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71802 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71803 fast_no_hz);
71804 }
71805 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71806 index 693513b..b9f1d63 100644
71807 --- a/kernel/rcutree_trace.c
71808 +++ b/kernel/rcutree_trace.c
71809 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71810 rdp->completed, rdp->gpnum,
71811 rdp->passed_quiesce, rdp->qs_pending);
71812 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71813 - atomic_read(&rdp->dynticks->dynticks),
71814 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71815 rdp->dynticks->dynticks_nesting,
71816 rdp->dynticks->dynticks_nmi_nesting,
71817 rdp->dynticks_fqs);
71818 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71819 rdp->completed, rdp->gpnum,
71820 rdp->passed_quiesce, rdp->qs_pending);
71821 seq_printf(m, ",%d,%llx,%d,%lu",
71822 - atomic_read(&rdp->dynticks->dynticks),
71823 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71824 rdp->dynticks->dynticks_nesting,
71825 rdp->dynticks->dynticks_nmi_nesting,
71826 rdp->dynticks_fqs);
71827 diff --git a/kernel/resource.c b/kernel/resource.c
71828 index 73f35d4..4684fc4 100644
71829 --- a/kernel/resource.c
71830 +++ b/kernel/resource.c
71831 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71832
71833 static int __init ioresources_init(void)
71834 {
71835 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71836 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71837 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71838 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71839 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71840 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71841 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71842 +#endif
71843 +#else
71844 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71845 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71846 +#endif
71847 return 0;
71848 }
71849 __initcall(ioresources_init);
71850 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71851 index 98ec494..4241d6d 100644
71852 --- a/kernel/rtmutex-tester.c
71853 +++ b/kernel/rtmutex-tester.c
71854 @@ -20,7 +20,7 @@
71855 #define MAX_RT_TEST_MUTEXES 8
71856
71857 static spinlock_t rttest_lock;
71858 -static atomic_t rttest_event;
71859 +static atomic_unchecked_t rttest_event;
71860
71861 struct test_thread_data {
71862 int opcode;
71863 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71864
71865 case RTTEST_LOCKCONT:
71866 td->mutexes[td->opdata] = 1;
71867 - td->event = atomic_add_return(1, &rttest_event);
71868 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71869 return 0;
71870
71871 case RTTEST_RESET:
71872 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71873 return 0;
71874
71875 case RTTEST_RESETEVENT:
71876 - atomic_set(&rttest_event, 0);
71877 + atomic_set_unchecked(&rttest_event, 0);
71878 return 0;
71879
71880 default:
71881 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71882 return ret;
71883
71884 td->mutexes[id] = 1;
71885 - td->event = atomic_add_return(1, &rttest_event);
71886 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71887 rt_mutex_lock(&mutexes[id]);
71888 - td->event = atomic_add_return(1, &rttest_event);
71889 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71890 td->mutexes[id] = 4;
71891 return 0;
71892
71893 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71894 return ret;
71895
71896 td->mutexes[id] = 1;
71897 - td->event = atomic_add_return(1, &rttest_event);
71898 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71899 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
71900 - td->event = atomic_add_return(1, &rttest_event);
71901 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71902 td->mutexes[id] = ret ? 0 : 4;
71903 return ret ? -EINTR : 0;
71904
71905 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71906 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
71907 return ret;
71908
71909 - td->event = atomic_add_return(1, &rttest_event);
71910 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71911 rt_mutex_unlock(&mutexes[id]);
71912 - td->event = atomic_add_return(1, &rttest_event);
71913 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71914 td->mutexes[id] = 0;
71915 return 0;
71916
71917 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71918 break;
71919
71920 td->mutexes[dat] = 2;
71921 - td->event = atomic_add_return(1, &rttest_event);
71922 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71923 break;
71924
71925 default:
71926 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71927 return;
71928
71929 td->mutexes[dat] = 3;
71930 - td->event = atomic_add_return(1, &rttest_event);
71931 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71932 break;
71933
71934 case RTTEST_LOCKNOWAIT:
71935 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71936 return;
71937
71938 td->mutexes[dat] = 1;
71939 - td->event = atomic_add_return(1, &rttest_event);
71940 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71941 return;
71942
71943 default:
71944 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
71945 index 15f60d0..7e50319 100644
71946 --- a/kernel/sched/auto_group.c
71947 +++ b/kernel/sched/auto_group.c
71948 @@ -11,7 +11,7 @@
71949
71950 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
71951 static struct autogroup autogroup_default;
71952 -static atomic_t autogroup_seq_nr;
71953 +static atomic_unchecked_t autogroup_seq_nr;
71954
71955 void __init autogroup_init(struct task_struct *init_task)
71956 {
71957 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
71958
71959 kref_init(&ag->kref);
71960 init_rwsem(&ag->lock);
71961 - ag->id = atomic_inc_return(&autogroup_seq_nr);
71962 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
71963 ag->tg = tg;
71964 #ifdef CONFIG_RT_GROUP_SCHED
71965 /*
71966 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
71967 index c529d00..d00b4f3 100644
71968 --- a/kernel/sched/core.c
71969 +++ b/kernel/sched/core.c
71970 @@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
71971 /* convert nice value [19,-20] to rlimit style value [1,40] */
71972 int nice_rlim = 20 - nice;
71973
71974 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
71975 +
71976 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
71977 capable(CAP_SYS_NICE));
71978 }
71979 @@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
71980 if (nice > 19)
71981 nice = 19;
71982
71983 - if (increment < 0 && !can_nice(current, nice))
71984 + if (increment < 0 && (!can_nice(current, nice) ||
71985 + gr_handle_chroot_nice()))
71986 return -EPERM;
71987
71988 retval = security_task_setnice(current, nice);
71989 @@ -3750,6 +3753,7 @@ recheck:
71990 unsigned long rlim_rtprio =
71991 task_rlimit(p, RLIMIT_RTPRIO);
71992
71993 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
71994 /* can't set/change the rt policy */
71995 if (policy != p->policy && !rlim_rtprio)
71996 return -EPERM;
71997 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
71998 index 6b800a1..0c36227 100644
71999 --- a/kernel/sched/fair.c
72000 +++ b/kernel/sched/fair.c
72001 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72002 * run_rebalance_domains is triggered when needed from the scheduler tick.
72003 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72004 */
72005 -static void run_rebalance_domains(struct softirq_action *h)
72006 +static void run_rebalance_domains(void)
72007 {
72008 int this_cpu = smp_processor_id();
72009 struct rq *this_rq = cpu_rq(this_cpu);
72010 diff --git a/kernel/signal.c b/kernel/signal.c
72011 index 57dde52..2c561f0 100644
72012 --- a/kernel/signal.c
72013 +++ b/kernel/signal.c
72014 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72015
72016 int print_fatal_signals __read_mostly;
72017
72018 -static void __user *sig_handler(struct task_struct *t, int sig)
72019 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
72020 {
72021 return t->sighand->action[sig - 1].sa.sa_handler;
72022 }
72023
72024 -static int sig_handler_ignored(void __user *handler, int sig)
72025 +static int sig_handler_ignored(__sighandler_t handler, int sig)
72026 {
72027 /* Is it explicitly or implicitly ignored? */
72028 return handler == SIG_IGN ||
72029 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72030
72031 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72032 {
72033 - void __user *handler;
72034 + __sighandler_t handler;
72035
72036 handler = sig_handler(t, sig);
72037
72038 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72039 atomic_inc(&user->sigpending);
72040 rcu_read_unlock();
72041
72042 + if (!override_rlimit)
72043 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72044 +
72045 if (override_rlimit ||
72046 atomic_read(&user->sigpending) <=
72047 task_rlimit(t, RLIMIT_SIGPENDING)) {
72048 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72049
72050 int unhandled_signal(struct task_struct *tsk, int sig)
72051 {
72052 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72053 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72054 if (is_global_init(tsk))
72055 return 1;
72056 if (handler != SIG_IGN && handler != SIG_DFL)
72057 @@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72058 }
72059 }
72060
72061 + /* allow glibc communication via tgkill to other threads in our
72062 + thread group */
72063 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72064 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72065 + && gr_handle_signal(t, sig))
72066 + return -EPERM;
72067 +
72068 return security_task_kill(t, info, sig, 0);
72069 }
72070
72071 @@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72072 return send_signal(sig, info, p, 1);
72073 }
72074
72075 -static int
72076 +int
72077 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72078 {
72079 return send_signal(sig, info, t, 0);
72080 @@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72081 unsigned long int flags;
72082 int ret, blocked, ignored;
72083 struct k_sigaction *action;
72084 + int is_unhandled = 0;
72085
72086 spin_lock_irqsave(&t->sighand->siglock, flags);
72087 action = &t->sighand->action[sig-1];
72088 @@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72089 }
72090 if (action->sa.sa_handler == SIG_DFL)
72091 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72092 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72093 + is_unhandled = 1;
72094 ret = specific_send_sig_info(sig, info, t);
72095 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72096
72097 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
72098 + normal operation */
72099 + if (is_unhandled) {
72100 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72101 + gr_handle_crash(t, sig);
72102 + }
72103 +
72104 return ret;
72105 }
72106
72107 @@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72108 ret = check_kill_permission(sig, info, p);
72109 rcu_read_unlock();
72110
72111 - if (!ret && sig)
72112 + if (!ret && sig) {
72113 ret = do_send_sig_info(sig, info, p, true);
72114 + if (!ret)
72115 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72116 + }
72117
72118 return ret;
72119 }
72120 @@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72121 int error = -ESRCH;
72122
72123 rcu_read_lock();
72124 - p = find_task_by_vpid(pid);
72125 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72126 + /* allow glibc communication via tgkill to other threads in our
72127 + thread group */
72128 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72129 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
72130 + p = find_task_by_vpid_unrestricted(pid);
72131 + else
72132 +#endif
72133 + p = find_task_by_vpid(pid);
72134 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72135 error = check_kill_permission(sig, info, p);
72136 /*
72137 diff --git a/kernel/softirq.c b/kernel/softirq.c
72138 index cc96bdc..6a96894 100644
72139 --- a/kernel/softirq.c
72140 +++ b/kernel/softirq.c
72141 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
72142 EXPORT_SYMBOL(irq_stat);
72143 #endif
72144
72145 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
72146 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
72147
72148 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72149
72150 -char *softirq_to_name[NR_SOFTIRQS] = {
72151 +const char * const softirq_to_name[NR_SOFTIRQS] = {
72152 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72153 "TASKLET", "SCHED", "HRTIMER", "RCU"
72154 };
72155 @@ -244,7 +244,7 @@ restart:
72156 kstat_incr_softirqs_this_cpu(vec_nr);
72157
72158 trace_softirq_entry(vec_nr);
72159 - h->action(h);
72160 + h->action();
72161 trace_softirq_exit(vec_nr);
72162 if (unlikely(prev_count != preempt_count())) {
72163 printk(KERN_ERR "huh, entered softirq %u %s %p"
72164 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
72165 or_softirq_pending(1UL << nr);
72166 }
72167
72168 -void open_softirq(int nr, void (*action)(struct softirq_action *))
72169 +void __init open_softirq(int nr, void (*action)(void))
72170 {
72171 softirq_vec[nr].action = action;
72172 }
72173 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72174
72175 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72176
72177 -static void tasklet_action(struct softirq_action *a)
72178 +static void tasklet_action(void)
72179 {
72180 struct tasklet_struct *list;
72181
72182 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
72183 }
72184 }
72185
72186 -static void tasklet_hi_action(struct softirq_action *a)
72187 +static void tasklet_hi_action(void)
72188 {
72189 struct tasklet_struct *list;
72190
72191 diff --git a/kernel/srcu.c b/kernel/srcu.c
72192 index 97c465e..d83f3bb 100644
72193 --- a/kernel/srcu.c
72194 +++ b/kernel/srcu.c
72195 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72196 preempt_disable();
72197 idx = rcu_dereference_index_check(sp->completed,
72198 rcu_read_lock_sched_held()) & 0x1;
72199 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72200 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72201 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72202 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72203 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72204 preempt_enable();
72205 return idx;
72206 }
72207 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72208 {
72209 preempt_disable();
72210 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72211 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72212 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72213 preempt_enable();
72214 }
72215 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72216 diff --git a/kernel/sys.c b/kernel/sys.c
72217 index e6e0ece..1f2e413 100644
72218 --- a/kernel/sys.c
72219 +++ b/kernel/sys.c
72220 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72221 error = -EACCES;
72222 goto out;
72223 }
72224 +
72225 + if (gr_handle_chroot_setpriority(p, niceval)) {
72226 + error = -EACCES;
72227 + goto out;
72228 + }
72229 +
72230 no_nice = security_task_setnice(p, niceval);
72231 if (no_nice) {
72232 error = no_nice;
72233 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72234 goto error;
72235 }
72236
72237 + if (gr_check_group_change(new->gid, new->egid, -1))
72238 + goto error;
72239 +
72240 if (rgid != (gid_t) -1 ||
72241 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72242 new->sgid = new->egid;
72243 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72244 old = current_cred();
72245
72246 retval = -EPERM;
72247 +
72248 + if (gr_check_group_change(kgid, kgid, kgid))
72249 + goto error;
72250 +
72251 if (nsown_capable(CAP_SETGID))
72252 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72253 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72254 @@ -647,7 +660,7 @@ error:
72255 /*
72256 * change the user struct in a credentials set to match the new UID
72257 */
72258 -static int set_user(struct cred *new)
72259 +int set_user(struct cred *new)
72260 {
72261 struct user_struct *new_user;
72262
72263 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72264 goto error;
72265 }
72266
72267 + if (gr_check_user_change(new->uid, new->euid, -1))
72268 + goto error;
72269 +
72270 if (!uid_eq(new->uid, old->uid)) {
72271 retval = set_user(new);
72272 if (retval < 0)
72273 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72274 old = current_cred();
72275
72276 retval = -EPERM;
72277 +
72278 + if (gr_check_crash_uid(kuid))
72279 + goto error;
72280 + if (gr_check_user_change(kuid, kuid, kuid))
72281 + goto error;
72282 +
72283 if (nsown_capable(CAP_SETUID)) {
72284 new->suid = new->uid = kuid;
72285 if (!uid_eq(kuid, old->uid)) {
72286 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72287 goto error;
72288 }
72289
72290 + if (gr_check_user_change(kruid, keuid, -1))
72291 + goto error;
72292 +
72293 if (ruid != (uid_t) -1) {
72294 new->uid = kruid;
72295 if (!uid_eq(kruid, old->uid)) {
72296 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72297 goto error;
72298 }
72299
72300 + if (gr_check_group_change(krgid, kegid, -1))
72301 + goto error;
72302 +
72303 if (rgid != (gid_t) -1)
72304 new->gid = krgid;
72305 if (egid != (gid_t) -1)
72306 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72307 if (!uid_valid(kuid))
72308 return old_fsuid;
72309
72310 + if (gr_check_user_change(-1, -1, kuid))
72311 + goto error;
72312 +
72313 new = prepare_creds();
72314 if (!new)
72315 return old_fsuid;
72316 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72317 }
72318 }
72319
72320 +error:
72321 abort_creds(new);
72322 return old_fsuid;
72323
72324 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72325 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72326 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72327 nsown_capable(CAP_SETGID)) {
72328 + if (gr_check_group_change(-1, -1, kgid))
72329 + goto error;
72330 +
72331 if (!gid_eq(kgid, old->fsgid)) {
72332 new->fsgid = kgid;
72333 goto change_okay;
72334 }
72335 }
72336
72337 +error:
72338 abort_creds(new);
72339 return old_fsgid;
72340
72341 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72342 return -EFAULT;
72343
72344 down_read(&uts_sem);
72345 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
72346 + error = __copy_to_user(name->sysname, &utsname()->sysname,
72347 __OLD_UTS_LEN);
72348 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72349 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72350 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
72351 __OLD_UTS_LEN);
72352 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72353 - error |= __copy_to_user(&name->release, &utsname()->release,
72354 + error |= __copy_to_user(name->release, &utsname()->release,
72355 __OLD_UTS_LEN);
72356 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72357 - error |= __copy_to_user(&name->version, &utsname()->version,
72358 + error |= __copy_to_user(name->version, &utsname()->version,
72359 __OLD_UTS_LEN);
72360 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72361 - error |= __copy_to_user(&name->machine, &utsname()->machine,
72362 + error |= __copy_to_user(name->machine, &utsname()->machine,
72363 __OLD_UTS_LEN);
72364 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72365 up_read(&uts_sem);
72366 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72367 error = get_dumpable(me->mm);
72368 break;
72369 case PR_SET_DUMPABLE:
72370 - if (arg2 < 0 || arg2 > 1) {
72371 + if (arg2 > 1) {
72372 error = -EINVAL;
72373 break;
72374 }
72375 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72376 index 26f65ea..df8e5ad 100644
72377 --- a/kernel/sysctl.c
72378 +++ b/kernel/sysctl.c
72379 @@ -92,7 +92,6 @@
72380
72381
72382 #if defined(CONFIG_SYSCTL)
72383 -
72384 /* External variables not in a header file. */
72385 extern int sysctl_overcommit_memory;
72386 extern int sysctl_overcommit_ratio;
72387 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72388 void __user *buffer, size_t *lenp, loff_t *ppos);
72389 #endif
72390
72391 -#ifdef CONFIG_PRINTK
72392 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72393 void __user *buffer, size_t *lenp, loff_t *ppos);
72394 -#endif
72395
72396 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72397 void __user *buffer, size_t *lenp, loff_t *ppos);
72398 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72399
72400 #endif
72401
72402 +extern struct ctl_table grsecurity_table[];
72403 +
72404 static struct ctl_table kern_table[];
72405 static struct ctl_table vm_table[];
72406 static struct ctl_table fs_table[];
72407 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72408 int sysctl_legacy_va_layout;
72409 #endif
72410
72411 +#ifdef CONFIG_PAX_SOFTMODE
72412 +static ctl_table pax_table[] = {
72413 + {
72414 + .procname = "softmode",
72415 + .data = &pax_softmode,
72416 + .maxlen = sizeof(unsigned int),
72417 + .mode = 0600,
72418 + .proc_handler = &proc_dointvec,
72419 + },
72420 +
72421 + { }
72422 +};
72423 +#endif
72424 +
72425 /* The default sysctl tables: */
72426
72427 static struct ctl_table sysctl_base_table[] = {
72428 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72429 #endif
72430
72431 static struct ctl_table kern_table[] = {
72432 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72433 + {
72434 + .procname = "grsecurity",
72435 + .mode = 0500,
72436 + .child = grsecurity_table,
72437 + },
72438 +#endif
72439 +
72440 +#ifdef CONFIG_PAX_SOFTMODE
72441 + {
72442 + .procname = "pax",
72443 + .mode = 0500,
72444 + .child = pax_table,
72445 + },
72446 +#endif
72447 +
72448 {
72449 .procname = "sched_child_runs_first",
72450 .data = &sysctl_sched_child_runs_first,
72451 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72452 .data = &modprobe_path,
72453 .maxlen = KMOD_PATH_LEN,
72454 .mode = 0644,
72455 - .proc_handler = proc_dostring,
72456 + .proc_handler = proc_dostring_modpriv,
72457 },
72458 {
72459 .procname = "modules_disabled",
72460 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72461 .extra1 = &zero,
72462 .extra2 = &one,
72463 },
72464 +#endif
72465 {
72466 .procname = "kptr_restrict",
72467 .data = &kptr_restrict,
72468 .maxlen = sizeof(int),
72469 .mode = 0644,
72470 .proc_handler = proc_dointvec_minmax_sysadmin,
72471 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72472 + .extra1 = &two,
72473 +#else
72474 .extra1 = &zero,
72475 +#endif
72476 .extra2 = &two,
72477 },
72478 -#endif
72479 {
72480 .procname = "ngroups_max",
72481 .data = &ngroups_max,
72482 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72483 .proc_handler = proc_dointvec_minmax,
72484 .extra1 = &zero,
72485 },
72486 + {
72487 + .procname = "heap_stack_gap",
72488 + .data = &sysctl_heap_stack_gap,
72489 + .maxlen = sizeof(sysctl_heap_stack_gap),
72490 + .mode = 0644,
72491 + .proc_handler = proc_doulongvec_minmax,
72492 + },
72493 #else
72494 {
72495 .procname = "nr_trim_pages",
72496 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72497 buffer, lenp, ppos);
72498 }
72499
72500 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72501 + void __user *buffer, size_t *lenp, loff_t *ppos)
72502 +{
72503 + if (write && !capable(CAP_SYS_MODULE))
72504 + return -EPERM;
72505 +
72506 + return _proc_do_string(table->data, table->maxlen, write,
72507 + buffer, lenp, ppos);
72508 +}
72509 +
72510 static size_t proc_skip_spaces(char **buf)
72511 {
72512 size_t ret;
72513 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72514 len = strlen(tmp);
72515 if (len > *size)
72516 len = *size;
72517 + if (len > sizeof(tmp))
72518 + len = sizeof(tmp);
72519 if (copy_to_user(*buf, tmp, len))
72520 return -EFAULT;
72521 *size -= len;
72522 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72523 return err;
72524 }
72525
72526 -#ifdef CONFIG_PRINTK
72527 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72528 void __user *buffer, size_t *lenp, loff_t *ppos)
72529 {
72530 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72531
72532 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72533 }
72534 -#endif
72535
72536 struct do_proc_dointvec_minmax_conv_param {
72537 int *min;
72538 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72539 *i = val;
72540 } else {
72541 val = convdiv * (*i) / convmul;
72542 - if (!first)
72543 + if (!first) {
72544 err = proc_put_char(&buffer, &left, '\t');
72545 + if (err)
72546 + break;
72547 + }
72548 err = proc_put_long(&buffer, &left, val, false);
72549 if (err)
72550 break;
72551 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72552 return -ENOSYS;
72553 }
72554
72555 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72556 + void __user *buffer, size_t *lenp, loff_t *ppos)
72557 +{
72558 + return -ENOSYS;
72559 +}
72560 +
72561 int proc_dointvec(struct ctl_table *table, int write,
72562 void __user *buffer, size_t *lenp, loff_t *ppos)
72563 {
72564 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72565 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72566 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72567 EXPORT_SYMBOL(proc_dostring);
72568 +EXPORT_SYMBOL(proc_dostring_modpriv);
72569 EXPORT_SYMBOL(proc_doulongvec_minmax);
72570 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72571 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72572 index 65bdcf1..21eb831 100644
72573 --- a/kernel/sysctl_binary.c
72574 +++ b/kernel/sysctl_binary.c
72575 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72576 int i;
72577
72578 set_fs(KERNEL_DS);
72579 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72580 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72581 set_fs(old_fs);
72582 if (result < 0)
72583 goto out_kfree;
72584 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72585 }
72586
72587 set_fs(KERNEL_DS);
72588 - result = vfs_write(file, buffer, str - buffer, &pos);
72589 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72590 set_fs(old_fs);
72591 if (result < 0)
72592 goto out_kfree;
72593 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72594 int i;
72595
72596 set_fs(KERNEL_DS);
72597 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72598 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72599 set_fs(old_fs);
72600 if (result < 0)
72601 goto out_kfree;
72602 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72603 }
72604
72605 set_fs(KERNEL_DS);
72606 - result = vfs_write(file, buffer, str - buffer, &pos);
72607 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72608 set_fs(old_fs);
72609 if (result < 0)
72610 goto out_kfree;
72611 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72612 int i;
72613
72614 set_fs(KERNEL_DS);
72615 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72616 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72617 set_fs(old_fs);
72618 if (result < 0)
72619 goto out;
72620 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72621 __le16 dnaddr;
72622
72623 set_fs(KERNEL_DS);
72624 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72625 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72626 set_fs(old_fs);
72627 if (result < 0)
72628 goto out;
72629 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72630 le16_to_cpu(dnaddr) & 0x3ff);
72631
72632 set_fs(KERNEL_DS);
72633 - result = vfs_write(file, buf, len, &pos);
72634 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72635 set_fs(old_fs);
72636 if (result < 0)
72637 goto out;
72638 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72639 index 145bb4d..b2aa969 100644
72640 --- a/kernel/taskstats.c
72641 +++ b/kernel/taskstats.c
72642 @@ -28,9 +28,12 @@
72643 #include <linux/fs.h>
72644 #include <linux/file.h>
72645 #include <linux/pid_namespace.h>
72646 +#include <linux/grsecurity.h>
72647 #include <net/genetlink.h>
72648 #include <linux/atomic.h>
72649
72650 +extern int gr_is_taskstats_denied(int pid);
72651 +
72652 /*
72653 * Maximum length of a cpumask that can be specified in
72654 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72655 @@ -570,6 +573,9 @@ err:
72656
72657 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72658 {
72659 + if (gr_is_taskstats_denied(current->pid))
72660 + return -EACCES;
72661 +
72662 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72663 return cmd_attr_register_cpumask(info);
72664 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72665 diff --git a/kernel/time.c b/kernel/time.c
72666 index d226c6a..c7c0960 100644
72667 --- a/kernel/time.c
72668 +++ b/kernel/time.c
72669 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72670 return error;
72671
72672 if (tz) {
72673 + /* we log in do_settimeofday called below, so don't log twice
72674 + */
72675 + if (!tv)
72676 + gr_log_timechange();
72677 +
72678 sys_tz = *tz;
72679 update_vsyscall_tz();
72680 if (firsttime) {
72681 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72682 index f11d83b..d016d91 100644
72683 --- a/kernel/time/alarmtimer.c
72684 +++ b/kernel/time/alarmtimer.c
72685 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72686 struct platform_device *pdev;
72687 int error = 0;
72688 int i;
72689 - struct k_clock alarm_clock = {
72690 + static struct k_clock alarm_clock = {
72691 .clock_getres = alarm_clock_getres,
72692 .clock_get = alarm_clock_get,
72693 .timer_create = alarm_timer_create,
72694 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72695 index f113755..ec24223 100644
72696 --- a/kernel/time/tick-broadcast.c
72697 +++ b/kernel/time/tick-broadcast.c
72698 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72699 * then clear the broadcast bit.
72700 */
72701 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72702 - int cpu = smp_processor_id();
72703 + cpu = smp_processor_id();
72704
72705 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72706 tick_broadcast_clear_oneshot(cpu);
72707 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72708 index e424970..4c7962b 100644
72709 --- a/kernel/time/timekeeping.c
72710 +++ b/kernel/time/timekeeping.c
72711 @@ -15,6 +15,7 @@
72712 #include <linux/init.h>
72713 #include <linux/mm.h>
72714 #include <linux/sched.h>
72715 +#include <linux/grsecurity.h>
72716 #include <linux/syscore_ops.h>
72717 #include <linux/clocksource.h>
72718 #include <linux/jiffies.h>
72719 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72720 if (!timespec_valid_strict(tv))
72721 return -EINVAL;
72722
72723 + gr_log_timechange();
72724 +
72725 write_seqlock_irqsave(&tk->lock, flags);
72726
72727 timekeeping_forward_now(tk);
72728 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72729 index af5a7e9..715611a 100644
72730 --- a/kernel/time/timer_list.c
72731 +++ b/kernel/time/timer_list.c
72732 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72733
72734 static void print_name_offset(struct seq_file *m, void *sym)
72735 {
72736 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72737 + SEQ_printf(m, "<%p>", NULL);
72738 +#else
72739 char symname[KSYM_NAME_LEN];
72740
72741 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72742 SEQ_printf(m, "<%pK>", sym);
72743 else
72744 SEQ_printf(m, "%s", symname);
72745 +#endif
72746 }
72747
72748 static void
72749 @@ -112,7 +116,11 @@ next_one:
72750 static void
72751 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72752 {
72753 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72754 + SEQ_printf(m, " .base: %p\n", NULL);
72755 +#else
72756 SEQ_printf(m, " .base: %pK\n", base);
72757 +#endif
72758 SEQ_printf(m, " .index: %d\n",
72759 base->index);
72760 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72761 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72762 {
72763 struct proc_dir_entry *pe;
72764
72765 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72766 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72767 +#else
72768 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72769 +#endif
72770 if (!pe)
72771 return -ENOMEM;
72772 return 0;
72773 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72774 index 0b537f2..40d6c20 100644
72775 --- a/kernel/time/timer_stats.c
72776 +++ b/kernel/time/timer_stats.c
72777 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72778 static unsigned long nr_entries;
72779 static struct entry entries[MAX_ENTRIES];
72780
72781 -static atomic_t overflow_count;
72782 +static atomic_unchecked_t overflow_count;
72783
72784 /*
72785 * The entries are in a hash-table, for fast lookup:
72786 @@ -140,7 +140,7 @@ static void reset_entries(void)
72787 nr_entries = 0;
72788 memset(entries, 0, sizeof(entries));
72789 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72790 - atomic_set(&overflow_count, 0);
72791 + atomic_set_unchecked(&overflow_count, 0);
72792 }
72793
72794 static struct entry *alloc_entry(void)
72795 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72796 if (likely(entry))
72797 entry->count++;
72798 else
72799 - atomic_inc(&overflow_count);
72800 + atomic_inc_unchecked(&overflow_count);
72801
72802 out_unlock:
72803 raw_spin_unlock_irqrestore(lock, flags);
72804 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72805
72806 static void print_name_offset(struct seq_file *m, unsigned long addr)
72807 {
72808 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72809 + seq_printf(m, "<%p>", NULL);
72810 +#else
72811 char symname[KSYM_NAME_LEN];
72812
72813 if (lookup_symbol_name(addr, symname) < 0)
72814 - seq_printf(m, "<%p>", (void *)addr);
72815 + seq_printf(m, "<%pK>", (void *)addr);
72816 else
72817 seq_printf(m, "%s", symname);
72818 +#endif
72819 }
72820
72821 static int tstats_show(struct seq_file *m, void *v)
72822 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72823
72824 seq_puts(m, "Timer Stats Version: v0.2\n");
72825 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72826 - if (atomic_read(&overflow_count))
72827 + if (atomic_read_unchecked(&overflow_count))
72828 seq_printf(m, "Overflow: %d entries\n",
72829 - atomic_read(&overflow_count));
72830 + atomic_read_unchecked(&overflow_count));
72831
72832 for (i = 0; i < nr_entries; i++) {
72833 entry = entries + i;
72834 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72835 {
72836 struct proc_dir_entry *pe;
72837
72838 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72839 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72840 +#else
72841 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72842 +#endif
72843 if (!pe)
72844 return -ENOMEM;
72845 return 0;
72846 diff --git a/kernel/timer.c b/kernel/timer.c
72847 index 367d008..46857a0 100644
72848 --- a/kernel/timer.c
72849 +++ b/kernel/timer.c
72850 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72851 /*
72852 * This function runs timers and the timer-tq in bottom half context.
72853 */
72854 -static void run_timer_softirq(struct softirq_action *h)
72855 +static void run_timer_softirq(void)
72856 {
72857 struct tvec_base *base = __this_cpu_read(tvec_bases);
72858
72859 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72860 return NOTIFY_OK;
72861 }
72862
72863 -static struct notifier_block __cpuinitdata timers_nb = {
72864 +static struct notifier_block __cpuinitconst timers_nb = {
72865 .notifier_call = timer_cpu_notify,
72866 };
72867
72868 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72869 index c0bd030..62a1927 100644
72870 --- a/kernel/trace/blktrace.c
72871 +++ b/kernel/trace/blktrace.c
72872 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72873 struct blk_trace *bt = filp->private_data;
72874 char buf[16];
72875
72876 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
72877 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
72878
72879 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
72880 }
72881 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
72882 return 1;
72883
72884 bt = buf->chan->private_data;
72885 - atomic_inc(&bt->dropped);
72886 + atomic_inc_unchecked(&bt->dropped);
72887 return 0;
72888 }
72889
72890 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
72891
72892 bt->dir = dir;
72893 bt->dev = dev;
72894 - atomic_set(&bt->dropped, 0);
72895 + atomic_set_unchecked(&bt->dropped, 0);
72896
72897 ret = -EIO;
72898 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
72899 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
72900 index 356bc2f..7c94fc0 100644
72901 --- a/kernel/trace/ftrace.c
72902 +++ b/kernel/trace/ftrace.c
72903 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
72904 if (unlikely(ftrace_disabled))
72905 return 0;
72906
72907 + ret = ftrace_arch_code_modify_prepare();
72908 + FTRACE_WARN_ON(ret);
72909 + if (ret)
72910 + return 0;
72911 +
72912 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
72913 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
72914 if (ret) {
72915 ftrace_bug(ret, ip);
72916 - return 0;
72917 }
72918 - return 1;
72919 + return ret ? 0 : 1;
72920 }
72921
72922 /*
72923 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
72924
72925 int
72926 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
72927 - void *data)
72928 + void *data)
72929 {
72930 struct ftrace_func_probe *entry;
72931 struct ftrace_page *pg;
72932 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
72933 if (!count)
72934 return 0;
72935
72936 + pax_open_kernel();
72937 sort(start, count, sizeof(*start),
72938 ftrace_cmp_ips, ftrace_swap_ips);
72939 + pax_close_kernel();
72940
72941 start_pg = ftrace_allocate_pages(count);
72942 if (!start_pg)
72943 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
72944 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
72945
72946 static int ftrace_graph_active;
72947 -static struct notifier_block ftrace_suspend_notifier;
72948 -
72949 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
72950 {
72951 return 0;
72952 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
72953 return NOTIFY_DONE;
72954 }
72955
72956 +static struct notifier_block ftrace_suspend_notifier = {
72957 + .notifier_call = ftrace_suspend_notifier_call
72958 +};
72959 +
72960 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72961 trace_func_graph_ent_t entryfunc)
72962 {
72963 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72964 goto out;
72965 }
72966
72967 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
72968 register_pm_notifier(&ftrace_suspend_notifier);
72969
72970 ftrace_graph_active++;
72971 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
72972 index 4cb5e51..e7e05d9 100644
72973 --- a/kernel/trace/ring_buffer.c
72974 +++ b/kernel/trace/ring_buffer.c
72975 @@ -346,9 +346,9 @@ struct buffer_data_page {
72976 */
72977 struct buffer_page {
72978 struct list_head list; /* list of buffer pages */
72979 - local_t write; /* index for next write */
72980 + local_unchecked_t write; /* index for next write */
72981 unsigned read; /* index for next read */
72982 - local_t entries; /* entries on this page */
72983 + local_unchecked_t entries; /* entries on this page */
72984 unsigned long real_end; /* real end of data */
72985 struct buffer_data_page *page; /* Actual data page */
72986 };
72987 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
72988 unsigned long lost_events;
72989 unsigned long last_overrun;
72990 local_t entries_bytes;
72991 - local_t commit_overrun;
72992 - local_t overrun;
72993 + local_unchecked_t commit_overrun;
72994 + local_unchecked_t overrun;
72995 local_t entries;
72996 local_t committing;
72997 local_t commits;
72998 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72999 *
73000 * We add a counter to the write field to denote this.
73001 */
73002 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73003 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73004 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73005 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73006
73007 /*
73008 * Just make sure we have seen our old_write and synchronize
73009 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73010 * cmpxchg to only update if an interrupt did not already
73011 * do it for us. If the cmpxchg fails, we don't care.
73012 */
73013 - (void)local_cmpxchg(&next_page->write, old_write, val);
73014 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73015 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73016 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73017
73018 /*
73019 * No need to worry about races with clearing out the commit.
73020 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73021
73022 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73023 {
73024 - return local_read(&bpage->entries) & RB_WRITE_MASK;
73025 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73026 }
73027
73028 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73029 {
73030 - return local_read(&bpage->write) & RB_WRITE_MASK;
73031 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73032 }
73033
73034 static int
73035 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73036 * bytes consumed in ring buffer from here.
73037 * Increment overrun to account for the lost events.
73038 */
73039 - local_add(page_entries, &cpu_buffer->overrun);
73040 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
73041 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73042 }
73043
73044 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73045 * it is our responsibility to update
73046 * the counters.
73047 */
73048 - local_add(entries, &cpu_buffer->overrun);
73049 + local_add_unchecked(entries, &cpu_buffer->overrun);
73050 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73051
73052 /*
73053 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73054 if (tail == BUF_PAGE_SIZE)
73055 tail_page->real_end = 0;
73056
73057 - local_sub(length, &tail_page->write);
73058 + local_sub_unchecked(length, &tail_page->write);
73059 return;
73060 }
73061
73062 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73063 rb_event_set_padding(event);
73064
73065 /* Set the write back to the previous setting */
73066 - local_sub(length, &tail_page->write);
73067 + local_sub_unchecked(length, &tail_page->write);
73068 return;
73069 }
73070
73071 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73072
73073 /* Set write to end of buffer */
73074 length = (tail + length) - BUF_PAGE_SIZE;
73075 - local_sub(length, &tail_page->write);
73076 + local_sub_unchecked(length, &tail_page->write);
73077 }
73078
73079 /*
73080 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73081 * about it.
73082 */
73083 if (unlikely(next_page == commit_page)) {
73084 - local_inc(&cpu_buffer->commit_overrun);
73085 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73086 goto out_reset;
73087 }
73088
73089 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73090 cpu_buffer->tail_page) &&
73091 (cpu_buffer->commit_page ==
73092 cpu_buffer->reader_page))) {
73093 - local_inc(&cpu_buffer->commit_overrun);
73094 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73095 goto out_reset;
73096 }
73097 }
73098 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73099 length += RB_LEN_TIME_EXTEND;
73100
73101 tail_page = cpu_buffer->tail_page;
73102 - write = local_add_return(length, &tail_page->write);
73103 + write = local_add_return_unchecked(length, &tail_page->write);
73104
73105 /* set write to only the index of the write */
73106 write &= RB_WRITE_MASK;
73107 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73108 kmemcheck_annotate_bitfield(event, bitfield);
73109 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73110
73111 - local_inc(&tail_page->entries);
73112 + local_inc_unchecked(&tail_page->entries);
73113
73114 /*
73115 * If this is the first commit on the page, then update
73116 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73117
73118 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73119 unsigned long write_mask =
73120 - local_read(&bpage->write) & ~RB_WRITE_MASK;
73121 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73122 unsigned long event_length = rb_event_length(event);
73123 /*
73124 * This is on the tail page. It is possible that
73125 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73126 */
73127 old_index += write_mask;
73128 new_index += write_mask;
73129 - index = local_cmpxchg(&bpage->write, old_index, new_index);
73130 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73131 if (index == old_index) {
73132 /* update counters */
73133 local_sub(event_length, &cpu_buffer->entries_bytes);
73134 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73135
73136 /* Do the likely case first */
73137 if (likely(bpage->page == (void *)addr)) {
73138 - local_dec(&bpage->entries);
73139 + local_dec_unchecked(&bpage->entries);
73140 return;
73141 }
73142
73143 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73144 start = bpage;
73145 do {
73146 if (bpage->page == (void *)addr) {
73147 - local_dec(&bpage->entries);
73148 + local_dec_unchecked(&bpage->entries);
73149 return;
73150 }
73151 rb_inc_page(cpu_buffer, &bpage);
73152 @@ -2923,7 +2923,7 @@ static inline unsigned long
73153 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73154 {
73155 return local_read(&cpu_buffer->entries) -
73156 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73157 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73158 }
73159
73160 /**
73161 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73162 return 0;
73163
73164 cpu_buffer = buffer->buffers[cpu];
73165 - ret = local_read(&cpu_buffer->overrun);
73166 + ret = local_read_unchecked(&cpu_buffer->overrun);
73167
73168 return ret;
73169 }
73170 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73171 return 0;
73172
73173 cpu_buffer = buffer->buffers[cpu];
73174 - ret = local_read(&cpu_buffer->commit_overrun);
73175 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73176
73177 return ret;
73178 }
73179 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73180 /* if you care about this being correct, lock the buffer */
73181 for_each_buffer_cpu(buffer, cpu) {
73182 cpu_buffer = buffer->buffers[cpu];
73183 - overruns += local_read(&cpu_buffer->overrun);
73184 + overruns += local_read_unchecked(&cpu_buffer->overrun);
73185 }
73186
73187 return overruns;
73188 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73189 /*
73190 * Reset the reader page to size zero.
73191 */
73192 - local_set(&cpu_buffer->reader_page->write, 0);
73193 - local_set(&cpu_buffer->reader_page->entries, 0);
73194 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73195 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73196 local_set(&cpu_buffer->reader_page->page->commit, 0);
73197 cpu_buffer->reader_page->real_end = 0;
73198
73199 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73200 * want to compare with the last_overrun.
73201 */
73202 smp_mb();
73203 - overwrite = local_read(&(cpu_buffer->overrun));
73204 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73205
73206 /*
73207 * Here's the tricky part.
73208 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73209
73210 cpu_buffer->head_page
73211 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73212 - local_set(&cpu_buffer->head_page->write, 0);
73213 - local_set(&cpu_buffer->head_page->entries, 0);
73214 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
73215 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73216 local_set(&cpu_buffer->head_page->page->commit, 0);
73217
73218 cpu_buffer->head_page->read = 0;
73219 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73220
73221 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73222 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73223 - local_set(&cpu_buffer->reader_page->write, 0);
73224 - local_set(&cpu_buffer->reader_page->entries, 0);
73225 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73226 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73227 local_set(&cpu_buffer->reader_page->page->commit, 0);
73228 cpu_buffer->reader_page->read = 0;
73229
73230 - local_set(&cpu_buffer->commit_overrun, 0);
73231 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73232 local_set(&cpu_buffer->entries_bytes, 0);
73233 - local_set(&cpu_buffer->overrun, 0);
73234 + local_set_unchecked(&cpu_buffer->overrun, 0);
73235 local_set(&cpu_buffer->entries, 0);
73236 local_set(&cpu_buffer->committing, 0);
73237 local_set(&cpu_buffer->commits, 0);
73238 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73239 rb_init_page(bpage);
73240 bpage = reader->page;
73241 reader->page = *data_page;
73242 - local_set(&reader->write, 0);
73243 - local_set(&reader->entries, 0);
73244 + local_set_unchecked(&reader->write, 0);
73245 + local_set_unchecked(&reader->entries, 0);
73246 reader->read = 0;
73247 *data_page = bpage;
73248
73249 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73250 index 31e4f55..62da00f 100644
73251 --- a/kernel/trace/trace.c
73252 +++ b/kernel/trace/trace.c
73253 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73254 };
73255 #endif
73256
73257 -static struct dentry *d_tracer;
73258 -
73259 struct dentry *tracing_init_dentry(void)
73260 {
73261 + static struct dentry *d_tracer;
73262 static int once;
73263
73264 if (d_tracer)
73265 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73266 return d_tracer;
73267 }
73268
73269 -static struct dentry *d_percpu;
73270 -
73271 struct dentry *tracing_dentry_percpu(void)
73272 {
73273 + static struct dentry *d_percpu;
73274 static int once;
73275 struct dentry *d_tracer;
73276
73277 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73278 index d608d09..bd3801f 100644
73279 --- a/kernel/trace/trace_events.c
73280 +++ b/kernel/trace/trace_events.c
73281 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73282 struct ftrace_module_file_ops {
73283 struct list_head list;
73284 struct module *mod;
73285 - struct file_operations id;
73286 - struct file_operations enable;
73287 - struct file_operations format;
73288 - struct file_operations filter;
73289 };
73290
73291 static struct ftrace_module_file_ops *
73292 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73293
73294 file_ops->mod = mod;
73295
73296 - file_ops->id = ftrace_event_id_fops;
73297 - file_ops->id.owner = mod;
73298 -
73299 - file_ops->enable = ftrace_enable_fops;
73300 - file_ops->enable.owner = mod;
73301 -
73302 - file_ops->filter = ftrace_event_filter_fops;
73303 - file_ops->filter.owner = mod;
73304 -
73305 - file_ops->format = ftrace_event_format_fops;
73306 - file_ops->format.owner = mod;
73307 + pax_open_kernel();
73308 + mod->trace_id.owner = mod;
73309 + mod->trace_enable.owner = mod;
73310 + mod->trace_filter.owner = mod;
73311 + mod->trace_format.owner = mod;
73312 + pax_close_kernel();
73313
73314 list_add(&file_ops->list, &ftrace_module_file_list);
73315
73316 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73317
73318 for_each_event(call, start, end) {
73319 __trace_add_event_call(*call, mod,
73320 - &file_ops->id, &file_ops->enable,
73321 - &file_ops->filter, &file_ops->format);
73322 + &mod->trace_id, &mod->trace_enable,
73323 + &mod->trace_filter, &mod->trace_format);
73324 }
73325 }
73326
73327 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73328 index fd3c8aa..5f324a6 100644
73329 --- a/kernel/trace/trace_mmiotrace.c
73330 +++ b/kernel/trace/trace_mmiotrace.c
73331 @@ -24,7 +24,7 @@ struct header_iter {
73332 static struct trace_array *mmio_trace_array;
73333 static bool overrun_detected;
73334 static unsigned long prev_overruns;
73335 -static atomic_t dropped_count;
73336 +static atomic_unchecked_t dropped_count;
73337
73338 static void mmio_reset_data(struct trace_array *tr)
73339 {
73340 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73341
73342 static unsigned long count_overruns(struct trace_iterator *iter)
73343 {
73344 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
73345 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73346 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73347
73348 if (over > prev_overruns)
73349 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73350 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73351 sizeof(*entry), 0, pc);
73352 if (!event) {
73353 - atomic_inc(&dropped_count);
73354 + atomic_inc_unchecked(&dropped_count);
73355 return;
73356 }
73357 entry = ring_buffer_event_data(event);
73358 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73359 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73360 sizeof(*entry), 0, pc);
73361 if (!event) {
73362 - atomic_inc(&dropped_count);
73363 + atomic_inc_unchecked(&dropped_count);
73364 return;
73365 }
73366 entry = ring_buffer_event_data(event);
73367 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73368 index 123b189..1e9e2a6 100644
73369 --- a/kernel/trace/trace_output.c
73370 +++ b/kernel/trace/trace_output.c
73371 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73372
73373 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73374 if (!IS_ERR(p)) {
73375 - p = mangle_path(s->buffer + s->len, p, "\n");
73376 + p = mangle_path(s->buffer + s->len, p, "\n\\");
73377 if (p) {
73378 s->len = p - s->buffer;
73379 return 1;
73380 @@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73381 goto out;
73382 }
73383
73384 + pax_open_kernel();
73385 if (event->funcs->trace == NULL)
73386 - event->funcs->trace = trace_nop_print;
73387 + *(void **)&event->funcs->trace = trace_nop_print;
73388 if (event->funcs->raw == NULL)
73389 - event->funcs->raw = trace_nop_print;
73390 + *(void **)&event->funcs->raw = trace_nop_print;
73391 if (event->funcs->hex == NULL)
73392 - event->funcs->hex = trace_nop_print;
73393 + *(void **)&event->funcs->hex = trace_nop_print;
73394 if (event->funcs->binary == NULL)
73395 - event->funcs->binary = trace_nop_print;
73396 + *(void **)&event->funcs->binary = trace_nop_print;
73397 + pax_close_kernel();
73398
73399 key = event->type & (EVENT_HASHSIZE - 1);
73400
73401 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73402 index 0c1b1657..95337e9 100644
73403 --- a/kernel/trace/trace_stack.c
73404 +++ b/kernel/trace/trace_stack.c
73405 @@ -53,7 +53,7 @@ static inline void check_stack(void)
73406 return;
73407
73408 /* we do not handle interrupt stacks yet */
73409 - if (!object_is_on_stack(&this_size))
73410 + if (!object_starts_on_stack(&this_size))
73411 return;
73412
73413 local_irq_save(flags);
73414 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73415 index 28e9d6c9..50381bd 100644
73416 --- a/lib/Kconfig.debug
73417 +++ b/lib/Kconfig.debug
73418 @@ -1278,6 +1278,7 @@ config LATENCYTOP
73419 depends on DEBUG_KERNEL
73420 depends on STACKTRACE_SUPPORT
73421 depends on PROC_FS
73422 + depends on !GRKERNSEC_HIDESYM
73423 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73424 select KALLSYMS
73425 select KALLSYMS_ALL
73426 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73427
73428 config PROVIDE_OHCI1394_DMA_INIT
73429 bool "Remote debugging over FireWire early on boot"
73430 - depends on PCI && X86
73431 + depends on PCI && X86 && !GRKERNSEC
73432 help
73433 If you want to debug problems which hang or crash the kernel early
73434 on boot and the crashing machine has a FireWire port, you can use
73435 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73436
73437 config FIREWIRE_OHCI_REMOTE_DMA
73438 bool "Remote debugging over FireWire with firewire-ohci"
73439 - depends on FIREWIRE_OHCI
73440 + depends on FIREWIRE_OHCI && !GRKERNSEC
73441 help
73442 This option lets you use the FireWire bus for remote debugging
73443 with help of the firewire-ohci driver. It enables unfiltered
73444 diff --git a/lib/Makefile b/lib/Makefile
73445 index a08b791..a3ff1eb 100644
73446 --- a/lib/Makefile
73447 +++ b/lib/Makefile
73448 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73449
73450 obj-$(CONFIG_BTREE) += btree.o
73451 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73452 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73453 +obj-y += list_debug.o
73454 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73455
73456 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73457 diff --git a/lib/bitmap.c b/lib/bitmap.c
73458 index 06fdfa1..97c5c7d 100644
73459 --- a/lib/bitmap.c
73460 +++ b/lib/bitmap.c
73461 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73462 {
73463 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73464 u32 chunk;
73465 - const char __user __force *ubuf = (const char __user __force *)buf;
73466 + const char __user *ubuf = (const char __force_user *)buf;
73467
73468 bitmap_zero(maskp, nmaskbits);
73469
73470 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73471 {
73472 if (!access_ok(VERIFY_READ, ubuf, ulen))
73473 return -EFAULT;
73474 - return __bitmap_parse((const char __force *)ubuf,
73475 + return __bitmap_parse((const char __force_kernel *)ubuf,
73476 ulen, 1, maskp, nmaskbits);
73477
73478 }
73479 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73480 {
73481 unsigned a, b;
73482 int c, old_c, totaldigits;
73483 - const char __user __force *ubuf = (const char __user __force *)buf;
73484 + const char __user *ubuf = (const char __force_user *)buf;
73485 int exp_digit, in_range;
73486
73487 totaldigits = c = 0;
73488 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73489 {
73490 if (!access_ok(VERIFY_READ, ubuf, ulen))
73491 return -EFAULT;
73492 - return __bitmap_parselist((const char __force *)ubuf,
73493 + return __bitmap_parselist((const char __force_kernel *)ubuf,
73494 ulen, 1, maskp, nmaskbits);
73495 }
73496 EXPORT_SYMBOL(bitmap_parselist_user);
73497 diff --git a/lib/bug.c b/lib/bug.c
73498 index d0cdf14..4d07bd2 100644
73499 --- a/lib/bug.c
73500 +++ b/lib/bug.c
73501 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73502 return BUG_TRAP_TYPE_NONE;
73503
73504 bug = find_bug(bugaddr);
73505 + if (!bug)
73506 + return BUG_TRAP_TYPE_NONE;
73507
73508 file = NULL;
73509 line = 0;
73510 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73511 index d11808c..dc2d6f8 100644
73512 --- a/lib/debugobjects.c
73513 +++ b/lib/debugobjects.c
73514 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73515 if (limit > 4)
73516 return;
73517
73518 - is_on_stack = object_is_on_stack(addr);
73519 + is_on_stack = object_starts_on_stack(addr);
73520 if (is_on_stack == onstack)
73521 return;
73522
73523 diff --git a/lib/devres.c b/lib/devres.c
73524 index 80b9c76..9e32279 100644
73525 --- a/lib/devres.c
73526 +++ b/lib/devres.c
73527 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73528 void devm_iounmap(struct device *dev, void __iomem *addr)
73529 {
73530 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73531 - (void *)addr));
73532 + (void __force *)addr));
73533 iounmap(addr);
73534 }
73535 EXPORT_SYMBOL(devm_iounmap);
73536 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73537 {
73538 ioport_unmap(addr);
73539 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73540 - devm_ioport_map_match, (void *)addr));
73541 + devm_ioport_map_match, (void __force *)addr));
73542 }
73543 EXPORT_SYMBOL(devm_ioport_unmap);
73544
73545 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73546 index d84beb9..da44791 100644
73547 --- a/lib/dma-debug.c
73548 +++ b/lib/dma-debug.c
73549 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73550
73551 void dma_debug_add_bus(struct bus_type *bus)
73552 {
73553 - struct notifier_block *nb;
73554 + notifier_block_no_const *nb;
73555
73556 if (global_disable)
73557 return;
73558 @@ -919,7 +919,7 @@ out:
73559
73560 static void check_for_stack(struct device *dev, void *addr)
73561 {
73562 - if (object_is_on_stack(addr))
73563 + if (object_starts_on_stack(addr))
73564 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73565 "stack [addr=%p]\n", addr);
73566 }
73567 diff --git a/lib/inflate.c b/lib/inflate.c
73568 index 013a761..c28f3fc 100644
73569 --- a/lib/inflate.c
73570 +++ b/lib/inflate.c
73571 @@ -269,7 +269,7 @@ static void free(void *where)
73572 malloc_ptr = free_mem_ptr;
73573 }
73574 #else
73575 -#define malloc(a) kmalloc(a, GFP_KERNEL)
73576 +#define malloc(a) kmalloc((a), GFP_KERNEL)
73577 #define free(a) kfree(a)
73578 #endif
73579
73580 diff --git a/lib/ioremap.c b/lib/ioremap.c
73581 index 0c9216c..863bd89 100644
73582 --- a/lib/ioremap.c
73583 +++ b/lib/ioremap.c
73584 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73585 unsigned long next;
73586
73587 phys_addr -= addr;
73588 - pmd = pmd_alloc(&init_mm, pud, addr);
73589 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73590 if (!pmd)
73591 return -ENOMEM;
73592 do {
73593 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73594 unsigned long next;
73595
73596 phys_addr -= addr;
73597 - pud = pud_alloc(&init_mm, pgd, addr);
73598 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73599 if (!pud)
73600 return -ENOMEM;
73601 do {
73602 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73603 index bd2bea9..6b3c95e 100644
73604 --- a/lib/is_single_threaded.c
73605 +++ b/lib/is_single_threaded.c
73606 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73607 struct task_struct *p, *t;
73608 bool ret;
73609
73610 + if (!mm)
73611 + return true;
73612 +
73613 if (atomic_read(&task->signal->live) != 1)
73614 return false;
73615
73616 diff --git a/lib/list_debug.c b/lib/list_debug.c
73617 index c24c2f7..3fc5da0 100644
73618 --- a/lib/list_debug.c
73619 +++ b/lib/list_debug.c
73620 @@ -11,7 +11,9 @@
73621 #include <linux/bug.h>
73622 #include <linux/kernel.h>
73623 #include <linux/rculist.h>
73624 +#include <linux/mm.h>
73625
73626 +#ifdef CONFIG_DEBUG_LIST
73627 /*
73628 * Insert a new entry between two known consecutive entries.
73629 *
73630 @@ -19,21 +21,32 @@
73631 * the prev/next entries already!
73632 */
73633
73634 -void __list_add(struct list_head *new,
73635 - struct list_head *prev,
73636 - struct list_head *next)
73637 +static bool __list_add_debug(struct list_head *new,
73638 + struct list_head *prev,
73639 + struct list_head *next)
73640 {
73641 - WARN(next->prev != prev,
73642 + if (WARN(next->prev != prev,
73643 "list_add corruption. next->prev should be "
73644 "prev (%p), but was %p. (next=%p).\n",
73645 - prev, next->prev, next);
73646 - WARN(prev->next != next,
73647 + prev, next->prev, next) ||
73648 + WARN(prev->next != next,
73649 "list_add corruption. prev->next should be "
73650 "next (%p), but was %p. (prev=%p).\n",
73651 - next, prev->next, prev);
73652 - WARN(new == prev || new == next,
73653 + next, prev->next, prev) ||
73654 + WARN(new == prev || new == next,
73655 "list_add double add: new=%p, prev=%p, next=%p.\n",
73656 - new, prev, next);
73657 + new, prev, next))
73658 + return false;
73659 + return true;
73660 +}
73661 +
73662 +void __list_add(struct list_head *new,
73663 + struct list_head *prev,
73664 + struct list_head *next)
73665 +{
73666 + if (!__list_add_debug(new, prev, next))
73667 + return;
73668 +
73669 next->prev = new;
73670 new->next = next;
73671 new->prev = prev;
73672 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73673 }
73674 EXPORT_SYMBOL(__list_add);
73675
73676 -void __list_del_entry(struct list_head *entry)
73677 +static bool __list_del_entry_debug(struct list_head *entry)
73678 {
73679 struct list_head *prev, *next;
73680
73681 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73682 WARN(next->prev != entry,
73683 "list_del corruption. next->prev should be %p, "
73684 "but was %p\n", entry, next->prev))
73685 + return false;
73686 + return true;
73687 +}
73688 +
73689 +void __list_del_entry(struct list_head *entry)
73690 +{
73691 + if (!__list_del_entry_debug(entry))
73692 return;
73693
73694 - __list_del(prev, next);
73695 + __list_del(entry->prev, entry->next);
73696 }
73697 EXPORT_SYMBOL(__list_del_entry);
73698
73699 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73700 void __list_add_rcu(struct list_head *new,
73701 struct list_head *prev, struct list_head *next)
73702 {
73703 - WARN(next->prev != prev,
73704 + if (WARN(next->prev != prev,
73705 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73706 - prev, next->prev, next);
73707 - WARN(prev->next != next,
73708 + prev, next->prev, next) ||
73709 + WARN(prev->next != next,
73710 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73711 - next, prev->next, prev);
73712 + next, prev->next, prev))
73713 + return;
73714 +
73715 new->next = next;
73716 new->prev = prev;
73717 rcu_assign_pointer(list_next_rcu(prev), new);
73718 next->prev = new;
73719 }
73720 EXPORT_SYMBOL(__list_add_rcu);
73721 +#endif
73722 +
73723 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73724 +{
73725 + struct list_head *prev, *next;
73726 +
73727 + prev = head->prev;
73728 + next = head;
73729 +
73730 +#ifdef CONFIG_DEBUG_LIST
73731 + if (!__list_add_debug(new, prev, next))
73732 + return;
73733 +#endif
73734 +
73735 + pax_open_kernel();
73736 + next->prev = new;
73737 + new->next = next;
73738 + new->prev = prev;
73739 + prev->next = new;
73740 + pax_close_kernel();
73741 +}
73742 +EXPORT_SYMBOL(pax_list_add_tail);
73743 +
73744 +void pax_list_del(struct list_head *entry)
73745 +{
73746 +#ifdef CONFIG_DEBUG_LIST
73747 + if (!__list_del_entry_debug(entry))
73748 + return;
73749 +#endif
73750 +
73751 + pax_open_kernel();
73752 + __list_del(entry->prev, entry->next);
73753 + entry->next = LIST_POISON1;
73754 + entry->prev = LIST_POISON2;
73755 + pax_close_kernel();
73756 +}
73757 +EXPORT_SYMBOL(pax_list_del);
73758 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73759 index e796429..6e38f9f 100644
73760 --- a/lib/radix-tree.c
73761 +++ b/lib/radix-tree.c
73762 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73763 int nr;
73764 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73765 };
73766 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73767 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73768
73769 static inline void *ptr_to_indirect(void *ptr)
73770 {
73771 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73772 index bb2b201..46abaf9 100644
73773 --- a/lib/strncpy_from_user.c
73774 +++ b/lib/strncpy_from_user.c
73775 @@ -21,7 +21,7 @@
73776 */
73777 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73778 {
73779 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73780 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73781 long res = 0;
73782
73783 /*
73784 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73785 index a28df52..3d55877 100644
73786 --- a/lib/strnlen_user.c
73787 +++ b/lib/strnlen_user.c
73788 @@ -26,7 +26,7 @@
73789 */
73790 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73791 {
73792 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73793 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73794 long align, res = 0;
73795 unsigned long c;
73796
73797 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73798 index 39c99fe..18f060b 100644
73799 --- a/lib/vsprintf.c
73800 +++ b/lib/vsprintf.c
73801 @@ -16,6 +16,9 @@
73802 * - scnprintf and vscnprintf
73803 */
73804
73805 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73806 +#define __INCLUDED_BY_HIDESYM 1
73807 +#endif
73808 #include <stdarg.h>
73809 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73810 #include <linux/types.h>
73811 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73812 char sym[KSYM_SYMBOL_LEN];
73813 if (ext == 'B')
73814 sprint_backtrace(sym, value);
73815 - else if (ext != 'f' && ext != 's')
73816 + else if (ext != 'f' && ext != 's' && ext != 'a')
73817 sprint_symbol(sym, value);
73818 else
73819 sprint_symbol_no_offset(sym, value);
73820 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73821 return number(buf, end, *(const netdev_features_t *)addr, spec);
73822 }
73823
73824 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73825 +int kptr_restrict __read_mostly = 2;
73826 +#else
73827 int kptr_restrict __read_mostly;
73828 +#endif
73829
73830 /*
73831 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73832 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73833 * - 'S' For symbolic direct pointers with offset
73834 * - 's' For symbolic direct pointers without offset
73835 * - 'B' For backtraced symbolic direct pointers with offset
73836 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73837 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73838 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73839 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73840 * - 'M' For a 6-byte MAC address, it prints the address in the
73841 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73842
73843 if (!ptr && *fmt != 'K') {
73844 /*
73845 - * Print (null) with the same width as a pointer so it makes
73846 + * Print (nil) with the same width as a pointer so it makes
73847 * tabular output look nice.
73848 */
73849 if (spec.field_width == -1)
73850 spec.field_width = default_width;
73851 - return string(buf, end, "(null)", spec);
73852 + return string(buf, end, "(nil)", spec);
73853 }
73854
73855 switch (*fmt) {
73856 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73857 /* Fallthrough */
73858 case 'S':
73859 case 's':
73860 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73861 + break;
73862 +#else
73863 + return symbol_string(buf, end, ptr, spec, *fmt);
73864 +#endif
73865 + case 'A':
73866 + case 'a':
73867 case 'B':
73868 return symbol_string(buf, end, ptr, spec, *fmt);
73869 case 'R':
73870 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73871 va_end(va);
73872 return buf;
73873 }
73874 + case 'P':
73875 + break;
73876 case 'K':
73877 /*
73878 * %pK cannot be used in IRQ context because its test
73879 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73880 }
73881 break;
73882 }
73883 +
73884 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73885 + /* 'P' = approved pointers to copy to userland,
73886 + as in the /proc/kallsyms case, as we make it display nothing
73887 + for non-root users, and the real contents for root users
73888 + Also ignore 'K' pointers, since we force their NULLing for non-root users
73889 + above
73890 + */
73891 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
73892 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
73893 + dump_stack();
73894 + ptr = NULL;
73895 + }
73896 +#endif
73897 +
73898 spec.flags |= SMALL;
73899 if (spec.field_width == -1) {
73900 spec.field_width = default_width;
73901 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73902 typeof(type) value; \
73903 if (sizeof(type) == 8) { \
73904 args = PTR_ALIGN(args, sizeof(u32)); \
73905 - *(u32 *)&value = *(u32 *)args; \
73906 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
73907 + *(u32 *)&value = *(const u32 *)args; \
73908 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
73909 } else { \
73910 args = PTR_ALIGN(args, sizeof(type)); \
73911 - value = *(typeof(type) *)args; \
73912 + value = *(const typeof(type) *)args; \
73913 } \
73914 args += sizeof(type); \
73915 value; \
73916 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73917 case FORMAT_TYPE_STR: {
73918 const char *str_arg = args;
73919 args += strlen(str_arg) + 1;
73920 - str = string(str, end, (char *)str_arg, spec);
73921 + str = string(str, end, str_arg, spec);
73922 break;
73923 }
73924
73925 diff --git a/localversion-grsec b/localversion-grsec
73926 new file mode 100644
73927 index 0000000..7cd6065
73928 --- /dev/null
73929 +++ b/localversion-grsec
73930 @@ -0,0 +1 @@
73931 +-grsec
73932 diff --git a/mm/Kconfig b/mm/Kconfig
73933 index a3f8ddd..f31e92e 100644
73934 --- a/mm/Kconfig
73935 +++ b/mm/Kconfig
73936 @@ -252,10 +252,10 @@ config KSM
73937 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
73938
73939 config DEFAULT_MMAP_MIN_ADDR
73940 - int "Low address space to protect from user allocation"
73941 + int "Low address space to protect from user allocation"
73942 depends on MMU
73943 - default 4096
73944 - help
73945 + default 65536
73946 + help
73947 This is the portion of low virtual memory which should be protected
73948 from userspace allocation. Keeping a user from writing to low pages
73949 can help reduce the impact of kernel NULL pointer bugs.
73950 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
73951
73952 config HWPOISON_INJECT
73953 tristate "HWPoison pages injector"
73954 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
73955 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
73956 select PROC_PAGE_MONITOR
73957
73958 config NOMMU_INITIAL_TRIM_EXCESS
73959 diff --git a/mm/filemap.c b/mm/filemap.c
73960 index 83efee7..3f99381 100644
73961 --- a/mm/filemap.c
73962 +++ b/mm/filemap.c
73963 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
73964 struct address_space *mapping = file->f_mapping;
73965
73966 if (!mapping->a_ops->readpage)
73967 - return -ENOEXEC;
73968 + return -ENODEV;
73969 file_accessed(file);
73970 vma->vm_ops = &generic_file_vm_ops;
73971 return 0;
73972 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
73973 *pos = i_size_read(inode);
73974
73975 if (limit != RLIM_INFINITY) {
73976 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
73977 if (*pos >= limit) {
73978 send_sig(SIGXFSZ, current, 0);
73979 return -EFBIG;
73980 diff --git a/mm/fremap.c b/mm/fremap.c
73981 index a0aaf0e..20325c3 100644
73982 --- a/mm/fremap.c
73983 +++ b/mm/fremap.c
73984 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
73985 retry:
73986 vma = find_vma(mm, start);
73987
73988 +#ifdef CONFIG_PAX_SEGMEXEC
73989 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
73990 + goto out;
73991 +#endif
73992 +
73993 /*
73994 * Make sure the vma is shared, that it supports prefaulting,
73995 * and that the remapped range is valid and fully within
73996 diff --git a/mm/highmem.c b/mm/highmem.c
73997 index 09fc744..3936897 100644
73998 --- a/mm/highmem.c
73999 +++ b/mm/highmem.c
74000 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
74001 * So no dangers, even with speculative execution.
74002 */
74003 page = pte_page(pkmap_page_table[i]);
74004 + pax_open_kernel();
74005 pte_clear(&init_mm, (unsigned long)page_address(page),
74006 &pkmap_page_table[i]);
74007 -
74008 + pax_close_kernel();
74009 set_page_address(page, NULL);
74010 need_flush = 1;
74011 }
74012 @@ -199,9 +200,11 @@ start:
74013 }
74014 }
74015 vaddr = PKMAP_ADDR(last_pkmap_nr);
74016 +
74017 + pax_open_kernel();
74018 set_pte_at(&init_mm, vaddr,
74019 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74020 -
74021 + pax_close_kernel();
74022 pkmap_count[last_pkmap_nr] = 1;
74023 set_page_address(page, (void *)vaddr);
74024
74025 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74026 index 40f17c3..c1cc011 100644
74027 --- a/mm/huge_memory.c
74028 +++ b/mm/huge_memory.c
74029 @@ -710,7 +710,7 @@ out:
74030 * run pte_offset_map on the pmd, if an huge pmd could
74031 * materialize from under us from a different thread.
74032 */
74033 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74034 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74035 return VM_FAULT_OOM;
74036 /* if an huge pmd materialized from under us just retry later */
74037 if (unlikely(pmd_trans_huge(*pmd)))
74038 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74039 index b969ed4..10e3e37 100644
74040 --- a/mm/hugetlb.c
74041 +++ b/mm/hugetlb.c
74042 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74043 return 1;
74044 }
74045
74046 +#ifdef CONFIG_PAX_SEGMEXEC
74047 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74048 +{
74049 + struct mm_struct *mm = vma->vm_mm;
74050 + struct vm_area_struct *vma_m;
74051 + unsigned long address_m;
74052 + pte_t *ptep_m;
74053 +
74054 + vma_m = pax_find_mirror_vma(vma);
74055 + if (!vma_m)
74056 + return;
74057 +
74058 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74059 + address_m = address + SEGMEXEC_TASK_SIZE;
74060 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74061 + get_page(page_m);
74062 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
74063 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74064 +}
74065 +#endif
74066 +
74067 /*
74068 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74069 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74070 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
74071 make_huge_pte(vma, new_page, 1));
74072 page_remove_rmap(old_page);
74073 hugepage_add_new_anon_rmap(new_page, vma, address);
74074 +
74075 +#ifdef CONFIG_PAX_SEGMEXEC
74076 + pax_mirror_huge_pte(vma, address, new_page);
74077 +#endif
74078 +
74079 /* Make the old page be freed below */
74080 new_page = old_page;
74081 }
74082 @@ -2786,6 +2812,10 @@ retry:
74083 && (vma->vm_flags & VM_SHARED)));
74084 set_huge_pte_at(mm, address, ptep, new_pte);
74085
74086 +#ifdef CONFIG_PAX_SEGMEXEC
74087 + pax_mirror_huge_pte(vma, address, page);
74088 +#endif
74089 +
74090 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74091 /* Optimization, do the COW without a second fault */
74092 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74093 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74094 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74095 struct hstate *h = hstate_vma(vma);
74096
74097 +#ifdef CONFIG_PAX_SEGMEXEC
74098 + struct vm_area_struct *vma_m;
74099 +#endif
74100 +
74101 address &= huge_page_mask(h);
74102
74103 ptep = huge_pte_offset(mm, address);
74104 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74105 VM_FAULT_SET_HINDEX(hstate_index(h));
74106 }
74107
74108 +#ifdef CONFIG_PAX_SEGMEXEC
74109 + vma_m = pax_find_mirror_vma(vma);
74110 + if (vma_m) {
74111 + unsigned long address_m;
74112 +
74113 + if (vma->vm_start > vma_m->vm_start) {
74114 + address_m = address;
74115 + address -= SEGMEXEC_TASK_SIZE;
74116 + vma = vma_m;
74117 + h = hstate_vma(vma);
74118 + } else
74119 + address_m = address + SEGMEXEC_TASK_SIZE;
74120 +
74121 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74122 + return VM_FAULT_OOM;
74123 + address_m &= HPAGE_MASK;
74124 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74125 + }
74126 +#endif
74127 +
74128 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74129 if (!ptep)
74130 return VM_FAULT_OOM;
74131 diff --git a/mm/internal.h b/mm/internal.h
74132 index 3c5197d..08d0065 100644
74133 --- a/mm/internal.h
74134 +++ b/mm/internal.h
74135 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74136 * in mm/page_alloc.c
74137 */
74138 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74139 +extern void free_compound_page(struct page *page);
74140 extern void prep_compound_page(struct page *page, unsigned long order);
74141 #ifdef CONFIG_MEMORY_FAILURE
74142 extern bool is_free_buddy_page(struct page *page);
74143 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74144 index a217cc5..44b2b35 100644
74145 --- a/mm/kmemleak.c
74146 +++ b/mm/kmemleak.c
74147 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74148
74149 for (i = 0; i < object->trace_len; i++) {
74150 void *ptr = (void *)object->trace[i];
74151 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74152 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
74153 }
74154 }
74155
74156 @@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
74157 return -ENOMEM;
74158 }
74159
74160 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
74161 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
74162 &kmemleak_fops);
74163 if (!dentry)
74164 pr_warning("Failed to create the debugfs kmemleak file\n");
74165 diff --git a/mm/maccess.c b/mm/maccess.c
74166 index d53adf9..03a24bf 100644
74167 --- a/mm/maccess.c
74168 +++ b/mm/maccess.c
74169 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74170 set_fs(KERNEL_DS);
74171 pagefault_disable();
74172 ret = __copy_from_user_inatomic(dst,
74173 - (__force const void __user *)src, size);
74174 + (const void __force_user *)src, size);
74175 pagefault_enable();
74176 set_fs(old_fs);
74177
74178 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74179
74180 set_fs(KERNEL_DS);
74181 pagefault_disable();
74182 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74183 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74184 pagefault_enable();
74185 set_fs(old_fs);
74186
74187 diff --git a/mm/madvise.c b/mm/madvise.c
74188 index 03dfa5c..b032917 100644
74189 --- a/mm/madvise.c
74190 +++ b/mm/madvise.c
74191 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74192 pgoff_t pgoff;
74193 unsigned long new_flags = vma->vm_flags;
74194
74195 +#ifdef CONFIG_PAX_SEGMEXEC
74196 + struct vm_area_struct *vma_m;
74197 +#endif
74198 +
74199 switch (behavior) {
74200 case MADV_NORMAL:
74201 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74202 @@ -123,6 +127,13 @@ success:
74203 /*
74204 * vm_flags is protected by the mmap_sem held in write mode.
74205 */
74206 +
74207 +#ifdef CONFIG_PAX_SEGMEXEC
74208 + vma_m = pax_find_mirror_vma(vma);
74209 + if (vma_m)
74210 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74211 +#endif
74212 +
74213 vma->vm_flags = new_flags;
74214
74215 out:
74216 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74217 struct vm_area_struct ** prev,
74218 unsigned long start, unsigned long end)
74219 {
74220 +
74221 +#ifdef CONFIG_PAX_SEGMEXEC
74222 + struct vm_area_struct *vma_m;
74223 +#endif
74224 +
74225 *prev = vma;
74226 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74227 return -EINVAL;
74228 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74229 zap_page_range(vma, start, end - start, &details);
74230 } else
74231 zap_page_range(vma, start, end - start, NULL);
74232 +
74233 +#ifdef CONFIG_PAX_SEGMEXEC
74234 + vma_m = pax_find_mirror_vma(vma);
74235 + if (vma_m) {
74236 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74237 + struct zap_details details = {
74238 + .nonlinear_vma = vma_m,
74239 + .last_index = ULONG_MAX,
74240 + };
74241 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74242 + } else
74243 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74244 + }
74245 +#endif
74246 +
74247 return 0;
74248 }
74249
74250 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74251 if (end < start)
74252 goto out;
74253
74254 +#ifdef CONFIG_PAX_SEGMEXEC
74255 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74256 + if (end > SEGMEXEC_TASK_SIZE)
74257 + goto out;
74258 + } else
74259 +#endif
74260 +
74261 + if (end > TASK_SIZE)
74262 + goto out;
74263 +
74264 error = 0;
74265 if (end == start)
74266 goto out;
74267 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74268 index 8b20278..05dac18 100644
74269 --- a/mm/memory-failure.c
74270 +++ b/mm/memory-failure.c
74271 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74272
74273 int sysctl_memory_failure_recovery __read_mostly = 1;
74274
74275 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74276 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74277
74278 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74279
74280 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74281 pfn, t->comm, t->pid);
74282 si.si_signo = SIGBUS;
74283 si.si_errno = 0;
74284 - si.si_addr = (void *)addr;
74285 + si.si_addr = (void __user *)addr;
74286 #ifdef __ARCH_SI_TRAPNO
74287 si.si_trapno = trapno;
74288 #endif
74289 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74290 }
74291
74292 nr_pages = 1 << compound_trans_order(hpage);
74293 - atomic_long_add(nr_pages, &mce_bad_pages);
74294 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74295
74296 /*
74297 * We need/can do nothing about count=0 pages.
74298 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74299 if (!PageHWPoison(hpage)
74300 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74301 || (p != hpage && TestSetPageHWPoison(hpage))) {
74302 - atomic_long_sub(nr_pages, &mce_bad_pages);
74303 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74304 return 0;
74305 }
74306 set_page_hwpoison_huge_page(hpage);
74307 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74308 }
74309 if (hwpoison_filter(p)) {
74310 if (TestClearPageHWPoison(p))
74311 - atomic_long_sub(nr_pages, &mce_bad_pages);
74312 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74313 unlock_page(hpage);
74314 put_page(hpage);
74315 return 0;
74316 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74317 return 0;
74318 }
74319 if (TestClearPageHWPoison(p))
74320 - atomic_long_sub(nr_pages, &mce_bad_pages);
74321 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74322 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74323 return 0;
74324 }
74325 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74326 */
74327 if (TestClearPageHWPoison(page)) {
74328 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74329 - atomic_long_sub(nr_pages, &mce_bad_pages);
74330 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74331 freeit = 1;
74332 if (PageHuge(page))
74333 clear_page_hwpoison_huge_page(page);
74334 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74335 }
74336 done:
74337 if (!PageHWPoison(hpage))
74338 - atomic_long_add(1 << compound_trans_order(hpage),
74339 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74340 &mce_bad_pages);
74341 set_page_hwpoison_huge_page(hpage);
74342 dequeue_hwpoisoned_huge_page(hpage);
74343 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74344 return ret;
74345
74346 done:
74347 - atomic_long_add(1, &mce_bad_pages);
74348 + atomic_long_add_unchecked(1, &mce_bad_pages);
74349 SetPageHWPoison(page);
74350 /* keep elevated page count for bad page */
74351 return ret;
74352 diff --git a/mm/memory.c b/mm/memory.c
74353 index f2973b2..fd020a7 100644
74354 --- a/mm/memory.c
74355 +++ b/mm/memory.c
74356 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74357 free_pte_range(tlb, pmd, addr);
74358 } while (pmd++, addr = next, addr != end);
74359
74360 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74361 start &= PUD_MASK;
74362 if (start < floor)
74363 return;
74364 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74365 pmd = pmd_offset(pud, start);
74366 pud_clear(pud);
74367 pmd_free_tlb(tlb, pmd, start);
74368 +#endif
74369 +
74370 }
74371
74372 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74373 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74374 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74375 } while (pud++, addr = next, addr != end);
74376
74377 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74378 start &= PGDIR_MASK;
74379 if (start < floor)
74380 return;
74381 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74382 pud = pud_offset(pgd, start);
74383 pgd_clear(pgd);
74384 pud_free_tlb(tlb, pud, start);
74385 +#endif
74386 +
74387 }
74388
74389 /*
74390 @@ -1626,12 +1632,6 @@ no_page_table:
74391 return page;
74392 }
74393
74394 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74395 -{
74396 - return stack_guard_page_start(vma, addr) ||
74397 - stack_guard_page_end(vma, addr+PAGE_SIZE);
74398 -}
74399 -
74400 /**
74401 * __get_user_pages() - pin user pages in memory
74402 * @tsk: task_struct of target task
74403 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74404 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74405 i = 0;
74406
74407 - do {
74408 + while (nr_pages) {
74409 struct vm_area_struct *vma;
74410
74411 - vma = find_extend_vma(mm, start);
74412 + vma = find_vma(mm, start);
74413 if (!vma && in_gate_area(mm, start)) {
74414 unsigned long pg = start & PAGE_MASK;
74415 pgd_t *pgd;
74416 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74417 goto next_page;
74418 }
74419
74420 - if (!vma ||
74421 + if (!vma || start < vma->vm_start ||
74422 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74423 !(vm_flags & vma->vm_flags))
74424 return i ? : -EFAULT;
74425 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74426 int ret;
74427 unsigned int fault_flags = 0;
74428
74429 - /* For mlock, just skip the stack guard page. */
74430 - if (foll_flags & FOLL_MLOCK) {
74431 - if (stack_guard_page(vma, start))
74432 - goto next_page;
74433 - }
74434 if (foll_flags & FOLL_WRITE)
74435 fault_flags |= FAULT_FLAG_WRITE;
74436 if (nonblocking)
74437 @@ -1860,7 +1855,7 @@ next_page:
74438 start += PAGE_SIZE;
74439 nr_pages--;
74440 } while (nr_pages && start < vma->vm_end);
74441 - } while (nr_pages);
74442 + }
74443 return i;
74444 }
74445 EXPORT_SYMBOL(__get_user_pages);
74446 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74447 page_add_file_rmap(page);
74448 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74449
74450 +#ifdef CONFIG_PAX_SEGMEXEC
74451 + pax_mirror_file_pte(vma, addr, page, ptl);
74452 +#endif
74453 +
74454 retval = 0;
74455 pte_unmap_unlock(pte, ptl);
74456 return retval;
74457 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74458 if (!page_count(page))
74459 return -EINVAL;
74460 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74461 +
74462 +#ifdef CONFIG_PAX_SEGMEXEC
74463 + struct vm_area_struct *vma_m;
74464 +#endif
74465 +
74466 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74467 BUG_ON(vma->vm_flags & VM_PFNMAP);
74468 vma->vm_flags |= VM_MIXEDMAP;
74469 +
74470 +#ifdef CONFIG_PAX_SEGMEXEC
74471 + vma_m = pax_find_mirror_vma(vma);
74472 + if (vma_m)
74473 + vma_m->vm_flags |= VM_MIXEDMAP;
74474 +#endif
74475 +
74476 }
74477 return insert_page(vma, addr, page, vma->vm_page_prot);
74478 }
74479 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74480 unsigned long pfn)
74481 {
74482 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74483 + BUG_ON(vma->vm_mirror);
74484
74485 if (addr < vma->vm_start || addr >= vma->vm_end)
74486 return -EFAULT;
74487 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74488
74489 BUG_ON(pud_huge(*pud));
74490
74491 - pmd = pmd_alloc(mm, pud, addr);
74492 + pmd = (mm == &init_mm) ?
74493 + pmd_alloc_kernel(mm, pud, addr) :
74494 + pmd_alloc(mm, pud, addr);
74495 if (!pmd)
74496 return -ENOMEM;
74497 do {
74498 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74499 unsigned long next;
74500 int err;
74501
74502 - pud = pud_alloc(mm, pgd, addr);
74503 + pud = (mm == &init_mm) ?
74504 + pud_alloc_kernel(mm, pgd, addr) :
74505 + pud_alloc(mm, pgd, addr);
74506 if (!pud)
74507 return -ENOMEM;
74508 do {
74509 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74510 copy_user_highpage(dst, src, va, vma);
74511 }
74512
74513 +#ifdef CONFIG_PAX_SEGMEXEC
74514 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74515 +{
74516 + struct mm_struct *mm = vma->vm_mm;
74517 + spinlock_t *ptl;
74518 + pte_t *pte, entry;
74519 +
74520 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74521 + entry = *pte;
74522 + if (!pte_present(entry)) {
74523 + if (!pte_none(entry)) {
74524 + BUG_ON(pte_file(entry));
74525 + free_swap_and_cache(pte_to_swp_entry(entry));
74526 + pte_clear_not_present_full(mm, address, pte, 0);
74527 + }
74528 + } else {
74529 + struct page *page;
74530 +
74531 + flush_cache_page(vma, address, pte_pfn(entry));
74532 + entry = ptep_clear_flush(vma, address, pte);
74533 + BUG_ON(pte_dirty(entry));
74534 + page = vm_normal_page(vma, address, entry);
74535 + if (page) {
74536 + update_hiwater_rss(mm);
74537 + if (PageAnon(page))
74538 + dec_mm_counter_fast(mm, MM_ANONPAGES);
74539 + else
74540 + dec_mm_counter_fast(mm, MM_FILEPAGES);
74541 + page_remove_rmap(page);
74542 + page_cache_release(page);
74543 + }
74544 + }
74545 + pte_unmap_unlock(pte, ptl);
74546 +}
74547 +
74548 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
74549 + *
74550 + * the ptl of the lower mapped page is held on entry and is not released on exit
74551 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74552 + */
74553 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74554 +{
74555 + struct mm_struct *mm = vma->vm_mm;
74556 + unsigned long address_m;
74557 + spinlock_t *ptl_m;
74558 + struct vm_area_struct *vma_m;
74559 + pmd_t *pmd_m;
74560 + pte_t *pte_m, entry_m;
74561 +
74562 + BUG_ON(!page_m || !PageAnon(page_m));
74563 +
74564 + vma_m = pax_find_mirror_vma(vma);
74565 + if (!vma_m)
74566 + return;
74567 +
74568 + BUG_ON(!PageLocked(page_m));
74569 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74570 + address_m = address + SEGMEXEC_TASK_SIZE;
74571 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74572 + pte_m = pte_offset_map(pmd_m, address_m);
74573 + ptl_m = pte_lockptr(mm, pmd_m);
74574 + if (ptl != ptl_m) {
74575 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74576 + if (!pte_none(*pte_m))
74577 + goto out;
74578 + }
74579 +
74580 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74581 + page_cache_get(page_m);
74582 + page_add_anon_rmap(page_m, vma_m, address_m);
74583 + inc_mm_counter_fast(mm, MM_ANONPAGES);
74584 + set_pte_at(mm, address_m, pte_m, entry_m);
74585 + update_mmu_cache(vma_m, address_m, entry_m);
74586 +out:
74587 + if (ptl != ptl_m)
74588 + spin_unlock(ptl_m);
74589 + pte_unmap(pte_m);
74590 + unlock_page(page_m);
74591 +}
74592 +
74593 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74594 +{
74595 + struct mm_struct *mm = vma->vm_mm;
74596 + unsigned long address_m;
74597 + spinlock_t *ptl_m;
74598 + struct vm_area_struct *vma_m;
74599 + pmd_t *pmd_m;
74600 + pte_t *pte_m, entry_m;
74601 +
74602 + BUG_ON(!page_m || PageAnon(page_m));
74603 +
74604 + vma_m = pax_find_mirror_vma(vma);
74605 + if (!vma_m)
74606 + return;
74607 +
74608 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74609 + address_m = address + SEGMEXEC_TASK_SIZE;
74610 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74611 + pte_m = pte_offset_map(pmd_m, address_m);
74612 + ptl_m = pte_lockptr(mm, pmd_m);
74613 + if (ptl != ptl_m) {
74614 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74615 + if (!pte_none(*pte_m))
74616 + goto out;
74617 + }
74618 +
74619 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74620 + page_cache_get(page_m);
74621 + page_add_file_rmap(page_m);
74622 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74623 + set_pte_at(mm, address_m, pte_m, entry_m);
74624 + update_mmu_cache(vma_m, address_m, entry_m);
74625 +out:
74626 + if (ptl != ptl_m)
74627 + spin_unlock(ptl_m);
74628 + pte_unmap(pte_m);
74629 +}
74630 +
74631 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74632 +{
74633 + struct mm_struct *mm = vma->vm_mm;
74634 + unsigned long address_m;
74635 + spinlock_t *ptl_m;
74636 + struct vm_area_struct *vma_m;
74637 + pmd_t *pmd_m;
74638 + pte_t *pte_m, entry_m;
74639 +
74640 + vma_m = pax_find_mirror_vma(vma);
74641 + if (!vma_m)
74642 + return;
74643 +
74644 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74645 + address_m = address + SEGMEXEC_TASK_SIZE;
74646 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74647 + pte_m = pte_offset_map(pmd_m, address_m);
74648 + ptl_m = pte_lockptr(mm, pmd_m);
74649 + if (ptl != ptl_m) {
74650 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74651 + if (!pte_none(*pte_m))
74652 + goto out;
74653 + }
74654 +
74655 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74656 + set_pte_at(mm, address_m, pte_m, entry_m);
74657 +out:
74658 + if (ptl != ptl_m)
74659 + spin_unlock(ptl_m);
74660 + pte_unmap(pte_m);
74661 +}
74662 +
74663 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74664 +{
74665 + struct page *page_m;
74666 + pte_t entry;
74667 +
74668 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74669 + goto out;
74670 +
74671 + entry = *pte;
74672 + page_m = vm_normal_page(vma, address, entry);
74673 + if (!page_m)
74674 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74675 + else if (PageAnon(page_m)) {
74676 + if (pax_find_mirror_vma(vma)) {
74677 + pte_unmap_unlock(pte, ptl);
74678 + lock_page(page_m);
74679 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74680 + if (pte_same(entry, *pte))
74681 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74682 + else
74683 + unlock_page(page_m);
74684 + }
74685 + } else
74686 + pax_mirror_file_pte(vma, address, page_m, ptl);
74687 +
74688 +out:
74689 + pte_unmap_unlock(pte, ptl);
74690 +}
74691 +#endif
74692 +
74693 /*
74694 * This routine handles present pages, when users try to write
74695 * to a shared page. It is done by copying the page to a new address
74696 @@ -2720,6 +2916,12 @@ gotten:
74697 */
74698 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74699 if (likely(pte_same(*page_table, orig_pte))) {
74700 +
74701 +#ifdef CONFIG_PAX_SEGMEXEC
74702 + if (pax_find_mirror_vma(vma))
74703 + BUG_ON(!trylock_page(new_page));
74704 +#endif
74705 +
74706 if (old_page) {
74707 if (!PageAnon(old_page)) {
74708 dec_mm_counter_fast(mm, MM_FILEPAGES);
74709 @@ -2771,6 +2973,10 @@ gotten:
74710 page_remove_rmap(old_page);
74711 }
74712
74713 +#ifdef CONFIG_PAX_SEGMEXEC
74714 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74715 +#endif
74716 +
74717 /* Free the old page.. */
74718 new_page = old_page;
74719 ret |= VM_FAULT_WRITE;
74720 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74721 swap_free(entry);
74722 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74723 try_to_free_swap(page);
74724 +
74725 +#ifdef CONFIG_PAX_SEGMEXEC
74726 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74727 +#endif
74728 +
74729 unlock_page(page);
74730 if (swapcache) {
74731 /*
74732 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74733
74734 /* No need to invalidate - it was non-present before */
74735 update_mmu_cache(vma, address, page_table);
74736 +
74737 +#ifdef CONFIG_PAX_SEGMEXEC
74738 + pax_mirror_anon_pte(vma, address, page, ptl);
74739 +#endif
74740 +
74741 unlock:
74742 pte_unmap_unlock(page_table, ptl);
74743 out:
74744 @@ -3093,40 +3309,6 @@ out_release:
74745 }
74746
74747 /*
74748 - * This is like a special single-page "expand_{down|up}wards()",
74749 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74750 - * doesn't hit another vma.
74751 - */
74752 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74753 -{
74754 - address &= PAGE_MASK;
74755 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74756 - struct vm_area_struct *prev = vma->vm_prev;
74757 -
74758 - /*
74759 - * Is there a mapping abutting this one below?
74760 - *
74761 - * That's only ok if it's the same stack mapping
74762 - * that has gotten split..
74763 - */
74764 - if (prev && prev->vm_end == address)
74765 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74766 -
74767 - expand_downwards(vma, address - PAGE_SIZE);
74768 - }
74769 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74770 - struct vm_area_struct *next = vma->vm_next;
74771 -
74772 - /* As VM_GROWSDOWN but s/below/above/ */
74773 - if (next && next->vm_start == address + PAGE_SIZE)
74774 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74775 -
74776 - expand_upwards(vma, address + PAGE_SIZE);
74777 - }
74778 - return 0;
74779 -}
74780 -
74781 -/*
74782 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74783 * but allow concurrent faults), and pte mapped but not yet locked.
74784 * We return with mmap_sem still held, but pte unmapped and unlocked.
74785 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74786 unsigned long address, pte_t *page_table, pmd_t *pmd,
74787 unsigned int flags)
74788 {
74789 - struct page *page;
74790 + struct page *page = NULL;
74791 spinlock_t *ptl;
74792 pte_t entry;
74793
74794 - pte_unmap(page_table);
74795 -
74796 - /* Check if we need to add a guard page to the stack */
74797 - if (check_stack_guard_page(vma, address) < 0)
74798 - return VM_FAULT_SIGBUS;
74799 -
74800 - /* Use the zero-page for reads */
74801 if (!(flags & FAULT_FLAG_WRITE)) {
74802 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74803 vma->vm_page_prot));
74804 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74805 + ptl = pte_lockptr(mm, pmd);
74806 + spin_lock(ptl);
74807 if (!pte_none(*page_table))
74808 goto unlock;
74809 goto setpte;
74810 }
74811
74812 /* Allocate our own private page. */
74813 + pte_unmap(page_table);
74814 +
74815 if (unlikely(anon_vma_prepare(vma)))
74816 goto oom;
74817 page = alloc_zeroed_user_highpage_movable(vma, address);
74818 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74819 if (!pte_none(*page_table))
74820 goto release;
74821
74822 +#ifdef CONFIG_PAX_SEGMEXEC
74823 + if (pax_find_mirror_vma(vma))
74824 + BUG_ON(!trylock_page(page));
74825 +#endif
74826 +
74827 inc_mm_counter_fast(mm, MM_ANONPAGES);
74828 page_add_new_anon_rmap(page, vma, address);
74829 setpte:
74830 @@ -3181,6 +3364,12 @@ setpte:
74831
74832 /* No need to invalidate - it was non-present before */
74833 update_mmu_cache(vma, address, page_table);
74834 +
74835 +#ifdef CONFIG_PAX_SEGMEXEC
74836 + if (page)
74837 + pax_mirror_anon_pte(vma, address, page, ptl);
74838 +#endif
74839 +
74840 unlock:
74841 pte_unmap_unlock(page_table, ptl);
74842 return 0;
74843 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74844 */
74845 /* Only go through if we didn't race with anybody else... */
74846 if (likely(pte_same(*page_table, orig_pte))) {
74847 +
74848 +#ifdef CONFIG_PAX_SEGMEXEC
74849 + if (anon && pax_find_mirror_vma(vma))
74850 + BUG_ON(!trylock_page(page));
74851 +#endif
74852 +
74853 flush_icache_page(vma, page);
74854 entry = mk_pte(page, vma->vm_page_prot);
74855 if (flags & FAULT_FLAG_WRITE)
74856 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74857
74858 /* no need to invalidate: a not-present page won't be cached */
74859 update_mmu_cache(vma, address, page_table);
74860 +
74861 +#ifdef CONFIG_PAX_SEGMEXEC
74862 + if (anon)
74863 + pax_mirror_anon_pte(vma, address, page, ptl);
74864 + else
74865 + pax_mirror_file_pte(vma, address, page, ptl);
74866 +#endif
74867 +
74868 } else {
74869 if (cow_page)
74870 mem_cgroup_uncharge_page(cow_page);
74871 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
74872 if (flags & FAULT_FLAG_WRITE)
74873 flush_tlb_fix_spurious_fault(vma, address);
74874 }
74875 +
74876 +#ifdef CONFIG_PAX_SEGMEXEC
74877 + pax_mirror_pte(vma, address, pte, pmd, ptl);
74878 + return 0;
74879 +#endif
74880 +
74881 unlock:
74882 pte_unmap_unlock(pte, ptl);
74883 return 0;
74884 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74885 pmd_t *pmd;
74886 pte_t *pte;
74887
74888 +#ifdef CONFIG_PAX_SEGMEXEC
74889 + struct vm_area_struct *vma_m;
74890 +#endif
74891 +
74892 __set_current_state(TASK_RUNNING);
74893
74894 count_vm_event(PGFAULT);
74895 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74896 if (unlikely(is_vm_hugetlb_page(vma)))
74897 return hugetlb_fault(mm, vma, address, flags);
74898
74899 +#ifdef CONFIG_PAX_SEGMEXEC
74900 + vma_m = pax_find_mirror_vma(vma);
74901 + if (vma_m) {
74902 + unsigned long address_m;
74903 + pgd_t *pgd_m;
74904 + pud_t *pud_m;
74905 + pmd_t *pmd_m;
74906 +
74907 + if (vma->vm_start > vma_m->vm_start) {
74908 + address_m = address;
74909 + address -= SEGMEXEC_TASK_SIZE;
74910 + vma = vma_m;
74911 + } else
74912 + address_m = address + SEGMEXEC_TASK_SIZE;
74913 +
74914 + pgd_m = pgd_offset(mm, address_m);
74915 + pud_m = pud_alloc(mm, pgd_m, address_m);
74916 + if (!pud_m)
74917 + return VM_FAULT_OOM;
74918 + pmd_m = pmd_alloc(mm, pud_m, address_m);
74919 + if (!pmd_m)
74920 + return VM_FAULT_OOM;
74921 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
74922 + return VM_FAULT_OOM;
74923 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
74924 + }
74925 +#endif
74926 +
74927 retry:
74928 pgd = pgd_offset(mm, address);
74929 pud = pud_alloc(mm, pgd, address);
74930 @@ -3565,7 +3806,7 @@ retry:
74931 * run pte_offset_map on the pmd, if an huge pmd could
74932 * materialize from under us from a different thread.
74933 */
74934 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
74935 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74936 return VM_FAULT_OOM;
74937 /* if an huge pmd materialized from under us just retry later */
74938 if (unlikely(pmd_trans_huge(*pmd)))
74939 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74940 spin_unlock(&mm->page_table_lock);
74941 return 0;
74942 }
74943 +
74944 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74945 +{
74946 + pud_t *new = pud_alloc_one(mm, address);
74947 + if (!new)
74948 + return -ENOMEM;
74949 +
74950 + smp_wmb(); /* See comment in __pte_alloc */
74951 +
74952 + spin_lock(&mm->page_table_lock);
74953 + if (pgd_present(*pgd)) /* Another has populated it */
74954 + pud_free(mm, new);
74955 + else
74956 + pgd_populate_kernel(mm, pgd, new);
74957 + spin_unlock(&mm->page_table_lock);
74958 + return 0;
74959 +}
74960 #endif /* __PAGETABLE_PUD_FOLDED */
74961
74962 #ifndef __PAGETABLE_PMD_FOLDED
74963 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74964 spin_unlock(&mm->page_table_lock);
74965 return 0;
74966 }
74967 +
74968 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74969 +{
74970 + pmd_t *new = pmd_alloc_one(mm, address);
74971 + if (!new)
74972 + return -ENOMEM;
74973 +
74974 + smp_wmb(); /* See comment in __pte_alloc */
74975 +
74976 + spin_lock(&mm->page_table_lock);
74977 +#ifndef __ARCH_HAS_4LEVEL_HACK
74978 + if (pud_present(*pud)) /* Another has populated it */
74979 + pmd_free(mm, new);
74980 + else
74981 + pud_populate_kernel(mm, pud, new);
74982 +#else
74983 + if (pgd_present(*pud)) /* Another has populated it */
74984 + pmd_free(mm, new);
74985 + else
74986 + pgd_populate_kernel(mm, pud, new);
74987 +#endif /* __ARCH_HAS_4LEVEL_HACK */
74988 + spin_unlock(&mm->page_table_lock);
74989 + return 0;
74990 +}
74991 #endif /* __PAGETABLE_PMD_FOLDED */
74992
74993 int make_pages_present(unsigned long addr, unsigned long end)
74994 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
74995 gate_vma.vm_start = FIXADDR_USER_START;
74996 gate_vma.vm_end = FIXADDR_USER_END;
74997 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
74998 - gate_vma.vm_page_prot = __P101;
74999 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75000
75001 return 0;
75002 }
75003 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75004 index 002c281..9429765 100644
75005 --- a/mm/mempolicy.c
75006 +++ b/mm/mempolicy.c
75007 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75008 unsigned long vmstart;
75009 unsigned long vmend;
75010
75011 +#ifdef CONFIG_PAX_SEGMEXEC
75012 + struct vm_area_struct *vma_m;
75013 +#endif
75014 +
75015 vma = find_vma(mm, start);
75016 if (!vma || vma->vm_start > start)
75017 return -EFAULT;
75018 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75019 if (err)
75020 goto out;
75021 }
75022 +
75023 err = vma_replace_policy(vma, new_pol);
75024 if (err)
75025 goto out;
75026 +
75027 +#ifdef CONFIG_PAX_SEGMEXEC
75028 + vma_m = pax_find_mirror_vma(vma);
75029 + if (vma_m) {
75030 + err = vma_replace_policy(vma_m, new_pol);
75031 + if (err)
75032 + goto out;
75033 + }
75034 +#endif
75035 +
75036 }
75037
75038 out:
75039 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75040
75041 if (end < start)
75042 return -EINVAL;
75043 +
75044 +#ifdef CONFIG_PAX_SEGMEXEC
75045 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75046 + if (end > SEGMEXEC_TASK_SIZE)
75047 + return -EINVAL;
75048 + } else
75049 +#endif
75050 +
75051 + if (end > TASK_SIZE)
75052 + return -EINVAL;
75053 +
75054 if (end == start)
75055 return 0;
75056
75057 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75058 */
75059 tcred = __task_cred(task);
75060 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75061 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75062 - !capable(CAP_SYS_NICE)) {
75063 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75064 rcu_read_unlock();
75065 err = -EPERM;
75066 goto out_put;
75067 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75068 goto out;
75069 }
75070
75071 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75072 + if (mm != current->mm &&
75073 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75074 + mmput(mm);
75075 + err = -EPERM;
75076 + goto out;
75077 + }
75078 +#endif
75079 +
75080 err = do_migrate_pages(mm, old, new,
75081 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75082
75083 diff --git a/mm/migrate.c b/mm/migrate.c
75084 index 346d32d..d7adff2 100644
75085 --- a/mm/migrate.c
75086 +++ b/mm/migrate.c
75087 @@ -1352,8 +1352,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75088 */
75089 tcred = __task_cred(task);
75090 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75091 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75092 - !capable(CAP_SYS_NICE)) {
75093 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75094 rcu_read_unlock();
75095 err = -EPERM;
75096 goto out;
75097 diff --git a/mm/mlock.c b/mm/mlock.c
75098 index c9bd528..da8d069 100644
75099 --- a/mm/mlock.c
75100 +++ b/mm/mlock.c
75101 @@ -13,6 +13,7 @@
75102 #include <linux/pagemap.h>
75103 #include <linux/mempolicy.h>
75104 #include <linux/syscalls.h>
75105 +#include <linux/security.h>
75106 #include <linux/sched.h>
75107 #include <linux/export.h>
75108 #include <linux/rmap.h>
75109 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75110 {
75111 unsigned long nstart, end, tmp;
75112 struct vm_area_struct * vma, * prev;
75113 - int error;
75114 + int error = 0;
75115
75116 VM_BUG_ON(start & ~PAGE_MASK);
75117 VM_BUG_ON(len != PAGE_ALIGN(len));
75118 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75119 return -EINVAL;
75120 if (end == start)
75121 return 0;
75122 + if (end > TASK_SIZE)
75123 + return -EINVAL;
75124 +
75125 vma = find_vma(current->mm, start);
75126 if (!vma || vma->vm_start > start)
75127 return -ENOMEM;
75128 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75129 for (nstart = start ; ; ) {
75130 vm_flags_t newflags;
75131
75132 +#ifdef CONFIG_PAX_SEGMEXEC
75133 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75134 + break;
75135 +#endif
75136 +
75137 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75138
75139 newflags = vma->vm_flags | VM_LOCKED;
75140 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75141 lock_limit >>= PAGE_SHIFT;
75142
75143 /* check against resource limits */
75144 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75145 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75146 error = do_mlock(start, len, 1);
75147 up_write(&current->mm->mmap_sem);
75148 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
75149 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75150 vm_flags_t newflags;
75151
75152 +#ifdef CONFIG_PAX_SEGMEXEC
75153 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75154 + break;
75155 +#endif
75156 +
75157 + BUG_ON(vma->vm_end > TASK_SIZE);
75158 newflags = vma->vm_flags | VM_LOCKED;
75159 if (!(flags & MCL_CURRENT))
75160 newflags &= ~VM_LOCKED;
75161 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75162 lock_limit >>= PAGE_SHIFT;
75163
75164 ret = -ENOMEM;
75165 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75166 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75167 capable(CAP_IPC_LOCK))
75168 ret = do_mlockall(flags);
75169 diff --git a/mm/mmap.c b/mm/mmap.c
75170 index 9a796c4..e2c9724 100644
75171 --- a/mm/mmap.c
75172 +++ b/mm/mmap.c
75173 @@ -31,6 +31,7 @@
75174 #include <linux/audit.h>
75175 #include <linux/khugepaged.h>
75176 #include <linux/uprobes.h>
75177 +#include <linux/random.h>
75178
75179 #include <asm/uaccess.h>
75180 #include <asm/cacheflush.h>
75181 @@ -47,6 +48,16 @@
75182 #define arch_rebalance_pgtables(addr, len) (addr)
75183 #endif
75184
75185 +static inline void verify_mm_writelocked(struct mm_struct *mm)
75186 +{
75187 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75188 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75189 + up_read(&mm->mmap_sem);
75190 + BUG();
75191 + }
75192 +#endif
75193 +}
75194 +
75195 static void unmap_region(struct mm_struct *mm,
75196 struct vm_area_struct *vma, struct vm_area_struct *prev,
75197 unsigned long start, unsigned long end);
75198 @@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75199 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75200 *
75201 */
75202 -pgprot_t protection_map[16] = {
75203 +pgprot_t protection_map[16] __read_only = {
75204 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75205 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75206 };
75207
75208 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
75209 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75210 {
75211 - return __pgprot(pgprot_val(protection_map[vm_flags &
75212 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75213 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75214 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75215 +
75216 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75217 + if (!(__supported_pte_mask & _PAGE_NX) &&
75218 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75219 + (vm_flags & (VM_READ | VM_WRITE)))
75220 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75221 +#endif
75222 +
75223 + return prot;
75224 }
75225 EXPORT_SYMBOL(vm_get_page_prot);
75226
75227 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75228 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75229 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75230 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75231 /*
75232 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75233 * other variables. It can be updated by several CPUs frequently.
75234 @@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75235 struct vm_area_struct *next = vma->vm_next;
75236
75237 might_sleep();
75238 + BUG_ON(vma->vm_mirror);
75239 if (vma->vm_ops && vma->vm_ops->close)
75240 vma->vm_ops->close(vma);
75241 if (vma->vm_file)
75242 @@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75243 * not page aligned -Ram Gupta
75244 */
75245 rlim = rlimit(RLIMIT_DATA);
75246 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75247 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75248 (mm->end_data - mm->start_data) > rlim)
75249 goto out;
75250 @@ -736,6 +759,12 @@ static int
75251 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75252 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75253 {
75254 +
75255 +#ifdef CONFIG_PAX_SEGMEXEC
75256 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75257 + return 0;
75258 +#endif
75259 +
75260 if (is_mergeable_vma(vma, file, vm_flags) &&
75261 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75262 if (vma->vm_pgoff == vm_pgoff)
75263 @@ -755,6 +784,12 @@ static int
75264 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75265 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75266 {
75267 +
75268 +#ifdef CONFIG_PAX_SEGMEXEC
75269 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75270 + return 0;
75271 +#endif
75272 +
75273 if (is_mergeable_vma(vma, file, vm_flags) &&
75274 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75275 pgoff_t vm_pglen;
75276 @@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75277 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75278 struct vm_area_struct *prev, unsigned long addr,
75279 unsigned long end, unsigned long vm_flags,
75280 - struct anon_vma *anon_vma, struct file *file,
75281 + struct anon_vma *anon_vma, struct file *file,
75282 pgoff_t pgoff, struct mempolicy *policy)
75283 {
75284 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75285 struct vm_area_struct *area, *next;
75286 int err;
75287
75288 +#ifdef CONFIG_PAX_SEGMEXEC
75289 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75290 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75291 +
75292 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75293 +#endif
75294 +
75295 /*
75296 * We later require that vma->vm_flags == vm_flags,
75297 * so this tests vma->vm_flags & VM_SPECIAL, too.
75298 @@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75299 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75300 next = next->vm_next;
75301
75302 +#ifdef CONFIG_PAX_SEGMEXEC
75303 + if (prev)
75304 + prev_m = pax_find_mirror_vma(prev);
75305 + if (area)
75306 + area_m = pax_find_mirror_vma(area);
75307 + if (next)
75308 + next_m = pax_find_mirror_vma(next);
75309 +#endif
75310 +
75311 /*
75312 * Can it merge with the predecessor?
75313 */
75314 @@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75315 /* cases 1, 6 */
75316 err = vma_adjust(prev, prev->vm_start,
75317 next->vm_end, prev->vm_pgoff, NULL);
75318 - } else /* cases 2, 5, 7 */
75319 +
75320 +#ifdef CONFIG_PAX_SEGMEXEC
75321 + if (!err && prev_m)
75322 + err = vma_adjust(prev_m, prev_m->vm_start,
75323 + next_m->vm_end, prev_m->vm_pgoff, NULL);
75324 +#endif
75325 +
75326 + } else { /* cases 2, 5, 7 */
75327 err = vma_adjust(prev, prev->vm_start,
75328 end, prev->vm_pgoff, NULL);
75329 +
75330 +#ifdef CONFIG_PAX_SEGMEXEC
75331 + if (!err && prev_m)
75332 + err = vma_adjust(prev_m, prev_m->vm_start,
75333 + end_m, prev_m->vm_pgoff, NULL);
75334 +#endif
75335 +
75336 + }
75337 if (err)
75338 return NULL;
75339 khugepaged_enter_vma_merge(prev);
75340 @@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75341 mpol_equal(policy, vma_policy(next)) &&
75342 can_vma_merge_before(next, vm_flags,
75343 anon_vma, file, pgoff+pglen)) {
75344 - if (prev && addr < prev->vm_end) /* case 4 */
75345 + if (prev && addr < prev->vm_end) { /* case 4 */
75346 err = vma_adjust(prev, prev->vm_start,
75347 addr, prev->vm_pgoff, NULL);
75348 - else /* cases 3, 8 */
75349 +
75350 +#ifdef CONFIG_PAX_SEGMEXEC
75351 + if (!err && prev_m)
75352 + err = vma_adjust(prev_m, prev_m->vm_start,
75353 + addr_m, prev_m->vm_pgoff, NULL);
75354 +#endif
75355 +
75356 + } else { /* cases 3, 8 */
75357 err = vma_adjust(area, addr, next->vm_end,
75358 next->vm_pgoff - pglen, NULL);
75359 +
75360 +#ifdef CONFIG_PAX_SEGMEXEC
75361 + if (!err && area_m)
75362 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
75363 + next_m->vm_pgoff - pglen, NULL);
75364 +#endif
75365 +
75366 + }
75367 if (err)
75368 return NULL;
75369 khugepaged_enter_vma_merge(area);
75370 @@ -968,16 +1049,13 @@ none:
75371 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75372 struct file *file, long pages)
75373 {
75374 - const unsigned long stack_flags
75375 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75376 -
75377 mm->total_vm += pages;
75378
75379 if (file) {
75380 mm->shared_vm += pages;
75381 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75382 mm->exec_vm += pages;
75383 - } else if (flags & stack_flags)
75384 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75385 mm->stack_vm += pages;
75386 }
75387 #endif /* CONFIG_PROC_FS */
75388 @@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75389 * (the exception is when the underlying filesystem is noexec
75390 * mounted, in which case we dont add PROT_EXEC.)
75391 */
75392 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75393 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75394 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75395 prot |= PROT_EXEC;
75396
75397 @@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75398 /* Obtain the address to map to. we verify (or select) it and ensure
75399 * that it represents a valid section of the address space.
75400 */
75401 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
75402 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75403 if (addr & ~PAGE_MASK)
75404 return addr;
75405
75406 @@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75407 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75408 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75409
75410 +#ifdef CONFIG_PAX_MPROTECT
75411 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75412 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75413 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75414 + gr_log_rwxmmap(file);
75415 +
75416 +#ifdef CONFIG_PAX_EMUPLT
75417 + vm_flags &= ~VM_EXEC;
75418 +#else
75419 + return -EPERM;
75420 +#endif
75421 +
75422 + }
75423 +
75424 + if (!(vm_flags & VM_EXEC))
75425 + vm_flags &= ~VM_MAYEXEC;
75426 +#else
75427 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75428 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75429 +#endif
75430 + else
75431 + vm_flags &= ~VM_MAYWRITE;
75432 + }
75433 +#endif
75434 +
75435 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75436 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75437 + vm_flags &= ~VM_PAGEEXEC;
75438 +#endif
75439 +
75440 if (flags & MAP_LOCKED)
75441 if (!can_do_mlock())
75442 return -EPERM;
75443 @@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75444 locked += mm->locked_vm;
75445 lock_limit = rlimit(RLIMIT_MEMLOCK);
75446 lock_limit >>= PAGE_SHIFT;
75447 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75448 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75449 return -EAGAIN;
75450 }
75451 @@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75452 }
75453 }
75454
75455 + if (!gr_acl_handle_mmap(file, prot))
75456 + return -EACCES;
75457 +
75458 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75459 }
75460
75461 @@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75462 vm_flags_t vm_flags = vma->vm_flags;
75463
75464 /* If it was private or non-writable, the write bit is already clear */
75465 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75466 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75467 return 0;
75468
75469 /* The backer wishes to know when pages are first written to? */
75470 @@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75471 unsigned long charged = 0;
75472 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75473
75474 +#ifdef CONFIG_PAX_SEGMEXEC
75475 + struct vm_area_struct *vma_m = NULL;
75476 +#endif
75477 +
75478 + /*
75479 + * mm->mmap_sem is required to protect against another thread
75480 + * changing the mappings in case we sleep.
75481 + */
75482 + verify_mm_writelocked(mm);
75483 +
75484 /* Clear old maps */
75485 error = -ENOMEM;
75486 -munmap_back:
75487 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75488 if (do_munmap(mm, addr, len))
75489 return -ENOMEM;
75490 - goto munmap_back;
75491 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75492 }
75493
75494 /* Check against address space limit. */
75495 @@ -1307,6 +1428,16 @@ munmap_back:
75496 goto unacct_error;
75497 }
75498
75499 +#ifdef CONFIG_PAX_SEGMEXEC
75500 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75501 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75502 + if (!vma_m) {
75503 + error = -ENOMEM;
75504 + goto free_vma;
75505 + }
75506 + }
75507 +#endif
75508 +
75509 vma->vm_mm = mm;
75510 vma->vm_start = addr;
75511 vma->vm_end = addr + len;
75512 @@ -1331,6 +1462,13 @@ munmap_back:
75513 if (error)
75514 goto unmap_and_free_vma;
75515
75516 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75517 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75518 + vma->vm_flags |= VM_PAGEEXEC;
75519 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75520 + }
75521 +#endif
75522 +
75523 /* Can addr have changed??
75524 *
75525 * Answer: Yes, several device drivers can do it in their
75526 @@ -1365,6 +1503,11 @@ munmap_back:
75527 vma_link(mm, vma, prev, rb_link, rb_parent);
75528 file = vma->vm_file;
75529
75530 +#ifdef CONFIG_PAX_SEGMEXEC
75531 + if (vma_m)
75532 + BUG_ON(pax_mirror_vma(vma_m, vma));
75533 +#endif
75534 +
75535 /* Once vma denies write, undo our temporary denial count */
75536 if (correct_wcount)
75537 atomic_inc(&inode->i_writecount);
75538 @@ -1372,6 +1515,7 @@ out:
75539 perf_event_mmap(vma);
75540
75541 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75542 + track_exec_limit(mm, addr, addr + len, vm_flags);
75543 if (vm_flags & VM_LOCKED) {
75544 if (!mlock_vma_pages_range(vma, addr, addr + len))
75545 mm->locked_vm += (len >> PAGE_SHIFT);
75546 @@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75547 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75548 charged = 0;
75549 free_vma:
75550 +
75551 +#ifdef CONFIG_PAX_SEGMEXEC
75552 + if (vma_m)
75553 + kmem_cache_free(vm_area_cachep, vma_m);
75554 +#endif
75555 +
75556 kmem_cache_free(vm_area_cachep, vma);
75557 unacct_error:
75558 if (charged)
75559 @@ -1400,6 +1550,62 @@ unacct_error:
75560 return error;
75561 }
75562
75563 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75564 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75565 +{
75566 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75567 + return (random32() & 0xFF) << PAGE_SHIFT;
75568 +
75569 + return 0;
75570 +}
75571 +#endif
75572 +
75573 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75574 +{
75575 + if (!vma) {
75576 +#ifdef CONFIG_STACK_GROWSUP
75577 + if (addr > sysctl_heap_stack_gap)
75578 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75579 + else
75580 + vma = find_vma(current->mm, 0);
75581 + if (vma && (vma->vm_flags & VM_GROWSUP))
75582 + return false;
75583 +#endif
75584 + return true;
75585 + }
75586 +
75587 + if (addr + len > vma->vm_start)
75588 + return false;
75589 +
75590 + if (vma->vm_flags & VM_GROWSDOWN)
75591 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75592 +#ifdef CONFIG_STACK_GROWSUP
75593 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75594 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75595 +#endif
75596 + else if (offset)
75597 + return offset <= vma->vm_start - addr - len;
75598 +
75599 + return true;
75600 +}
75601 +
75602 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75603 +{
75604 + if (vma->vm_start < len)
75605 + return -ENOMEM;
75606 +
75607 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
75608 + if (offset <= vma->vm_start - len)
75609 + return vma->vm_start - len - offset;
75610 + else
75611 + return -ENOMEM;
75612 + }
75613 +
75614 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
75615 + return vma->vm_start - len - sysctl_heap_stack_gap;
75616 + return -ENOMEM;
75617 +}
75618 +
75619 /* Get an address range which is currently unmapped.
75620 * For shmat() with addr=0.
75621 *
75622 @@ -1419,6 +1625,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75623 struct mm_struct *mm = current->mm;
75624 struct vm_area_struct *vma;
75625 unsigned long start_addr;
75626 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75627
75628 if (len > TASK_SIZE)
75629 return -ENOMEM;
75630 @@ -1426,18 +1633,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75631 if (flags & MAP_FIXED)
75632 return addr;
75633
75634 +#ifdef CONFIG_PAX_RANDMMAP
75635 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75636 +#endif
75637 +
75638 if (addr) {
75639 addr = PAGE_ALIGN(addr);
75640 - vma = find_vma(mm, addr);
75641 - if (TASK_SIZE - len >= addr &&
75642 - (!vma || addr + len <= vma->vm_start))
75643 - return addr;
75644 + if (TASK_SIZE - len >= addr) {
75645 + vma = find_vma(mm, addr);
75646 + if (check_heap_stack_gap(vma, addr, len, offset))
75647 + return addr;
75648 + }
75649 }
75650 if (len > mm->cached_hole_size) {
75651 - start_addr = addr = mm->free_area_cache;
75652 + start_addr = addr = mm->free_area_cache;
75653 } else {
75654 - start_addr = addr = TASK_UNMAPPED_BASE;
75655 - mm->cached_hole_size = 0;
75656 + start_addr = addr = mm->mmap_base;
75657 + mm->cached_hole_size = 0;
75658 }
75659
75660 full_search:
75661 @@ -1448,34 +1660,40 @@ full_search:
75662 * Start a new search - just in case we missed
75663 * some holes.
75664 */
75665 - if (start_addr != TASK_UNMAPPED_BASE) {
75666 - addr = TASK_UNMAPPED_BASE;
75667 - start_addr = addr;
75668 + if (start_addr != mm->mmap_base) {
75669 + start_addr = addr = mm->mmap_base;
75670 mm->cached_hole_size = 0;
75671 goto full_search;
75672 }
75673 return -ENOMEM;
75674 }
75675 - if (!vma || addr + len <= vma->vm_start) {
75676 - /*
75677 - * Remember the place where we stopped the search:
75678 - */
75679 - mm->free_area_cache = addr + len;
75680 - return addr;
75681 - }
75682 + if (check_heap_stack_gap(vma, addr, len, offset))
75683 + break;
75684 if (addr + mm->cached_hole_size < vma->vm_start)
75685 mm->cached_hole_size = vma->vm_start - addr;
75686 addr = vma->vm_end;
75687 }
75688 +
75689 + /*
75690 + * Remember the place where we stopped the search:
75691 + */
75692 + mm->free_area_cache = addr + len;
75693 + return addr;
75694 }
75695 #endif
75696
75697 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75698 {
75699 +
75700 +#ifdef CONFIG_PAX_SEGMEXEC
75701 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75702 + return;
75703 +#endif
75704 +
75705 /*
75706 * Is this a new hole at the lowest possible address?
75707 */
75708 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75709 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75710 mm->free_area_cache = addr;
75711 }
75712
75713 @@ -1491,7 +1709,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75714 {
75715 struct vm_area_struct *vma;
75716 struct mm_struct *mm = current->mm;
75717 - unsigned long addr = addr0, start_addr;
75718 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75719 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75720
75721 /* requested length too big for entire address space */
75722 if (len > TASK_SIZE)
75723 @@ -1500,13 +1719,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75724 if (flags & MAP_FIXED)
75725 return addr;
75726
75727 +#ifdef CONFIG_PAX_RANDMMAP
75728 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75729 +#endif
75730 +
75731 /* requesting a specific address */
75732 if (addr) {
75733 addr = PAGE_ALIGN(addr);
75734 - vma = find_vma(mm, addr);
75735 - if (TASK_SIZE - len >= addr &&
75736 - (!vma || addr + len <= vma->vm_start))
75737 - return addr;
75738 + if (TASK_SIZE - len >= addr) {
75739 + vma = find_vma(mm, addr);
75740 + if (check_heap_stack_gap(vma, addr, len, offset))
75741 + return addr;
75742 + }
75743 }
75744
75745 /* check if free_area_cache is useful for us */
75746 @@ -1530,7 +1754,7 @@ try_again:
75747 * return with success:
75748 */
75749 vma = find_vma(mm, addr);
75750 - if (!vma || addr+len <= vma->vm_start)
75751 + if (check_heap_stack_gap(vma, addr, len, offset))
75752 /* remember the address as a hint for next time */
75753 return (mm->free_area_cache = addr);
75754
75755 @@ -1539,8 +1763,8 @@ try_again:
75756 mm->cached_hole_size = vma->vm_start - addr;
75757
75758 /* try just below the current vma->vm_start */
75759 - addr = vma->vm_start-len;
75760 - } while (len < vma->vm_start);
75761 + addr = skip_heap_stack_gap(vma, len, offset);
75762 + } while (!IS_ERR_VALUE(addr));
75763
75764 fail:
75765 /*
75766 @@ -1563,13 +1787,21 @@ fail:
75767 * can happen with large stack limits and large mmap()
75768 * allocations.
75769 */
75770 + mm->mmap_base = TASK_UNMAPPED_BASE;
75771 +
75772 +#ifdef CONFIG_PAX_RANDMMAP
75773 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75774 + mm->mmap_base += mm->delta_mmap;
75775 +#endif
75776 +
75777 + mm->free_area_cache = mm->mmap_base;
75778 mm->cached_hole_size = ~0UL;
75779 - mm->free_area_cache = TASK_UNMAPPED_BASE;
75780 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75781 /*
75782 * Restore the topdown base:
75783 */
75784 - mm->free_area_cache = mm->mmap_base;
75785 + mm->mmap_base = base;
75786 + mm->free_area_cache = base;
75787 mm->cached_hole_size = ~0UL;
75788
75789 return addr;
75790 @@ -1578,6 +1810,12 @@ fail:
75791
75792 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75793 {
75794 +
75795 +#ifdef CONFIG_PAX_SEGMEXEC
75796 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75797 + return;
75798 +#endif
75799 +
75800 /*
75801 * Is this a new hole at the highest possible address?
75802 */
75803 @@ -1585,8 +1823,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75804 mm->free_area_cache = addr;
75805
75806 /* dont allow allocations above current base */
75807 - if (mm->free_area_cache > mm->mmap_base)
75808 + if (mm->free_area_cache > mm->mmap_base) {
75809 mm->free_area_cache = mm->mmap_base;
75810 + mm->cached_hole_size = ~0UL;
75811 + }
75812 }
75813
75814 unsigned long
75815 @@ -1685,6 +1925,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75816 return vma;
75817 }
75818
75819 +#ifdef CONFIG_PAX_SEGMEXEC
75820 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75821 +{
75822 + struct vm_area_struct *vma_m;
75823 +
75824 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75825 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75826 + BUG_ON(vma->vm_mirror);
75827 + return NULL;
75828 + }
75829 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75830 + vma_m = vma->vm_mirror;
75831 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75832 + BUG_ON(vma->vm_file != vma_m->vm_file);
75833 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75834 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
75835 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
75836 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
75837 + return vma_m;
75838 +}
75839 +#endif
75840 +
75841 /*
75842 * Verify that the stack growth is acceptable and
75843 * update accounting. This is shared with both the
75844 @@ -1701,6 +1963,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75845 return -ENOMEM;
75846
75847 /* Stack limit test */
75848 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
75849 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
75850 return -ENOMEM;
75851
75852 @@ -1711,6 +1974,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75853 locked = mm->locked_vm + grow;
75854 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
75855 limit >>= PAGE_SHIFT;
75856 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75857 if (locked > limit && !capable(CAP_IPC_LOCK))
75858 return -ENOMEM;
75859 }
75860 @@ -1740,37 +2004,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75861 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
75862 * vma is the last one with address > vma->vm_end. Have to extend vma.
75863 */
75864 +#ifndef CONFIG_IA64
75865 +static
75866 +#endif
75867 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75868 {
75869 int error;
75870 + bool locknext;
75871
75872 if (!(vma->vm_flags & VM_GROWSUP))
75873 return -EFAULT;
75874
75875 + /* Also guard against wrapping around to address 0. */
75876 + if (address < PAGE_ALIGN(address+1))
75877 + address = PAGE_ALIGN(address+1);
75878 + else
75879 + return -ENOMEM;
75880 +
75881 /*
75882 * We must make sure the anon_vma is allocated
75883 * so that the anon_vma locking is not a noop.
75884 */
75885 if (unlikely(anon_vma_prepare(vma)))
75886 return -ENOMEM;
75887 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
75888 + if (locknext && anon_vma_prepare(vma->vm_next))
75889 + return -ENOMEM;
75890 vma_lock_anon_vma(vma);
75891 + if (locknext)
75892 + vma_lock_anon_vma(vma->vm_next);
75893
75894 /*
75895 * vma->vm_start/vm_end cannot change under us because the caller
75896 * is required to hold the mmap_sem in read mode. We need the
75897 - * anon_vma lock to serialize against concurrent expand_stacks.
75898 - * Also guard against wrapping around to address 0.
75899 + * anon_vma locks to serialize against concurrent expand_stacks
75900 + * and expand_upwards.
75901 */
75902 - if (address < PAGE_ALIGN(address+4))
75903 - address = PAGE_ALIGN(address+4);
75904 - else {
75905 - vma_unlock_anon_vma(vma);
75906 - return -ENOMEM;
75907 - }
75908 error = 0;
75909
75910 /* Somebody else might have raced and expanded it already */
75911 - if (address > vma->vm_end) {
75912 + 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)
75913 + error = -ENOMEM;
75914 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
75915 unsigned long size, grow;
75916
75917 size = address - vma->vm_start;
75918 @@ -1787,6 +2062,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75919 }
75920 }
75921 }
75922 + if (locknext)
75923 + vma_unlock_anon_vma(vma->vm_next);
75924 vma_unlock_anon_vma(vma);
75925 khugepaged_enter_vma_merge(vma);
75926 validate_mm(vma->vm_mm);
75927 @@ -1801,6 +2078,8 @@ int expand_downwards(struct vm_area_struct *vma,
75928 unsigned long address)
75929 {
75930 int error;
75931 + bool lockprev = false;
75932 + struct vm_area_struct *prev;
75933
75934 /*
75935 * We must make sure the anon_vma is allocated
75936 @@ -1814,6 +2093,15 @@ int expand_downwards(struct vm_area_struct *vma,
75937 if (error)
75938 return error;
75939
75940 + prev = vma->vm_prev;
75941 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
75942 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
75943 +#endif
75944 + if (lockprev && anon_vma_prepare(prev))
75945 + return -ENOMEM;
75946 + if (lockprev)
75947 + vma_lock_anon_vma(prev);
75948 +
75949 vma_lock_anon_vma(vma);
75950
75951 /*
75952 @@ -1823,9 +2111,17 @@ int expand_downwards(struct vm_area_struct *vma,
75953 */
75954
75955 /* Somebody else might have raced and expanded it already */
75956 - if (address < vma->vm_start) {
75957 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
75958 + error = -ENOMEM;
75959 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
75960 unsigned long size, grow;
75961
75962 +#ifdef CONFIG_PAX_SEGMEXEC
75963 + struct vm_area_struct *vma_m;
75964 +
75965 + vma_m = pax_find_mirror_vma(vma);
75966 +#endif
75967 +
75968 size = vma->vm_end - address;
75969 grow = (vma->vm_start - address) >> PAGE_SHIFT;
75970
75971 @@ -1837,6 +2133,17 @@ int expand_downwards(struct vm_area_struct *vma,
75972 vma->vm_start = address;
75973 vma->vm_pgoff -= grow;
75974 anon_vma_interval_tree_post_update_vma(vma);
75975 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
75976 +
75977 +#ifdef CONFIG_PAX_SEGMEXEC
75978 + if (vma_m) {
75979 + anon_vma_interval_tree_pre_update_vma(vma_m);
75980 + vma_m->vm_start -= grow << PAGE_SHIFT;
75981 + vma_m->vm_pgoff -= grow;
75982 + anon_vma_interval_tree_post_update_vma(vma_m);
75983 + }
75984 +#endif
75985 +
75986 perf_event_mmap(vma);
75987 }
75988 }
75989 @@ -1914,6 +2221,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
75990 do {
75991 long nrpages = vma_pages(vma);
75992
75993 +#ifdef CONFIG_PAX_SEGMEXEC
75994 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
75995 + vma = remove_vma(vma);
75996 + continue;
75997 + }
75998 +#endif
75999 +
76000 if (vma->vm_flags & VM_ACCOUNT)
76001 nr_accounted += nrpages;
76002 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76003 @@ -1959,6 +2273,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76004 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76005 vma->vm_prev = NULL;
76006 do {
76007 +
76008 +#ifdef CONFIG_PAX_SEGMEXEC
76009 + if (vma->vm_mirror) {
76010 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76011 + vma->vm_mirror->vm_mirror = NULL;
76012 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
76013 + vma->vm_mirror = NULL;
76014 + }
76015 +#endif
76016 +
76017 rb_erase(&vma->vm_rb, &mm->mm_rb);
76018 mm->map_count--;
76019 tail_vma = vma;
76020 @@ -1987,14 +2311,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76021 struct vm_area_struct *new;
76022 int err = -ENOMEM;
76023
76024 +#ifdef CONFIG_PAX_SEGMEXEC
76025 + struct vm_area_struct *vma_m, *new_m = NULL;
76026 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76027 +#endif
76028 +
76029 if (is_vm_hugetlb_page(vma) && (addr &
76030 ~(huge_page_mask(hstate_vma(vma)))))
76031 return -EINVAL;
76032
76033 +#ifdef CONFIG_PAX_SEGMEXEC
76034 + vma_m = pax_find_mirror_vma(vma);
76035 +#endif
76036 +
76037 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76038 if (!new)
76039 goto out_err;
76040
76041 +#ifdef CONFIG_PAX_SEGMEXEC
76042 + if (vma_m) {
76043 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76044 + if (!new_m) {
76045 + kmem_cache_free(vm_area_cachep, new);
76046 + goto out_err;
76047 + }
76048 + }
76049 +#endif
76050 +
76051 /* most fields are the same, copy all, and then fixup */
76052 *new = *vma;
76053
76054 @@ -2007,6 +2350,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76055 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76056 }
76057
76058 +#ifdef CONFIG_PAX_SEGMEXEC
76059 + if (vma_m) {
76060 + *new_m = *vma_m;
76061 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
76062 + new_m->vm_mirror = new;
76063 + new->vm_mirror = new_m;
76064 +
76065 + if (new_below)
76066 + new_m->vm_end = addr_m;
76067 + else {
76068 + new_m->vm_start = addr_m;
76069 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76070 + }
76071 + }
76072 +#endif
76073 +
76074 pol = mpol_dup(vma_policy(vma));
76075 if (IS_ERR(pol)) {
76076 err = PTR_ERR(pol);
76077 @@ -2029,6 +2388,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76078 else
76079 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76080
76081 +#ifdef CONFIG_PAX_SEGMEXEC
76082 + if (!err && vma_m) {
76083 + if (anon_vma_clone(new_m, vma_m))
76084 + goto out_free_mpol;
76085 +
76086 + mpol_get(pol);
76087 + vma_set_policy(new_m, pol);
76088 +
76089 + if (new_m->vm_file)
76090 + get_file(new_m->vm_file);
76091 +
76092 + if (new_m->vm_ops && new_m->vm_ops->open)
76093 + new_m->vm_ops->open(new_m);
76094 +
76095 + if (new_below)
76096 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76097 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76098 + else
76099 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76100 +
76101 + if (err) {
76102 + if (new_m->vm_ops && new_m->vm_ops->close)
76103 + new_m->vm_ops->close(new_m);
76104 + if (new_m->vm_file)
76105 + fput(new_m->vm_file);
76106 + mpol_put(pol);
76107 + }
76108 + }
76109 +#endif
76110 +
76111 /* Success. */
76112 if (!err)
76113 return 0;
76114 @@ -2038,10 +2427,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76115 new->vm_ops->close(new);
76116 if (new->vm_file)
76117 fput(new->vm_file);
76118 - unlink_anon_vmas(new);
76119 out_free_mpol:
76120 mpol_put(pol);
76121 out_free_vma:
76122 +
76123 +#ifdef CONFIG_PAX_SEGMEXEC
76124 + if (new_m) {
76125 + unlink_anon_vmas(new_m);
76126 + kmem_cache_free(vm_area_cachep, new_m);
76127 + }
76128 +#endif
76129 +
76130 + unlink_anon_vmas(new);
76131 kmem_cache_free(vm_area_cachep, new);
76132 out_err:
76133 return err;
76134 @@ -2054,6 +2451,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76135 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76136 unsigned long addr, int new_below)
76137 {
76138 +
76139 +#ifdef CONFIG_PAX_SEGMEXEC
76140 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76141 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76142 + if (mm->map_count >= sysctl_max_map_count-1)
76143 + return -ENOMEM;
76144 + } else
76145 +#endif
76146 +
76147 if (mm->map_count >= sysctl_max_map_count)
76148 return -ENOMEM;
76149
76150 @@ -2065,11 +2471,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76151 * work. This now handles partial unmappings.
76152 * Jeremy Fitzhardinge <jeremy@goop.org>
76153 */
76154 +#ifdef CONFIG_PAX_SEGMEXEC
76155 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76156 {
76157 + int ret = __do_munmap(mm, start, len);
76158 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76159 + return ret;
76160 +
76161 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76162 +}
76163 +
76164 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76165 +#else
76166 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76167 +#endif
76168 +{
76169 unsigned long end;
76170 struct vm_area_struct *vma, *prev, *last;
76171
76172 + /*
76173 + * mm->mmap_sem is required to protect against another thread
76174 + * changing the mappings in case we sleep.
76175 + */
76176 + verify_mm_writelocked(mm);
76177 +
76178 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76179 return -EINVAL;
76180
76181 @@ -2144,6 +2569,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76182 /* Fix up all other VM information */
76183 remove_vma_list(mm, vma);
76184
76185 + track_exec_limit(mm, start, end, 0UL);
76186 +
76187 return 0;
76188 }
76189
76190 @@ -2152,6 +2579,13 @@ int vm_munmap(unsigned long start, size_t len)
76191 int ret;
76192 struct mm_struct *mm = current->mm;
76193
76194 +
76195 +#ifdef CONFIG_PAX_SEGMEXEC
76196 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76197 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76198 + return -EINVAL;
76199 +#endif
76200 +
76201 down_write(&mm->mmap_sem);
76202 ret = do_munmap(mm, start, len);
76203 up_write(&mm->mmap_sem);
76204 @@ -2165,16 +2599,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76205 return vm_munmap(addr, len);
76206 }
76207
76208 -static inline void verify_mm_writelocked(struct mm_struct *mm)
76209 -{
76210 -#ifdef CONFIG_DEBUG_VM
76211 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76212 - WARN_ON(1);
76213 - up_read(&mm->mmap_sem);
76214 - }
76215 -#endif
76216 -}
76217 -
76218 /*
76219 * this is really a simplified "do_mmap". it only handles
76220 * anonymous maps. eventually we may be able to do some
76221 @@ -2188,6 +2612,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76222 struct rb_node ** rb_link, * rb_parent;
76223 pgoff_t pgoff = addr >> PAGE_SHIFT;
76224 int error;
76225 + unsigned long charged;
76226
76227 len = PAGE_ALIGN(len);
76228 if (!len)
76229 @@ -2195,16 +2620,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76230
76231 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76232
76233 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76234 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76235 + flags &= ~VM_EXEC;
76236 +
76237 +#ifdef CONFIG_PAX_MPROTECT
76238 + if (mm->pax_flags & MF_PAX_MPROTECT)
76239 + flags &= ~VM_MAYEXEC;
76240 +#endif
76241 +
76242 + }
76243 +#endif
76244 +
76245 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76246 if (error & ~PAGE_MASK)
76247 return error;
76248
76249 + charged = len >> PAGE_SHIFT;
76250 +
76251 /*
76252 * mlock MCL_FUTURE?
76253 */
76254 if (mm->def_flags & VM_LOCKED) {
76255 unsigned long locked, lock_limit;
76256 - locked = len >> PAGE_SHIFT;
76257 + locked = charged;
76258 locked += mm->locked_vm;
76259 lock_limit = rlimit(RLIMIT_MEMLOCK);
76260 lock_limit >>= PAGE_SHIFT;
76261 @@ -2221,21 +2660,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76262 /*
76263 * Clear old maps. this also does some error checking for us
76264 */
76265 - munmap_back:
76266 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76267 if (do_munmap(mm, addr, len))
76268 return -ENOMEM;
76269 - goto munmap_back;
76270 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76271 }
76272
76273 /* Check against address space limits *after* clearing old maps... */
76274 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76275 + if (!may_expand_vm(mm, charged))
76276 return -ENOMEM;
76277
76278 if (mm->map_count > sysctl_max_map_count)
76279 return -ENOMEM;
76280
76281 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76282 + if (security_vm_enough_memory_mm(mm, charged))
76283 return -ENOMEM;
76284
76285 /* Can we just expand an old private anonymous mapping? */
76286 @@ -2249,7 +2687,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76287 */
76288 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76289 if (!vma) {
76290 - vm_unacct_memory(len >> PAGE_SHIFT);
76291 + vm_unacct_memory(charged);
76292 return -ENOMEM;
76293 }
76294
76295 @@ -2263,11 +2701,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76296 vma_link(mm, vma, prev, rb_link, rb_parent);
76297 out:
76298 perf_event_mmap(vma);
76299 - mm->total_vm += len >> PAGE_SHIFT;
76300 + mm->total_vm += charged;
76301 if (flags & VM_LOCKED) {
76302 if (!mlock_vma_pages_range(vma, addr, addr + len))
76303 - mm->locked_vm += (len >> PAGE_SHIFT);
76304 + mm->locked_vm += charged;
76305 }
76306 + track_exec_limit(mm, addr, addr + len, flags);
76307 return addr;
76308 }
76309
76310 @@ -2325,6 +2764,7 @@ void exit_mmap(struct mm_struct *mm)
76311 while (vma) {
76312 if (vma->vm_flags & VM_ACCOUNT)
76313 nr_accounted += vma_pages(vma);
76314 + vma->vm_mirror = NULL;
76315 vma = remove_vma(vma);
76316 }
76317 vm_unacct_memory(nr_accounted);
76318 @@ -2341,6 +2781,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76319 struct vm_area_struct *prev;
76320 struct rb_node **rb_link, *rb_parent;
76321
76322 +#ifdef CONFIG_PAX_SEGMEXEC
76323 + struct vm_area_struct *vma_m = NULL;
76324 +#endif
76325 +
76326 + if (security_mmap_addr(vma->vm_start))
76327 + return -EPERM;
76328 +
76329 /*
76330 * The vm_pgoff of a purely anonymous vma should be irrelevant
76331 * until its first write fault, when page's anon_vma and index
76332 @@ -2364,7 +2811,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76333 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76334 return -ENOMEM;
76335
76336 +#ifdef CONFIG_PAX_SEGMEXEC
76337 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76338 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76339 + if (!vma_m)
76340 + return -ENOMEM;
76341 + }
76342 +#endif
76343 +
76344 vma_link(mm, vma, prev, rb_link, rb_parent);
76345 +
76346 +#ifdef CONFIG_PAX_SEGMEXEC
76347 + if (vma_m)
76348 + BUG_ON(pax_mirror_vma(vma_m, vma));
76349 +#endif
76350 +
76351 return 0;
76352 }
76353
76354 @@ -2384,6 +2845,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76355 struct mempolicy *pol;
76356 bool faulted_in_anon_vma = true;
76357
76358 + BUG_ON(vma->vm_mirror);
76359 +
76360 /*
76361 * If anonymous vma has not yet been faulted, update new pgoff
76362 * to match new location, to increase its chance of merging.
76363 @@ -2450,6 +2913,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76364 return NULL;
76365 }
76366
76367 +#ifdef CONFIG_PAX_SEGMEXEC
76368 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76369 +{
76370 + struct vm_area_struct *prev_m;
76371 + struct rb_node **rb_link_m, *rb_parent_m;
76372 + struct mempolicy *pol_m;
76373 +
76374 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76375 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76376 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76377 + *vma_m = *vma;
76378 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76379 + if (anon_vma_clone(vma_m, vma))
76380 + return -ENOMEM;
76381 + pol_m = vma_policy(vma_m);
76382 + mpol_get(pol_m);
76383 + vma_set_policy(vma_m, pol_m);
76384 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76385 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76386 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76387 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76388 + if (vma_m->vm_file)
76389 + get_file(vma_m->vm_file);
76390 + if (vma_m->vm_ops && vma_m->vm_ops->open)
76391 + vma_m->vm_ops->open(vma_m);
76392 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76393 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76394 + vma_m->vm_mirror = vma;
76395 + vma->vm_mirror = vma_m;
76396 + return 0;
76397 +}
76398 +#endif
76399 +
76400 /*
76401 * Return true if the calling process may expand its vm space by the passed
76402 * number of pages
76403 @@ -2461,6 +2957,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76404
76405 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76406
76407 +#ifdef CONFIG_PAX_RANDMMAP
76408 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76409 + cur -= mm->brk_gap;
76410 +#endif
76411 +
76412 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76413 if (cur + npages > lim)
76414 return 0;
76415 return 1;
76416 @@ -2531,6 +3033,22 @@ int install_special_mapping(struct mm_struct *mm,
76417 vma->vm_start = addr;
76418 vma->vm_end = addr + len;
76419
76420 +#ifdef CONFIG_PAX_MPROTECT
76421 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76422 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76423 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76424 + return -EPERM;
76425 + if (!(vm_flags & VM_EXEC))
76426 + vm_flags &= ~VM_MAYEXEC;
76427 +#else
76428 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76429 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76430 +#endif
76431 + else
76432 + vm_flags &= ~VM_MAYWRITE;
76433 + }
76434 +#endif
76435 +
76436 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76437 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76438
76439 diff --git a/mm/mprotect.c b/mm/mprotect.c
76440 index a409926..8b32e6d 100644
76441 --- a/mm/mprotect.c
76442 +++ b/mm/mprotect.c
76443 @@ -23,10 +23,17 @@
76444 #include <linux/mmu_notifier.h>
76445 #include <linux/migrate.h>
76446 #include <linux/perf_event.h>
76447 +
76448 +#ifdef CONFIG_PAX_MPROTECT
76449 +#include <linux/elf.h>
76450 +#include <linux/binfmts.h>
76451 +#endif
76452 +
76453 #include <asm/uaccess.h>
76454 #include <asm/pgtable.h>
76455 #include <asm/cacheflush.h>
76456 #include <asm/tlbflush.h>
76457 +#include <asm/mmu_context.h>
76458
76459 #ifndef pgprot_modify
76460 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76461 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76462 flush_tlb_range(vma, start, end);
76463 }
76464
76465 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76466 +/* called while holding the mmap semaphor for writing except stack expansion */
76467 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76468 +{
76469 + unsigned long oldlimit, newlimit = 0UL;
76470 +
76471 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76472 + return;
76473 +
76474 + spin_lock(&mm->page_table_lock);
76475 + oldlimit = mm->context.user_cs_limit;
76476 + if ((prot & VM_EXEC) && oldlimit < end)
76477 + /* USER_CS limit moved up */
76478 + newlimit = end;
76479 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76480 + /* USER_CS limit moved down */
76481 + newlimit = start;
76482 +
76483 + if (newlimit) {
76484 + mm->context.user_cs_limit = newlimit;
76485 +
76486 +#ifdef CONFIG_SMP
76487 + wmb();
76488 + cpus_clear(mm->context.cpu_user_cs_mask);
76489 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76490 +#endif
76491 +
76492 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76493 + }
76494 + spin_unlock(&mm->page_table_lock);
76495 + if (newlimit == end) {
76496 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
76497 +
76498 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
76499 + if (is_vm_hugetlb_page(vma))
76500 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76501 + else
76502 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76503 + }
76504 +}
76505 +#endif
76506 +
76507 int
76508 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76509 unsigned long start, unsigned long end, unsigned long newflags)
76510 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76511 int error;
76512 int dirty_accountable = 0;
76513
76514 +#ifdef CONFIG_PAX_SEGMEXEC
76515 + struct vm_area_struct *vma_m = NULL;
76516 + unsigned long start_m, end_m;
76517 +
76518 + start_m = start + SEGMEXEC_TASK_SIZE;
76519 + end_m = end + SEGMEXEC_TASK_SIZE;
76520 +#endif
76521 +
76522 if (newflags == oldflags) {
76523 *pprev = vma;
76524 return 0;
76525 }
76526
76527 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76528 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76529 +
76530 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76531 + return -ENOMEM;
76532 +
76533 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76534 + return -ENOMEM;
76535 + }
76536 +
76537 /*
76538 * If we make a private mapping writable we increase our commit;
76539 * but (without finer accounting) cannot reduce our commit if we
76540 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76541 }
76542 }
76543
76544 +#ifdef CONFIG_PAX_SEGMEXEC
76545 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76546 + if (start != vma->vm_start) {
76547 + error = split_vma(mm, vma, start, 1);
76548 + if (error)
76549 + goto fail;
76550 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76551 + *pprev = (*pprev)->vm_next;
76552 + }
76553 +
76554 + if (end != vma->vm_end) {
76555 + error = split_vma(mm, vma, end, 0);
76556 + if (error)
76557 + goto fail;
76558 + }
76559 +
76560 + if (pax_find_mirror_vma(vma)) {
76561 + error = __do_munmap(mm, start_m, end_m - start_m);
76562 + if (error)
76563 + goto fail;
76564 + } else {
76565 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76566 + if (!vma_m) {
76567 + error = -ENOMEM;
76568 + goto fail;
76569 + }
76570 + vma->vm_flags = newflags;
76571 + error = pax_mirror_vma(vma_m, vma);
76572 + if (error) {
76573 + vma->vm_flags = oldflags;
76574 + goto fail;
76575 + }
76576 + }
76577 + }
76578 +#endif
76579 +
76580 /*
76581 * First try to merge with previous and/or next vma.
76582 */
76583 @@ -204,9 +307,21 @@ success:
76584 * vm_flags and vm_page_prot are protected by the mmap_sem
76585 * held in write mode.
76586 */
76587 +
76588 +#ifdef CONFIG_PAX_SEGMEXEC
76589 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76590 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76591 +#endif
76592 +
76593 vma->vm_flags = newflags;
76594 +
76595 +#ifdef CONFIG_PAX_MPROTECT
76596 + if (mm->binfmt && mm->binfmt->handle_mprotect)
76597 + mm->binfmt->handle_mprotect(vma, newflags);
76598 +#endif
76599 +
76600 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76601 - vm_get_page_prot(newflags));
76602 + vm_get_page_prot(vma->vm_flags));
76603
76604 if (vma_wants_writenotify(vma)) {
76605 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76606 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76607 end = start + len;
76608 if (end <= start)
76609 return -ENOMEM;
76610 +
76611 +#ifdef CONFIG_PAX_SEGMEXEC
76612 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76613 + if (end > SEGMEXEC_TASK_SIZE)
76614 + return -EINVAL;
76615 + } else
76616 +#endif
76617 +
76618 + if (end > TASK_SIZE)
76619 + return -EINVAL;
76620 +
76621 if (!arch_validate_prot(prot))
76622 return -EINVAL;
76623
76624 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76625 /*
76626 * Does the application expect PROT_READ to imply PROT_EXEC:
76627 */
76628 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76629 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76630 prot |= PROT_EXEC;
76631
76632 vm_flags = calc_vm_prot_bits(prot);
76633 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76634 if (start > vma->vm_start)
76635 prev = vma;
76636
76637 +#ifdef CONFIG_PAX_MPROTECT
76638 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76639 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
76640 +#endif
76641 +
76642 for (nstart = start ; ; ) {
76643 unsigned long newflags;
76644
76645 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76646
76647 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76648 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76649 + if (prot & (PROT_WRITE | PROT_EXEC))
76650 + gr_log_rwxmprotect(vma->vm_file);
76651 +
76652 + error = -EACCES;
76653 + goto out;
76654 + }
76655 +
76656 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76657 error = -EACCES;
76658 goto out;
76659 }
76660 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76661 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76662 if (error)
76663 goto out;
76664 +
76665 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76666 +
76667 nstart = tmp;
76668
76669 if (nstart < prev->vm_end)
76670 diff --git a/mm/mremap.c b/mm/mremap.c
76671 index 1b61c2d..1cc0e3c 100644
76672 --- a/mm/mremap.c
76673 +++ b/mm/mremap.c
76674 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76675 continue;
76676 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76677 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76678 +
76679 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76680 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76681 + pte = pte_exprotect(pte);
76682 +#endif
76683 +
76684 set_pte_at(mm, new_addr, new_pte, pte);
76685 }
76686
76687 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76688 if (is_vm_hugetlb_page(vma))
76689 goto Einval;
76690
76691 +#ifdef CONFIG_PAX_SEGMEXEC
76692 + if (pax_find_mirror_vma(vma))
76693 + goto Einval;
76694 +#endif
76695 +
76696 /* We can't remap across vm area boundaries */
76697 if (old_len > vma->vm_end - addr)
76698 goto Efault;
76699 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76700 unsigned long ret = -EINVAL;
76701 unsigned long charged = 0;
76702 unsigned long map_flags;
76703 + unsigned long pax_task_size = TASK_SIZE;
76704
76705 if (new_addr & ~PAGE_MASK)
76706 goto out;
76707
76708 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76709 +#ifdef CONFIG_PAX_SEGMEXEC
76710 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76711 + pax_task_size = SEGMEXEC_TASK_SIZE;
76712 +#endif
76713 +
76714 + pax_task_size -= PAGE_SIZE;
76715 +
76716 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76717 goto out;
76718
76719 /* Check if the location we're moving into overlaps the
76720 * old location at all, and fail if it does.
76721 */
76722 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76723 - goto out;
76724 -
76725 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76726 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76727 goto out;
76728
76729 ret = do_munmap(mm, new_addr, new_len);
76730 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76731 struct vm_area_struct *vma;
76732 unsigned long ret = -EINVAL;
76733 unsigned long charged = 0;
76734 + unsigned long pax_task_size = TASK_SIZE;
76735
76736 down_write(&current->mm->mmap_sem);
76737
76738 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76739 if (!new_len)
76740 goto out;
76741
76742 +#ifdef CONFIG_PAX_SEGMEXEC
76743 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76744 + pax_task_size = SEGMEXEC_TASK_SIZE;
76745 +#endif
76746 +
76747 + pax_task_size -= PAGE_SIZE;
76748 +
76749 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76750 + old_len > pax_task_size || addr > pax_task_size-old_len)
76751 + goto out;
76752 +
76753 if (flags & MREMAP_FIXED) {
76754 if (flags & MREMAP_MAYMOVE)
76755 ret = mremap_to(addr, old_len, new_addr, new_len);
76756 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76757 addr + new_len);
76758 }
76759 ret = addr;
76760 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76761 goto out;
76762 }
76763 }
76764 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76765 goto out;
76766 }
76767
76768 + map_flags = vma->vm_flags;
76769 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76770 + if (!(ret & ~PAGE_MASK)) {
76771 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76772 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76773 + }
76774 }
76775 out:
76776 if (ret & ~PAGE_MASK)
76777 diff --git a/mm/nommu.c b/mm/nommu.c
76778 index 45131b4..c521665 100644
76779 --- a/mm/nommu.c
76780 +++ b/mm/nommu.c
76781 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76782 int sysctl_overcommit_ratio = 50; /* default is 50% */
76783 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76784 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76785 -int heap_stack_gap = 0;
76786
76787 atomic_long_t mmap_pages_allocated;
76788
76789 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76790 EXPORT_SYMBOL(find_vma);
76791
76792 /*
76793 - * find a VMA
76794 - * - we don't extend stack VMAs under NOMMU conditions
76795 - */
76796 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76797 -{
76798 - return find_vma(mm, addr);
76799 -}
76800 -
76801 -/*
76802 * expand a stack to a given address
76803 * - not supported under NOMMU conditions
76804 */
76805 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76806
76807 /* most fields are the same, copy all, and then fixup */
76808 *new = *vma;
76809 + INIT_LIST_HEAD(&new->anon_vma_chain);
76810 *region = *vma->vm_region;
76811 new->vm_region = region;
76812
76813 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76814 index ceb4168..d7774f2 100644
76815 --- a/mm/page_alloc.c
76816 +++ b/mm/page_alloc.c
76817 @@ -340,7 +340,7 @@ out:
76818 * This usage means that zero-order pages may not be compound.
76819 */
76820
76821 -static void free_compound_page(struct page *page)
76822 +void free_compound_page(struct page *page)
76823 {
76824 __free_pages_ok(page, compound_order(page));
76825 }
76826 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76827 int i;
76828 int bad = 0;
76829
76830 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76831 + unsigned long index = 1UL << order;
76832 +#endif
76833 +
76834 trace_mm_page_free(page, order);
76835 kmemcheck_free_shadow(page, order);
76836
76837 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76838 debug_check_no_obj_freed(page_address(page),
76839 PAGE_SIZE << order);
76840 }
76841 +
76842 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76843 + for (; index; --index)
76844 + sanitize_highpage(page + index - 1);
76845 +#endif
76846 +
76847 arch_free_page(page, order);
76848 kernel_map_pages(page, 1 << order, 0);
76849
76850 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
76851 arch_alloc_page(page, order);
76852 kernel_map_pages(page, 1 << order, 1);
76853
76854 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
76855 if (gfp_flags & __GFP_ZERO)
76856 prep_zero_page(page, order, gfp_flags);
76857 +#endif
76858
76859 if (order && (gfp_flags & __GFP_COMP))
76860 prep_compound_page(page, order);
76861 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
76862 unsigned long pfn;
76863
76864 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
76865 +#ifdef CONFIG_X86_32
76866 + /* boot failures in VMware 8 on 32bit vanilla since
76867 + this change */
76868 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
76869 +#else
76870 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
76871 +#endif
76872 return 1;
76873 }
76874 return 0;
76875 diff --git a/mm/percpu.c b/mm/percpu.c
76876 index ddc5efb..f632d2c 100644
76877 --- a/mm/percpu.c
76878 +++ b/mm/percpu.c
76879 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
76880 static unsigned int pcpu_high_unit_cpu __read_mostly;
76881
76882 /* the address of the first chunk which starts with the kernel static area */
76883 -void *pcpu_base_addr __read_mostly;
76884 +void *pcpu_base_addr __read_only;
76885 EXPORT_SYMBOL_GPL(pcpu_base_addr);
76886
76887 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
76888 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
76889 index 926b466..b23df53 100644
76890 --- a/mm/process_vm_access.c
76891 +++ b/mm/process_vm_access.c
76892 @@ -13,6 +13,7 @@
76893 #include <linux/uio.h>
76894 #include <linux/sched.h>
76895 #include <linux/highmem.h>
76896 +#include <linux/security.h>
76897 #include <linux/ptrace.h>
76898 #include <linux/slab.h>
76899 #include <linux/syscalls.h>
76900 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76901 size_t iov_l_curr_offset = 0;
76902 ssize_t iov_len;
76903
76904 + return -ENOSYS; // PaX: until properly audited
76905 +
76906 /*
76907 * Work out how many pages of struct pages we're going to need
76908 * when eventually calling get_user_pages
76909 */
76910 for (i = 0; i < riovcnt; i++) {
76911 iov_len = rvec[i].iov_len;
76912 - if (iov_len > 0) {
76913 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
76914 - + iov_len)
76915 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
76916 - / PAGE_SIZE + 1;
76917 - nr_pages = max(nr_pages, nr_pages_iov);
76918 - }
76919 + if (iov_len <= 0)
76920 + continue;
76921 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
76922 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
76923 + nr_pages = max(nr_pages, nr_pages_iov);
76924 }
76925
76926 if (nr_pages == 0)
76927 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76928 goto free_proc_pages;
76929 }
76930
76931 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
76932 + rc = -EPERM;
76933 + goto put_task_struct;
76934 + }
76935 +
76936 mm = mm_access(task, PTRACE_MODE_ATTACH);
76937 if (!mm || IS_ERR(mm)) {
76938 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
76939 diff --git a/mm/rmap.c b/mm/rmap.c
76940 index 2ee1ef0..2e175ba 100644
76941 --- a/mm/rmap.c
76942 +++ b/mm/rmap.c
76943 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76944 struct anon_vma *anon_vma = vma->anon_vma;
76945 struct anon_vma_chain *avc;
76946
76947 +#ifdef CONFIG_PAX_SEGMEXEC
76948 + struct anon_vma_chain *avc_m = NULL;
76949 +#endif
76950 +
76951 might_sleep();
76952 if (unlikely(!anon_vma)) {
76953 struct mm_struct *mm = vma->vm_mm;
76954 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76955 if (!avc)
76956 goto out_enomem;
76957
76958 +#ifdef CONFIG_PAX_SEGMEXEC
76959 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
76960 + if (!avc_m)
76961 + goto out_enomem_free_avc;
76962 +#endif
76963 +
76964 anon_vma = find_mergeable_anon_vma(vma);
76965 allocated = NULL;
76966 if (!anon_vma) {
76967 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76968 /* page_table_lock to protect against threads */
76969 spin_lock(&mm->page_table_lock);
76970 if (likely(!vma->anon_vma)) {
76971 +
76972 +#ifdef CONFIG_PAX_SEGMEXEC
76973 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
76974 +
76975 + if (vma_m) {
76976 + BUG_ON(vma_m->anon_vma);
76977 + vma_m->anon_vma = anon_vma;
76978 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
76979 + avc_m = NULL;
76980 + }
76981 +#endif
76982 +
76983 vma->anon_vma = anon_vma;
76984 anon_vma_chain_link(vma, avc, anon_vma);
76985 allocated = NULL;
76986 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76987
76988 if (unlikely(allocated))
76989 put_anon_vma(allocated);
76990 +
76991 +#ifdef CONFIG_PAX_SEGMEXEC
76992 + if (unlikely(avc_m))
76993 + anon_vma_chain_free(avc_m);
76994 +#endif
76995 +
76996 if (unlikely(avc))
76997 anon_vma_chain_free(avc);
76998 }
76999 return 0;
77000
77001 out_enomem_free_avc:
77002 +
77003 +#ifdef CONFIG_PAX_SEGMEXEC
77004 + if (avc_m)
77005 + anon_vma_chain_free(avc_m);
77006 +#endif
77007 +
77008 anon_vma_chain_free(avc);
77009 out_enomem:
77010 return -ENOMEM;
77011 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77012 * Attach the anon_vmas from src to dst.
77013 * Returns 0 on success, -ENOMEM on failure.
77014 */
77015 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77016 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77017 {
77018 struct anon_vma_chain *avc, *pavc;
77019 struct anon_vma *root = NULL;
77020 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77021 * the corresponding VMA in the parent process is attached to.
77022 * Returns 0 on success, non-zero on failure.
77023 */
77024 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77025 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77026 {
77027 struct anon_vma_chain *avc;
77028 struct anon_vma *anon_vma;
77029 diff --git a/mm/shmem.c b/mm/shmem.c
77030 index 50c5b8f..0bc87f7 100644
77031 --- a/mm/shmem.c
77032 +++ b/mm/shmem.c
77033 @@ -31,7 +31,7 @@
77034 #include <linux/export.h>
77035 #include <linux/swap.h>
77036
77037 -static struct vfsmount *shm_mnt;
77038 +struct vfsmount *shm_mnt;
77039
77040 #ifdef CONFIG_SHMEM
77041 /*
77042 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77043 #define BOGO_DIRENT_SIZE 20
77044
77045 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77046 -#define SHORT_SYMLINK_LEN 128
77047 +#define SHORT_SYMLINK_LEN 64
77048
77049 /*
77050 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77051 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77052 static int shmem_xattr_validate(const char *name)
77053 {
77054 struct { const char *prefix; size_t len; } arr[] = {
77055 +
77056 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77057 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77058 +#endif
77059 +
77060 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77061 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77062 };
77063 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77064 if (err)
77065 return err;
77066
77067 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77068 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77069 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77070 + return -EOPNOTSUPP;
77071 + if (size > 8)
77072 + return -EINVAL;
77073 + }
77074 +#endif
77075 +
77076 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77077 }
77078
77079 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77080 int err = -ENOMEM;
77081
77082 /* Round up to L1_CACHE_BYTES to resist false sharing */
77083 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77084 - L1_CACHE_BYTES), GFP_KERNEL);
77085 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77086 if (!sbinfo)
77087 return -ENOMEM;
77088
77089 diff --git a/mm/slab.c b/mm/slab.c
77090 index 33d3363..3851c61 100644
77091 --- a/mm/slab.c
77092 +++ b/mm/slab.c
77093 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77094
77095 /* Legal flag mask for kmem_cache_create(). */
77096 #if DEBUG
77097 -# define CREATE_MASK (SLAB_RED_ZONE | \
77098 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77099 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77100 SLAB_CACHE_DMA | \
77101 SLAB_STORE_USER | \
77102 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77103 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77104 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77105 #else
77106 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77107 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77108 SLAB_CACHE_DMA | \
77109 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77110 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77111 @@ -322,7 +322,7 @@ struct kmem_list3 {
77112 * Need this for bootstrapping a per node allocator.
77113 */
77114 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77115 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77116 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77117 #define CACHE_CACHE 0
77118 #define SIZE_AC MAX_NUMNODES
77119 #define SIZE_L3 (2 * MAX_NUMNODES)
77120 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77121 if ((x)->max_freeable < i) \
77122 (x)->max_freeable = i; \
77123 } while (0)
77124 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77125 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77126 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77127 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77128 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77129 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77130 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77131 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77132 #else
77133 #define STATS_INC_ACTIVE(x) do { } while (0)
77134 #define STATS_DEC_ACTIVE(x) do { } while (0)
77135 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77136 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77137 */
77138 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77139 - const struct slab *slab, void *obj)
77140 + const struct slab *slab, const void *obj)
77141 {
77142 u32 offset = (obj - slab->s_mem);
77143 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77144 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77145 struct cache_names {
77146 char *name;
77147 char *name_dma;
77148 + char *name_usercopy;
77149 };
77150
77151 static struct cache_names __initdata cache_names[] = {
77152 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77153 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77154 #include <linux/kmalloc_sizes.h>
77155 - {NULL,}
77156 + {NULL}
77157 #undef CACHE
77158 };
77159
77160 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77161 if (unlikely(gfpflags & GFP_DMA))
77162 return csizep->cs_dmacachep;
77163 #endif
77164 +
77165 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77166 + if (unlikely(gfpflags & GFP_USERCOPY))
77167 + return csizep->cs_usercopycachep;
77168 +#endif
77169 +
77170 return csizep->cs_cachep;
77171 }
77172
77173 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77174 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77175 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77176 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77177 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77178 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77179 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77180
77181 if (INDEX_AC != INDEX_L3) {
77182 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77183 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77184 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77185 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77186 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77187 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77188 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77189 }
77190
77191 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77192 sizes->cs_cachep->size = sizes->cs_size;
77193 sizes->cs_cachep->object_size = sizes->cs_size;
77194 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77195 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77196 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77197 list_add(&sizes->cs_cachep->list, &slab_caches);
77198 }
77199 #ifdef CONFIG_ZONE_DMA
77200 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77201 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77202 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77203 #endif
77204 +
77205 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77206 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77207 + sizes->cs_usercopycachep->name = names->name_usercopy;
77208 + sizes->cs_usercopycachep->size = sizes->cs_size;
77209 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
77210 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77211 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77212 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77213 +#endif
77214 +
77215 sizes++;
77216 names++;
77217 }
77218 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77219 }
77220 /* cpu stats */
77221 {
77222 - unsigned long allochit = atomic_read(&cachep->allochit);
77223 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77224 - unsigned long freehit = atomic_read(&cachep->freehit);
77225 - unsigned long freemiss = atomic_read(&cachep->freemiss);
77226 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77227 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77228 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77229 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77230
77231 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77232 allochit, allocmiss, freehit, freemiss);
77233 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77234 {
77235 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77236 #ifdef CONFIG_DEBUG_SLAB_LEAK
77237 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77238 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77239 #endif
77240 return 0;
77241 }
77242 module_init(slab_proc_init);
77243 #endif
77244
77245 +bool is_usercopy_object(const void *ptr)
77246 +{
77247 + struct page *page;
77248 + struct kmem_cache *cachep;
77249 +
77250 + if (ZERO_OR_NULL_PTR(ptr))
77251 + return false;
77252 +
77253 + if (!slab_is_available())
77254 + return false;
77255 +
77256 + if (!virt_addr_valid(ptr))
77257 + return false;
77258 +
77259 + page = virt_to_head_page(ptr);
77260 +
77261 + if (!PageSlab(page))
77262 + return false;
77263 +
77264 + cachep = page->slab_cache;
77265 + return cachep->flags & SLAB_USERCOPY;
77266 +}
77267 +
77268 +#ifdef CONFIG_PAX_USERCOPY
77269 +const char *check_heap_object(const void *ptr, unsigned long n)
77270 +{
77271 + struct page *page;
77272 + struct kmem_cache *cachep;
77273 + struct slab *slabp;
77274 + unsigned int objnr;
77275 + unsigned long offset;
77276 +
77277 + if (ZERO_OR_NULL_PTR(ptr))
77278 + return "<null>";
77279 +
77280 + if (!virt_addr_valid(ptr))
77281 + return NULL;
77282 +
77283 + page = virt_to_head_page(ptr);
77284 +
77285 + if (!PageSlab(page))
77286 + return NULL;
77287 +
77288 + cachep = page->slab_cache;
77289 + if (!(cachep->flags & SLAB_USERCOPY))
77290 + return cachep->name;
77291 +
77292 + slabp = page->slab_page;
77293 + objnr = obj_to_index(cachep, slabp, ptr);
77294 + BUG_ON(objnr >= cachep->num);
77295 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77296 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77297 + return NULL;
77298 +
77299 + return cachep->name;
77300 +}
77301 +#endif
77302 +
77303 /**
77304 * ksize - get the actual amount of memory allocated for a given object
77305 * @objp: Pointer to the object
77306 diff --git a/mm/slab_common.c b/mm/slab_common.c
77307 index 069a24e6..226a310 100644
77308 --- a/mm/slab_common.c
77309 +++ b/mm/slab_common.c
77310 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77311 err = __kmem_cache_create(s, flags);
77312 if (!err) {
77313
77314 - s->refcount = 1;
77315 + atomic_set(&s->refcount, 1);
77316 list_add(&s->list, &slab_caches);
77317
77318 } else {
77319 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77320 {
77321 get_online_cpus();
77322 mutex_lock(&slab_mutex);
77323 - s->refcount--;
77324 - if (!s->refcount) {
77325 + if (atomic_dec_and_test(&s->refcount)) {
77326 list_del(&s->list);
77327
77328 if (!__kmem_cache_shutdown(s)) {
77329 diff --git a/mm/slob.c b/mm/slob.c
77330 index 1e921c5..1ce12c2 100644
77331 --- a/mm/slob.c
77332 +++ b/mm/slob.c
77333 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77334 /*
77335 * Return the size of a slob block.
77336 */
77337 -static slobidx_t slob_units(slob_t *s)
77338 +static slobidx_t slob_units(const slob_t *s)
77339 {
77340 if (s->units > 0)
77341 return s->units;
77342 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77343 /*
77344 * Return the next free slob block pointer after this one.
77345 */
77346 -static slob_t *slob_next(slob_t *s)
77347 +static slob_t *slob_next(const slob_t *s)
77348 {
77349 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77350 slobidx_t next;
77351 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77352 /*
77353 * Returns true if s is the last free block in its page.
77354 */
77355 -static int slob_last(slob_t *s)
77356 +static int slob_last(const slob_t *s)
77357 {
77358 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77359 }
77360
77361 -static void *slob_new_pages(gfp_t gfp, int order, int node)
77362 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77363 {
77364 - void *page;
77365 + struct page *page;
77366
77367 #ifdef CONFIG_NUMA
77368 if (node != NUMA_NO_NODE)
77369 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77370 if (!page)
77371 return NULL;
77372
77373 - return page_address(page);
77374 + __SetPageSlab(page);
77375 + return page;
77376 }
77377
77378 -static void slob_free_pages(void *b, int order)
77379 +static void slob_free_pages(struct page *sp, int order)
77380 {
77381 if (current->reclaim_state)
77382 current->reclaim_state->reclaimed_slab += 1 << order;
77383 - free_pages((unsigned long)b, order);
77384 + __ClearPageSlab(sp);
77385 + reset_page_mapcount(sp);
77386 + sp->private = 0;
77387 + __free_pages(sp, order);
77388 }
77389
77390 /*
77391 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77392
77393 /* Not enough space: must allocate a new page */
77394 if (!b) {
77395 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77396 - if (!b)
77397 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77398 + if (!sp)
77399 return NULL;
77400 - sp = virt_to_page(b);
77401 - __SetPageSlab(sp);
77402 + b = page_address(sp);
77403
77404 spin_lock_irqsave(&slob_lock, flags);
77405 sp->units = SLOB_UNITS(PAGE_SIZE);
77406 sp->freelist = b;
77407 + sp->private = 0;
77408 INIT_LIST_HEAD(&sp->list);
77409 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77410 set_slob_page_free(sp, slob_list);
77411 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77412 if (slob_page_free(sp))
77413 clear_slob_page_free(sp);
77414 spin_unlock_irqrestore(&slob_lock, flags);
77415 - __ClearPageSlab(sp);
77416 - reset_page_mapcount(sp);
77417 - slob_free_pages(b, 0);
77418 + slob_free_pages(sp, 0);
77419 return;
77420 }
77421
77422 @@ -426,11 +428,10 @@ out:
77423 */
77424
77425 static __always_inline void *
77426 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77427 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77428 {
77429 - unsigned int *m;
77430 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77431 - void *ret;
77432 + slob_t *m;
77433 + void *ret = NULL;
77434
77435 gfp &= gfp_allowed_mask;
77436
77437 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77438
77439 if (!m)
77440 return NULL;
77441 - *m = size;
77442 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77443 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77444 + m[0].units = size;
77445 + m[1].units = align;
77446 ret = (void *)m + align;
77447
77448 trace_kmalloc_node(caller, ret,
77449 size, size + align, gfp, node);
77450 } else {
77451 unsigned int order = get_order(size);
77452 + struct page *page;
77453
77454 if (likely(order))
77455 gfp |= __GFP_COMP;
77456 - ret = slob_new_pages(gfp, order, node);
77457 - if (ret) {
77458 - struct page *page;
77459 - page = virt_to_page(ret);
77460 + page = slob_new_pages(gfp, order, node);
77461 + if (page) {
77462 + ret = page_address(page);
77463 page->private = size;
77464 }
77465
77466 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77467 size, PAGE_SIZE << order, gfp, node);
77468 }
77469
77470 - kmemleak_alloc(ret, size, 1, gfp);
77471 + return ret;
77472 +}
77473 +
77474 +static __always_inline void *
77475 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77476 +{
77477 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77478 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77479 +
77480 + if (!ZERO_OR_NULL_PTR(ret))
77481 + kmemleak_alloc(ret, size, 1, gfp);
77482 return ret;
77483 }
77484
77485 @@ -501,15 +515,91 @@ void kfree(const void *block)
77486 kmemleak_free(block);
77487
77488 sp = virt_to_page(block);
77489 - if (PageSlab(sp)) {
77490 + VM_BUG_ON(!PageSlab(sp));
77491 + if (!sp->private) {
77492 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77493 - unsigned int *m = (unsigned int *)(block - align);
77494 - slob_free(m, *m + align);
77495 - } else
77496 + slob_t *m = (slob_t *)(block - align);
77497 + slob_free(m, m[0].units + align);
77498 + } else {
77499 + __ClearPageSlab(sp);
77500 + reset_page_mapcount(sp);
77501 + sp->private = 0;
77502 put_page(sp);
77503 + }
77504 }
77505 EXPORT_SYMBOL(kfree);
77506
77507 +bool is_usercopy_object(const void *ptr)
77508 +{
77509 + if (!slab_is_available())
77510 + return false;
77511 +
77512 + // PAX: TODO
77513 +
77514 + return false;
77515 +}
77516 +
77517 +#ifdef CONFIG_PAX_USERCOPY
77518 +const char *check_heap_object(const void *ptr, unsigned long n)
77519 +{
77520 + struct page *page;
77521 + const slob_t *free;
77522 + const void *base;
77523 + unsigned long flags;
77524 +
77525 + if (ZERO_OR_NULL_PTR(ptr))
77526 + return "<null>";
77527 +
77528 + if (!virt_addr_valid(ptr))
77529 + return NULL;
77530 +
77531 + page = virt_to_head_page(ptr);
77532 + if (!PageSlab(page))
77533 + return NULL;
77534 +
77535 + if (page->private) {
77536 + base = page;
77537 + if (base <= ptr && n <= page->private - (ptr - base))
77538 + return NULL;
77539 + return "<slob>";
77540 + }
77541 +
77542 + /* some tricky double walking to find the chunk */
77543 + spin_lock_irqsave(&slob_lock, flags);
77544 + base = (void *)((unsigned long)ptr & PAGE_MASK);
77545 + free = page->freelist;
77546 +
77547 + while (!slob_last(free) && (void *)free <= ptr) {
77548 + base = free + slob_units(free);
77549 + free = slob_next(free);
77550 + }
77551 +
77552 + while (base < (void *)free) {
77553 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77554 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
77555 + int offset;
77556 +
77557 + if (ptr < base + align)
77558 + break;
77559 +
77560 + offset = ptr - base - align;
77561 + if (offset >= m) {
77562 + base += size;
77563 + continue;
77564 + }
77565 +
77566 + if (n > m - offset)
77567 + break;
77568 +
77569 + spin_unlock_irqrestore(&slob_lock, flags);
77570 + return NULL;
77571 + }
77572 +
77573 + spin_unlock_irqrestore(&slob_lock, flags);
77574 + return "<slob>";
77575 +}
77576 +#endif
77577 +
77578 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77579 size_t ksize(const void *block)
77580 {
77581 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
77582 return 0;
77583
77584 sp = virt_to_page(block);
77585 - if (PageSlab(sp)) {
77586 + VM_BUG_ON(!PageSlab(sp));
77587 + if (!sp->private) {
77588 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77589 - unsigned int *m = (unsigned int *)(block - align);
77590 - return SLOB_UNITS(*m) * SLOB_UNIT;
77591 + slob_t *m = (slob_t *)(block - align);
77592 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77593 } else
77594 return sp->private;
77595 }
77596 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77597
77598 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77599 {
77600 - void *b;
77601 + void *b = NULL;
77602
77603 flags &= gfp_allowed_mask;
77604
77605 lockdep_trace_alloc(flags);
77606
77607 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77608 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77609 +#else
77610 if (c->size < PAGE_SIZE) {
77611 b = slob_alloc(c->size, flags, c->align, node);
77612 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77613 SLOB_UNITS(c->size) * SLOB_UNIT,
77614 flags, node);
77615 } else {
77616 - b = slob_new_pages(flags, get_order(c->size), node);
77617 + struct page *sp;
77618 +
77619 + sp = slob_new_pages(flags, get_order(c->size), node);
77620 + if (sp) {
77621 + b = page_address(sp);
77622 + sp->private = c->size;
77623 + }
77624 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77625 PAGE_SIZE << get_order(c->size),
77626 flags, node);
77627 }
77628 +#endif
77629
77630 if (c->ctor)
77631 c->ctor(b);
77632 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77633
77634 static void __kmem_cache_free(void *b, int size)
77635 {
77636 - if (size < PAGE_SIZE)
77637 + struct page *sp;
77638 +
77639 + sp = virt_to_page(b);
77640 + BUG_ON(!PageSlab(sp));
77641 + if (!sp->private)
77642 slob_free(b, size);
77643 else
77644 - slob_free_pages(b, get_order(size));
77645 + slob_free_pages(sp, get_order(size));
77646 }
77647
77648 static void kmem_rcu_free(struct rcu_head *head)
77649 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77650
77651 void kmem_cache_free(struct kmem_cache *c, void *b)
77652 {
77653 + int size = c->size;
77654 +
77655 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77656 + if (size + c->align < PAGE_SIZE) {
77657 + size += c->align;
77658 + b -= c->align;
77659 + }
77660 +#endif
77661 +
77662 kmemleak_free_recursive(b, c->flags);
77663 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77664 struct slob_rcu *slob_rcu;
77665 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77666 - slob_rcu->size = c->size;
77667 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77668 + slob_rcu->size = size;
77669 call_rcu(&slob_rcu->head, kmem_rcu_free);
77670 } else {
77671 - __kmem_cache_free(b, c->size);
77672 + __kmem_cache_free(b, size);
77673 }
77674
77675 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77676 + trace_kfree(_RET_IP_, b);
77677 +#else
77678 trace_kmem_cache_free(_RET_IP_, b);
77679 +#endif
77680 +
77681 }
77682 EXPORT_SYMBOL(kmem_cache_free);
77683
77684 diff --git a/mm/slub.c b/mm/slub.c
77685 index 321afab..9595170 100644
77686 --- a/mm/slub.c
77687 +++ b/mm/slub.c
77688 @@ -201,7 +201,7 @@ struct track {
77689
77690 enum track_item { TRACK_ALLOC, TRACK_FREE };
77691
77692 -#ifdef CONFIG_SYSFS
77693 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77694 static int sysfs_slab_add(struct kmem_cache *);
77695 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77696 static void sysfs_slab_remove(struct kmem_cache *);
77697 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77698 if (!t->addr)
77699 return;
77700
77701 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77702 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77703 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77704 #ifdef CONFIG_STACKTRACE
77705 {
77706 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77707
77708 page = virt_to_head_page(x);
77709
77710 + BUG_ON(!PageSlab(page));
77711 +
77712 if (kmem_cache_debug(s) && page->slab != s) {
77713 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77714 " is from %s\n", page->slab->name, s->name);
77715 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77716 * Merge control. If this is set then no merging of slab caches will occur.
77717 * (Could be removed. This was introduced to pacify the merge skeptics.)
77718 */
77719 -static int slub_nomerge;
77720 +static int slub_nomerge = 1;
77721
77722 /*
77723 * Calculate the order of allocation given an slab object size.
77724 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77725 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77726 #endif
77727
77728 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77729 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77730 +#endif
77731 +
77732 static int __init setup_slub_min_order(char *str)
77733 {
77734 get_option(&str, &slub_min_order);
77735 @@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77736 if (kmem_cache_open(s, flags))
77737 goto panic;
77738
77739 - s->refcount = 1;
77740 + atomic_set(&s->refcount, 1);
77741 list_add(&s->list, &slab_caches);
77742 return s;
77743
77744 @@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77745 return kmalloc_dma_caches[index];
77746
77747 #endif
77748 +
77749 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77750 + if (flags & SLAB_USERCOPY)
77751 + return kmalloc_usercopy_caches[index];
77752 +
77753 +#endif
77754 +
77755 return kmalloc_caches[index];
77756 }
77757
77758 @@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77759 EXPORT_SYMBOL(__kmalloc_node);
77760 #endif
77761
77762 +bool is_usercopy_object(const void *ptr)
77763 +{
77764 + struct page *page;
77765 + struct kmem_cache *s;
77766 +
77767 + if (ZERO_OR_NULL_PTR(ptr))
77768 + return false;
77769 +
77770 + if (!slab_is_available())
77771 + return false;
77772 +
77773 + if (!virt_addr_valid(ptr))
77774 + return false;
77775 +
77776 + page = virt_to_head_page(ptr);
77777 +
77778 + if (!PageSlab(page))
77779 + return false;
77780 +
77781 + s = page->slab;
77782 + return s->flags & SLAB_USERCOPY;
77783 +}
77784 +
77785 +#ifdef CONFIG_PAX_USERCOPY
77786 +const char *check_heap_object(const void *ptr, unsigned long n)
77787 +{
77788 + struct page *page;
77789 + struct kmem_cache *s;
77790 + unsigned long offset;
77791 +
77792 + if (ZERO_OR_NULL_PTR(ptr))
77793 + return "<null>";
77794 +
77795 + if (!virt_addr_valid(ptr))
77796 + return NULL;
77797 +
77798 + page = virt_to_head_page(ptr);
77799 +
77800 + if (!PageSlab(page))
77801 + return NULL;
77802 +
77803 + s = page->slab;
77804 + if (!(s->flags & SLAB_USERCOPY))
77805 + return s->name;
77806 +
77807 + offset = (ptr - page_address(page)) % s->size;
77808 + if (offset <= s->object_size && n <= s->object_size - offset)
77809 + return NULL;
77810 +
77811 + return s->name;
77812 +}
77813 +#endif
77814 +
77815 size_t ksize(const void *object)
77816 {
77817 struct page *page;
77818 @@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77819 int node;
77820
77821 list_add(&s->list, &slab_caches);
77822 - s->refcount = -1;
77823 + atomic_set(&s->refcount, -1);
77824
77825 for_each_node_state(node, N_NORMAL_MEMORY) {
77826 struct kmem_cache_node *n = get_node(s, node);
77827 @@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
77828
77829 /* Caches that are not of the two-to-the-power-of size */
77830 if (KMALLOC_MIN_SIZE <= 32) {
77831 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77832 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77833 caches++;
77834 }
77835
77836 if (KMALLOC_MIN_SIZE <= 64) {
77837 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77838 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77839 caches++;
77840 }
77841
77842 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77843 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77844 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77845 caches++;
77846 }
77847
77848 @@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
77849 }
77850 }
77851 #endif
77852 +
77853 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77854 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
77855 + struct kmem_cache *s = kmalloc_caches[i];
77856 +
77857 + if (s && s->size) {
77858 + char *name = kasprintf(GFP_NOWAIT,
77859 + "usercopy-kmalloc-%d", s->object_size);
77860 +
77861 + BUG_ON(!name);
77862 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
77863 + s->object_size, SLAB_USERCOPY);
77864 + }
77865 + }
77866 +#endif
77867 +
77868 printk(KERN_INFO
77869 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
77870 " CPUs=%d, Nodes=%d\n",
77871 @@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
77872 /*
77873 * We may have set a slab to be unmergeable during bootstrap.
77874 */
77875 - if (s->refcount < 0)
77876 + if (atomic_read(&s->refcount) < 0)
77877 return 1;
77878
77879 return 0;
77880 @@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77881
77882 s = find_mergeable(size, align, flags, name, ctor);
77883 if (s) {
77884 - s->refcount++;
77885 + atomic_inc(&s->refcount);
77886 /*
77887 * Adjust the object sizes so that we clear
77888 * the complete object on kzalloc.
77889 @@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77890 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
77891
77892 if (sysfs_slab_alias(s, name)) {
77893 - s->refcount--;
77894 + atomic_dec(&s->refcount);
77895 s = NULL;
77896 }
77897 }
77898 @@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
77899 }
77900 #endif
77901
77902 -#ifdef CONFIG_SYSFS
77903 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77904 static int count_inuse(struct page *page)
77905 {
77906 return page->inuse;
77907 @@ -4451,12 +4533,12 @@ static void resiliency_test(void)
77908 validate_slab_cache(kmalloc_caches[9]);
77909 }
77910 #else
77911 -#ifdef CONFIG_SYSFS
77912 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77913 static void resiliency_test(void) {};
77914 #endif
77915 #endif
77916
77917 -#ifdef CONFIG_SYSFS
77918 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77919 enum slab_stat_type {
77920 SL_ALL, /* All slabs */
77921 SL_PARTIAL, /* Only partially allocated slabs */
77922 @@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
77923
77924 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
77925 {
77926 - return sprintf(buf, "%d\n", s->refcount - 1);
77927 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
77928 }
77929 SLAB_ATTR_RO(aliases);
77930
77931 @@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
77932 return name;
77933 }
77934
77935 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77936 static int sysfs_slab_add(struct kmem_cache *s)
77937 {
77938 int err;
77939 @@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
77940 kobject_del(&s->kobj);
77941 kobject_put(&s->kobj);
77942 }
77943 +#endif
77944
77945 /*
77946 * Need to buffer aliases during bootup until sysfs becomes
77947 @@ -5337,6 +5421,7 @@ struct saved_alias {
77948
77949 static struct saved_alias *alias_list;
77950
77951 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77952 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77953 {
77954 struct saved_alias *al;
77955 @@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77956 alias_list = al;
77957 return 0;
77958 }
77959 +#endif
77960
77961 static int __init slab_sysfs_init(void)
77962 {
77963 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
77964 index 1b7e22a..3fcd4f3 100644
77965 --- a/mm/sparse-vmemmap.c
77966 +++ b/mm/sparse-vmemmap.c
77967 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
77968 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77969 if (!p)
77970 return NULL;
77971 - pud_populate(&init_mm, pud, p);
77972 + pud_populate_kernel(&init_mm, pud, p);
77973 }
77974 return pud;
77975 }
77976 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
77977 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77978 if (!p)
77979 return NULL;
77980 - pgd_populate(&init_mm, pgd, p);
77981 + pgd_populate_kernel(&init_mm, pgd, p);
77982 }
77983 return pgd;
77984 }
77985 diff --git a/mm/swap.c b/mm/swap.c
77986 index 6310dc2..3662b3f 100644
77987 --- a/mm/swap.c
77988 +++ b/mm/swap.c
77989 @@ -30,6 +30,7 @@
77990 #include <linux/backing-dev.h>
77991 #include <linux/memcontrol.h>
77992 #include <linux/gfp.h>
77993 +#include <linux/hugetlb.h>
77994
77995 #include "internal.h"
77996
77997 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
77998
77999 __page_cache_release(page);
78000 dtor = get_compound_page_dtor(page);
78001 + if (!PageHuge(page))
78002 + BUG_ON(dtor != free_compound_page);
78003 (*dtor)(page);
78004 }
78005
78006 diff --git a/mm/swapfile.c b/mm/swapfile.c
78007 index f91a255..9dcac21 100644
78008 --- a/mm/swapfile.c
78009 +++ b/mm/swapfile.c
78010 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78011
78012 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78013 /* Activity counter to indicate that a swapon or swapoff has occurred */
78014 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
78015 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78016
78017 static inline unsigned char swap_count(unsigned char ent)
78018 {
78019 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78020 }
78021 filp_close(swap_file, NULL);
78022 err = 0;
78023 - atomic_inc(&proc_poll_event);
78024 + atomic_inc_unchecked(&proc_poll_event);
78025 wake_up_interruptible(&proc_poll_wait);
78026
78027 out_dput:
78028 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78029
78030 poll_wait(file, &proc_poll_wait, wait);
78031
78032 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
78033 - seq->poll_event = atomic_read(&proc_poll_event);
78034 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78035 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78036 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78037 }
78038
78039 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78040 return ret;
78041
78042 seq = file->private_data;
78043 - seq->poll_event = atomic_read(&proc_poll_event);
78044 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78045 return 0;
78046 }
78047
78048 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78049 (frontswap_map) ? "FS" : "");
78050
78051 mutex_unlock(&swapon_mutex);
78052 - atomic_inc(&proc_poll_event);
78053 + atomic_inc_unchecked(&proc_poll_event);
78054 wake_up_interruptible(&proc_poll_wait);
78055
78056 if (S_ISREG(inode->i_mode))
78057 diff --git a/mm/util.c b/mm/util.c
78058 index dc3036c..b6c7c9d 100644
78059 --- a/mm/util.c
78060 +++ b/mm/util.c
78061 @@ -292,6 +292,12 @@ done:
78062 void arch_pick_mmap_layout(struct mm_struct *mm)
78063 {
78064 mm->mmap_base = TASK_UNMAPPED_BASE;
78065 +
78066 +#ifdef CONFIG_PAX_RANDMMAP
78067 + if (mm->pax_flags & MF_PAX_RANDMMAP)
78068 + mm->mmap_base += mm->delta_mmap;
78069 +#endif
78070 +
78071 mm->get_unmapped_area = arch_get_unmapped_area;
78072 mm->unmap_area = arch_unmap_area;
78073 }
78074 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78075 index 78e0830..bc6bbd8 100644
78076 --- a/mm/vmalloc.c
78077 +++ b/mm/vmalloc.c
78078 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78079
78080 pte = pte_offset_kernel(pmd, addr);
78081 do {
78082 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78083 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78084 +
78085 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78086 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78087 + BUG_ON(!pte_exec(*pte));
78088 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78089 + continue;
78090 + }
78091 +#endif
78092 +
78093 + {
78094 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78095 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78096 + }
78097 } while (pte++, addr += PAGE_SIZE, addr != end);
78098 }
78099
78100 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78101 pte = pte_alloc_kernel(pmd, addr);
78102 if (!pte)
78103 return -ENOMEM;
78104 +
78105 + pax_open_kernel();
78106 do {
78107 struct page *page = pages[*nr];
78108
78109 - if (WARN_ON(!pte_none(*pte)))
78110 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78111 + if (pgprot_val(prot) & _PAGE_NX)
78112 +#endif
78113 +
78114 + if (!pte_none(*pte)) {
78115 + pax_close_kernel();
78116 + WARN_ON(1);
78117 return -EBUSY;
78118 - if (WARN_ON(!page))
78119 + }
78120 + if (!page) {
78121 + pax_close_kernel();
78122 + WARN_ON(1);
78123 return -ENOMEM;
78124 + }
78125 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78126 (*nr)++;
78127 } while (pte++, addr += PAGE_SIZE, addr != end);
78128 + pax_close_kernel();
78129 return 0;
78130 }
78131
78132 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78133 pmd_t *pmd;
78134 unsigned long next;
78135
78136 - pmd = pmd_alloc(&init_mm, pud, addr);
78137 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78138 if (!pmd)
78139 return -ENOMEM;
78140 do {
78141 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78142 pud_t *pud;
78143 unsigned long next;
78144
78145 - pud = pud_alloc(&init_mm, pgd, addr);
78146 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78147 if (!pud)
78148 return -ENOMEM;
78149 do {
78150 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78151 * and fall back on vmalloc() if that fails. Others
78152 * just put it in the vmalloc space.
78153 */
78154 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78155 +#ifdef CONFIG_MODULES
78156 +#ifdef MODULES_VADDR
78157 unsigned long addr = (unsigned long)x;
78158 if (addr >= MODULES_VADDR && addr < MODULES_END)
78159 return 1;
78160 #endif
78161 +
78162 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78163 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78164 + return 1;
78165 +#endif
78166 +
78167 +#endif
78168 +
78169 return is_vmalloc_addr(x);
78170 }
78171
78172 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78173
78174 if (!pgd_none(*pgd)) {
78175 pud_t *pud = pud_offset(pgd, addr);
78176 +#ifdef CONFIG_X86
78177 + if (!pud_large(*pud))
78178 +#endif
78179 if (!pud_none(*pud)) {
78180 pmd_t *pmd = pmd_offset(pud, addr);
78181 +#ifdef CONFIG_X86
78182 + if (!pmd_large(*pmd))
78183 +#endif
78184 if (!pmd_none(*pmd)) {
78185 pte_t *ptep, pte;
78186
78187 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78188 * Allocate a region of KVA of the specified size and alignment, within the
78189 * vstart and vend.
78190 */
78191 -static struct vmap_area *alloc_vmap_area(unsigned long size,
78192 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78193 unsigned long align,
78194 unsigned long vstart, unsigned long vend,
78195 int node, gfp_t gfp_mask)
78196 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78197 struct vm_struct *area;
78198
78199 BUG_ON(in_interrupt());
78200 +
78201 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78202 + if (flags & VM_KERNEXEC) {
78203 + if (start != VMALLOC_START || end != VMALLOC_END)
78204 + return NULL;
78205 + start = (unsigned long)MODULES_EXEC_VADDR;
78206 + end = (unsigned long)MODULES_EXEC_END;
78207 + }
78208 +#endif
78209 +
78210 if (flags & VM_IOREMAP) {
78211 int bit = fls(size);
78212
78213 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78214 if (count > totalram_pages)
78215 return NULL;
78216
78217 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78218 + if (!(pgprot_val(prot) & _PAGE_NX))
78219 + flags |= VM_KERNEXEC;
78220 +#endif
78221 +
78222 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78223 __builtin_return_address(0));
78224 if (!area)
78225 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78226 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78227 goto fail;
78228
78229 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78230 + if (!(pgprot_val(prot) & _PAGE_NX))
78231 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78232 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78233 + else
78234 +#endif
78235 +
78236 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78237 start, end, node, gfp_mask, caller);
78238 if (!area)
78239 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78240 * For tight control over page level allocator and protection flags
78241 * use __vmalloc() instead.
78242 */
78243 -
78244 void *vmalloc_exec(unsigned long size)
78245 {
78246 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78247 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78248 -1, __builtin_return_address(0));
78249 }
78250
78251 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78252 unsigned long uaddr = vma->vm_start;
78253 unsigned long usize = vma->vm_end - vma->vm_start;
78254
78255 + BUG_ON(vma->vm_mirror);
78256 +
78257 if ((PAGE_SIZE-1) & (unsigned long)addr)
78258 return -EINVAL;
78259
78260 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78261 v->addr, v->addr + v->size, v->size);
78262
78263 if (v->caller)
78264 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78265 + seq_printf(m, " %pK", v->caller);
78266 +#else
78267 seq_printf(m, " %pS", v->caller);
78268 +#endif
78269
78270 if (v->nr_pages)
78271 seq_printf(m, " pages=%d", v->nr_pages);
78272 diff --git a/mm/vmstat.c b/mm/vmstat.c
78273 index c737057..a49753a 100644
78274 --- a/mm/vmstat.c
78275 +++ b/mm/vmstat.c
78276 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78277 *
78278 * vm_stat contains the global counters
78279 */
78280 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78281 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78282 EXPORT_SYMBOL(vm_stat);
78283
78284 #ifdef CONFIG_SMP
78285 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78286 v = p->vm_stat_diff[i];
78287 p->vm_stat_diff[i] = 0;
78288 local_irq_restore(flags);
78289 - atomic_long_add(v, &zone->vm_stat[i]);
78290 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78291 global_diff[i] += v;
78292 #ifdef CONFIG_NUMA
78293 /* 3 seconds idle till flush */
78294 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78295
78296 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78297 if (global_diff[i])
78298 - atomic_long_add(global_diff[i], &vm_stat[i]);
78299 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78300 }
78301
78302 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78303 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78304 if (pset->vm_stat_diff[i]) {
78305 int v = pset->vm_stat_diff[i];
78306 pset->vm_stat_diff[i] = 0;
78307 - atomic_long_add(v, &zone->vm_stat[i]);
78308 - atomic_long_add(v, &vm_stat[i]);
78309 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78310 + atomic_long_add_unchecked(v, &vm_stat[i]);
78311 }
78312 }
78313 #endif
78314 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78315 start_cpu_timer(cpu);
78316 #endif
78317 #ifdef CONFIG_PROC_FS
78318 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78319 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78320 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78321 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78322 + {
78323 + mode_t gr_mode = S_IRUGO;
78324 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78325 + gr_mode = S_IRUSR;
78326 +#endif
78327 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78328 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78329 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78330 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78331 +#else
78332 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78333 +#endif
78334 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78335 + }
78336 #endif
78337 return 0;
78338 }
78339 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78340 index ee07072..593e3fd 100644
78341 --- a/net/8021q/vlan.c
78342 +++ b/net/8021q/vlan.c
78343 @@ -484,7 +484,7 @@ out:
78344 return NOTIFY_DONE;
78345 }
78346
78347 -static struct notifier_block vlan_notifier_block __read_mostly = {
78348 +static struct notifier_block vlan_notifier_block = {
78349 .notifier_call = vlan_device_event,
78350 };
78351
78352 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78353 err = -EPERM;
78354 if (!capable(CAP_NET_ADMIN))
78355 break;
78356 - if ((args.u.name_type >= 0) &&
78357 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78358 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78359 struct vlan_net *vn;
78360
78361 vn = net_generic(net, vlan_net_id);
78362 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78363 index 02efb25..41541a9 100644
78364 --- a/net/9p/trans_fd.c
78365 +++ b/net/9p/trans_fd.c
78366 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78367 oldfs = get_fs();
78368 set_fs(get_ds());
78369 /* The cast to a user pointer is valid due to the set_fs() */
78370 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78371 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78372 set_fs(oldfs);
78373
78374 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78375 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78376 index 876fbe8..8bbea9f 100644
78377 --- a/net/atm/atm_misc.c
78378 +++ b/net/atm/atm_misc.c
78379 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78380 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78381 return 1;
78382 atm_return(vcc, truesize);
78383 - atomic_inc(&vcc->stats->rx_drop);
78384 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78385 return 0;
78386 }
78387 EXPORT_SYMBOL(atm_charge);
78388 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78389 }
78390 }
78391 atm_return(vcc, guess);
78392 - atomic_inc(&vcc->stats->rx_drop);
78393 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78394 return NULL;
78395 }
78396 EXPORT_SYMBOL(atm_alloc_charge);
78397 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78398
78399 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78400 {
78401 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78402 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78403 __SONET_ITEMS
78404 #undef __HANDLE_ITEM
78405 }
78406 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78407
78408 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78409 {
78410 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78411 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78412 __SONET_ITEMS
78413 #undef __HANDLE_ITEM
78414 }
78415 diff --git a/net/atm/lec.h b/net/atm/lec.h
78416 index a86aff9..3a0d6f6 100644
78417 --- a/net/atm/lec.h
78418 +++ b/net/atm/lec.h
78419 @@ -48,7 +48,7 @@ struct lane2_ops {
78420 const u8 *tlvs, u32 sizeoftlvs);
78421 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78422 const u8 *tlvs, u32 sizeoftlvs);
78423 -};
78424 +} __no_const;
78425
78426 /*
78427 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78428 diff --git a/net/atm/proc.c b/net/atm/proc.c
78429 index 0d020de..011c7bb 100644
78430 --- a/net/atm/proc.c
78431 +++ b/net/atm/proc.c
78432 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78433 const struct k_atm_aal_stats *stats)
78434 {
78435 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78436 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78437 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78438 - atomic_read(&stats->rx_drop));
78439 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78440 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78441 + atomic_read_unchecked(&stats->rx_drop));
78442 }
78443
78444 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78445 diff --git a/net/atm/resources.c b/net/atm/resources.c
78446 index 0447d5d..3cf4728 100644
78447 --- a/net/atm/resources.c
78448 +++ b/net/atm/resources.c
78449 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78450 static void copy_aal_stats(struct k_atm_aal_stats *from,
78451 struct atm_aal_stats *to)
78452 {
78453 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78454 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78455 __AAL_STAT_ITEMS
78456 #undef __HANDLE_ITEM
78457 }
78458 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78459 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78460 struct atm_aal_stats *to)
78461 {
78462 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78463 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78464 __AAL_STAT_ITEMS
78465 #undef __HANDLE_ITEM
78466 }
78467 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78468 index c6fcc76..1270d14 100644
78469 --- a/net/batman-adv/bat_iv_ogm.c
78470 +++ b/net/batman-adv/bat_iv_ogm.c
78471 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78472
78473 /* randomize initial seqno to avoid collision */
78474 get_random_bytes(&random_seqno, sizeof(random_seqno));
78475 - atomic_set(&hard_iface->seqno, random_seqno);
78476 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78477
78478 hard_iface->packet_len = BATADV_OGM_HLEN;
78479 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78480 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78481 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78482
78483 /* change sequence number to network order */
78484 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78485 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78486 batadv_ogm_packet->seqno = htonl(seqno);
78487 - atomic_inc(&hard_iface->seqno);
78488 + atomic_inc_unchecked(&hard_iface->seqno);
78489
78490 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78491 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78492 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78493 return;
78494
78495 /* could be changed by schedule_own_packet() */
78496 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
78497 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78498
78499 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78500 has_directlink_flag = 1;
78501 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78502 index d112fd6..686a447 100644
78503 --- a/net/batman-adv/hard-interface.c
78504 +++ b/net/batman-adv/hard-interface.c
78505 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78506 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78507 dev_add_pack(&hard_iface->batman_adv_ptype);
78508
78509 - atomic_set(&hard_iface->frag_seqno, 1);
78510 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78511 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78512 hard_iface->net_dev->name);
78513
78514 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78515 /* This can't be called via a bat_priv callback because
78516 * we have no bat_priv yet.
78517 */
78518 - atomic_set(&hard_iface->seqno, 1);
78519 + atomic_set_unchecked(&hard_iface->seqno, 1);
78520 hard_iface->packet_buff = NULL;
78521
78522 return hard_iface;
78523 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78524 index ce0684a..4a0cbf1 100644
78525 --- a/net/batman-adv/soft-interface.c
78526 +++ b/net/batman-adv/soft-interface.c
78527 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78528 primary_if->net_dev->dev_addr, ETH_ALEN);
78529
78530 /* set broadcast sequence number */
78531 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78532 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78533 bcast_packet->seqno = htonl(seqno);
78534
78535 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78536 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78537 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78538
78539 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78540 - atomic_set(&bat_priv->bcast_seqno, 1);
78541 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78542 atomic_set(&bat_priv->tt.vn, 0);
78543 atomic_set(&bat_priv->tt.local_changes, 0);
78544 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78545 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78546 index ac1e07a..4c846e2 100644
78547 --- a/net/batman-adv/types.h
78548 +++ b/net/batman-adv/types.h
78549 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
78550 int16_t if_num;
78551 char if_status;
78552 struct net_device *net_dev;
78553 - atomic_t seqno;
78554 - atomic_t frag_seqno;
78555 + atomic_unchecked_t seqno;
78556 + atomic_unchecked_t frag_seqno;
78557 unsigned char *packet_buff;
78558 int packet_len;
78559 struct kobject *hardif_obj;
78560 @@ -244,7 +244,7 @@ struct batadv_priv {
78561 atomic_t orig_interval; /* uint */
78562 atomic_t hop_penalty; /* uint */
78563 atomic_t log_level; /* uint */
78564 - atomic_t bcast_seqno;
78565 + atomic_unchecked_t bcast_seqno;
78566 atomic_t bcast_queue_left;
78567 atomic_t batman_queue_left;
78568 char num_ifaces;
78569 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78570 index f397232..3206a33 100644
78571 --- a/net/batman-adv/unicast.c
78572 +++ b/net/batman-adv/unicast.c
78573 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78574 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78575 frag2->flags = large_tail;
78576
78577 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78578 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78579 frag1->seqno = htons(seqno - 1);
78580 frag2->seqno = htons(seqno);
78581
78582 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78583 index 07f0739..3c42e34 100644
78584 --- a/net/bluetooth/hci_sock.c
78585 +++ b/net/bluetooth/hci_sock.c
78586 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78587 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78588 }
78589
78590 - len = min_t(unsigned int, len, sizeof(uf));
78591 + len = min((size_t)len, sizeof(uf));
78592 if (copy_from_user(&uf, optval, len)) {
78593 err = -EFAULT;
78594 break;
78595 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78596 index a91239d..d7ed533 100644
78597 --- a/net/bluetooth/l2cap_core.c
78598 +++ b/net/bluetooth/l2cap_core.c
78599 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78600 break;
78601
78602 case L2CAP_CONF_RFC:
78603 - if (olen == sizeof(rfc))
78604 - memcpy(&rfc, (void *)val, olen);
78605 + if (olen != sizeof(rfc))
78606 + break;
78607 +
78608 + memcpy(&rfc, (void *)val, olen);
78609
78610 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78611 rfc.mode != chan->mode)
78612 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78613 index 083f2bf..799f9448 100644
78614 --- a/net/bluetooth/l2cap_sock.c
78615 +++ b/net/bluetooth/l2cap_sock.c
78616 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78617 struct sock *sk = sock->sk;
78618 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78619 struct l2cap_options opts;
78620 - int len, err = 0;
78621 + int err = 0;
78622 + size_t len = optlen;
78623 u32 opt;
78624
78625 BT_DBG("sk %p", sk);
78626 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78627 opts.max_tx = chan->max_tx;
78628 opts.txwin_size = chan->tx_win;
78629
78630 - len = min_t(unsigned int, sizeof(opts), optlen);
78631 + len = min(sizeof(opts), len);
78632 if (copy_from_user((char *) &opts, optval, len)) {
78633 err = -EFAULT;
78634 break;
78635 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78636 struct bt_security sec;
78637 struct bt_power pwr;
78638 struct l2cap_conn *conn;
78639 - int len, err = 0;
78640 + int err = 0;
78641 + size_t len = optlen;
78642 u32 opt;
78643
78644 BT_DBG("sk %p", sk);
78645 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78646
78647 sec.level = BT_SECURITY_LOW;
78648
78649 - len = min_t(unsigned int, sizeof(sec), optlen);
78650 + len = min(sizeof(sec), len);
78651 if (copy_from_user((char *) &sec, optval, len)) {
78652 err = -EFAULT;
78653 break;
78654 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78655
78656 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78657
78658 - len = min_t(unsigned int, sizeof(pwr), optlen);
78659 + len = min(sizeof(pwr), len);
78660 if (copy_from_user((char *) &pwr, optval, len)) {
78661 err = -EFAULT;
78662 break;
78663 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78664 index 868a909..d044bc3 100644
78665 --- a/net/bluetooth/rfcomm/sock.c
78666 +++ b/net/bluetooth/rfcomm/sock.c
78667 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78668 struct sock *sk = sock->sk;
78669 struct bt_security sec;
78670 int err = 0;
78671 - size_t len;
78672 + size_t len = optlen;
78673 u32 opt;
78674
78675 BT_DBG("sk %p", sk);
78676 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78677
78678 sec.level = BT_SECURITY_LOW;
78679
78680 - len = min_t(unsigned int, sizeof(sec), optlen);
78681 + len = min(sizeof(sec), len);
78682 if (copy_from_user((char *) &sec, optval, len)) {
78683 err = -EFAULT;
78684 break;
78685 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78686 index ccc2487..921073d 100644
78687 --- a/net/bluetooth/rfcomm/tty.c
78688 +++ b/net/bluetooth/rfcomm/tty.c
78689 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78690 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78691
78692 spin_lock_irqsave(&dev->port.lock, flags);
78693 - if (dev->port.count > 0) {
78694 + if (atomic_read(&dev->port.count) > 0) {
78695 spin_unlock_irqrestore(&dev->port.lock, flags);
78696 return;
78697 }
78698 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78699 return -ENODEV;
78700
78701 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78702 - dev->channel, dev->port.count);
78703 + dev->channel, atomic_read(&dev->port.count));
78704
78705 spin_lock_irqsave(&dev->port.lock, flags);
78706 - if (++dev->port.count > 1) {
78707 + if (atomic_inc_return(&dev->port.count) > 1) {
78708 spin_unlock_irqrestore(&dev->port.lock, flags);
78709 return 0;
78710 }
78711 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78712 return;
78713
78714 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78715 - dev->port.count);
78716 + atomic_read(&dev->port.count));
78717
78718 spin_lock_irqsave(&dev->port.lock, flags);
78719 - if (!--dev->port.count) {
78720 + if (!atomic_dec_return(&dev->port.count)) {
78721 spin_unlock_irqrestore(&dev->port.lock, flags);
78722 if (dev->tty_dev->parent)
78723 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78724 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78725 index 5fe2ff3..121d696 100644
78726 --- a/net/bridge/netfilter/ebtables.c
78727 +++ b/net/bridge/netfilter/ebtables.c
78728 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78729 tmp.valid_hooks = t->table->valid_hooks;
78730 }
78731 mutex_unlock(&ebt_mutex);
78732 - if (copy_to_user(user, &tmp, *len) != 0){
78733 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78734 BUGPRINT("c2u Didn't work\n");
78735 ret = -EFAULT;
78736 break;
78737 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78738 goto out;
78739 tmp.valid_hooks = t->valid_hooks;
78740
78741 - if (copy_to_user(user, &tmp, *len) != 0) {
78742 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78743 ret = -EFAULT;
78744 break;
78745 }
78746 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78747 tmp.entries_size = t->table->entries_size;
78748 tmp.valid_hooks = t->table->valid_hooks;
78749
78750 - if (copy_to_user(user, &tmp, *len) != 0) {
78751 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78752 ret = -EFAULT;
78753 break;
78754 }
78755 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78756 index 44f270f..1f5602d 100644
78757 --- a/net/caif/cfctrl.c
78758 +++ b/net/caif/cfctrl.c
78759 @@ -10,6 +10,7 @@
78760 #include <linux/spinlock.h>
78761 #include <linux/slab.h>
78762 #include <linux/pkt_sched.h>
78763 +#include <linux/sched.h>
78764 #include <net/caif/caif_layer.h>
78765 #include <net/caif/cfpkt.h>
78766 #include <net/caif/cfctrl.h>
78767 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78768 memset(&dev_info, 0, sizeof(dev_info));
78769 dev_info.id = 0xff;
78770 cfsrvl_init(&this->serv, 0, &dev_info, false);
78771 - atomic_set(&this->req_seq_no, 1);
78772 - atomic_set(&this->rsp_seq_no, 1);
78773 + atomic_set_unchecked(&this->req_seq_no, 1);
78774 + atomic_set_unchecked(&this->rsp_seq_no, 1);
78775 this->serv.layer.receive = cfctrl_recv;
78776 sprintf(this->serv.layer.name, "ctrl");
78777 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78778 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78779 struct cfctrl_request_info *req)
78780 {
78781 spin_lock_bh(&ctrl->info_list_lock);
78782 - atomic_inc(&ctrl->req_seq_no);
78783 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
78784 + atomic_inc_unchecked(&ctrl->req_seq_no);
78785 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78786 list_add_tail(&req->list, &ctrl->list);
78787 spin_unlock_bh(&ctrl->info_list_lock);
78788 }
78789 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78790 if (p != first)
78791 pr_warn("Requests are not received in order\n");
78792
78793 - atomic_set(&ctrl->rsp_seq_no,
78794 + atomic_set_unchecked(&ctrl->rsp_seq_no,
78795 p->sequence_no);
78796 list_del(&p->list);
78797 goto out;
78798 diff --git a/net/can/af_can.c b/net/can/af_can.c
78799 index ddac1ee..3ee0a78 100644
78800 --- a/net/can/af_can.c
78801 +++ b/net/can/af_can.c
78802 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78803 };
78804
78805 /* notifier block for netdevice event */
78806 -static struct notifier_block can_netdev_notifier __read_mostly = {
78807 +static struct notifier_block can_netdev_notifier = {
78808 .notifier_call = can_notifier,
78809 };
78810
78811 diff --git a/net/can/gw.c b/net/can/gw.c
78812 index 1f5c978..ef714c7 100644
78813 --- a/net/can/gw.c
78814 +++ b/net/can/gw.c
78815 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78816 MODULE_ALIAS("can-gw");
78817
78818 static HLIST_HEAD(cgw_list);
78819 -static struct notifier_block notifier;
78820
78821 static struct kmem_cache *cgw_cache __read_mostly;
78822
78823 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78824 return err;
78825 }
78826
78827 +static struct notifier_block notifier = {
78828 + .notifier_call = cgw_notifier
78829 +};
78830 +
78831 static __init int cgw_module_init(void)
78832 {
78833 printk(banner);
78834 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78835 return -ENOMEM;
78836
78837 /* set notifier */
78838 - notifier.notifier_call = cgw_notifier;
78839 register_netdevice_notifier(&notifier);
78840
78841 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78842 diff --git a/net/compat.c b/net/compat.c
78843 index 79ae884..17c5c09 100644
78844 --- a/net/compat.c
78845 +++ b/net/compat.c
78846 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78847 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78848 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78849 return -EFAULT;
78850 - kmsg->msg_name = compat_ptr(tmp1);
78851 - kmsg->msg_iov = compat_ptr(tmp2);
78852 - kmsg->msg_control = compat_ptr(tmp3);
78853 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
78854 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
78855 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
78856 return 0;
78857 }
78858
78859 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78860
78861 if (kern_msg->msg_namelen) {
78862 if (mode == VERIFY_READ) {
78863 - int err = move_addr_to_kernel(kern_msg->msg_name,
78864 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
78865 kern_msg->msg_namelen,
78866 kern_address);
78867 if (err < 0)
78868 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78869 kern_msg->msg_name = NULL;
78870
78871 tot_len = iov_from_user_compat_to_kern(kern_iov,
78872 - (struct compat_iovec __user *)kern_msg->msg_iov,
78873 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
78874 kern_msg->msg_iovlen);
78875 if (tot_len >= 0)
78876 kern_msg->msg_iov = kern_iov;
78877 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78878
78879 #define CMSG_COMPAT_FIRSTHDR(msg) \
78880 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
78881 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
78882 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
78883 (struct compat_cmsghdr __user *)NULL)
78884
78885 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
78886 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
78887 (ucmlen) <= (unsigned long) \
78888 ((mhdr)->msg_controllen - \
78889 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
78890 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
78891
78892 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
78893 struct compat_cmsghdr __user *cmsg, int cmsg_len)
78894 {
78895 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
78896 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
78897 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
78898 msg->msg_controllen)
78899 return NULL;
78900 return (struct compat_cmsghdr __user *)ptr;
78901 @@ -219,7 +219,7 @@ Efault:
78902
78903 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
78904 {
78905 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78906 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78907 struct compat_cmsghdr cmhdr;
78908 struct compat_timeval ctv;
78909 struct compat_timespec cts[3];
78910 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
78911
78912 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
78913 {
78914 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78915 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78916 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
78917 int fdnum = scm->fp->count;
78918 struct file **fp = scm->fp->fp;
78919 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
78920 return -EFAULT;
78921 old_fs = get_fs();
78922 set_fs(KERNEL_DS);
78923 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
78924 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
78925 set_fs(old_fs);
78926
78927 return err;
78928 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
78929 len = sizeof(ktime);
78930 old_fs = get_fs();
78931 set_fs(KERNEL_DS);
78932 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
78933 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
78934 set_fs(old_fs);
78935
78936 if (!err) {
78937 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78938 case MCAST_JOIN_GROUP:
78939 case MCAST_LEAVE_GROUP:
78940 {
78941 - struct compat_group_req __user *gr32 = (void *)optval;
78942 + struct compat_group_req __user *gr32 = (void __user *)optval;
78943 struct group_req __user *kgr =
78944 compat_alloc_user_space(sizeof(struct group_req));
78945 u32 interface;
78946 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78947 case MCAST_BLOCK_SOURCE:
78948 case MCAST_UNBLOCK_SOURCE:
78949 {
78950 - struct compat_group_source_req __user *gsr32 = (void *)optval;
78951 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
78952 struct group_source_req __user *kgsr = compat_alloc_user_space(
78953 sizeof(struct group_source_req));
78954 u32 interface;
78955 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78956 }
78957 case MCAST_MSFILTER:
78958 {
78959 - struct compat_group_filter __user *gf32 = (void *)optval;
78960 + struct compat_group_filter __user *gf32 = (void __user *)optval;
78961 struct group_filter __user *kgf;
78962 u32 interface, fmode, numsrc;
78963
78964 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
78965 char __user *optval, int __user *optlen,
78966 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
78967 {
78968 - struct compat_group_filter __user *gf32 = (void *)optval;
78969 + struct compat_group_filter __user *gf32 = (void __user *)optval;
78970 struct group_filter __user *kgf;
78971 int __user *koptlen;
78972 u32 interface, fmode, numsrc;
78973 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
78974
78975 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
78976 return -EINVAL;
78977 - if (copy_from_user(a, args, nas[call]))
78978 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
78979 return -EFAULT;
78980 a0 = a[0];
78981 a1 = a[1];
78982 diff --git a/net/core/datagram.c b/net/core/datagram.c
78983 index 0337e2b..f82d4a3 100644
78984 --- a/net/core/datagram.c
78985 +++ b/net/core/datagram.c
78986 @@ -187,7 +187,7 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned int flags,
78987 skb_queue_walk(queue, skb) {
78988 *peeked = skb->peeked;
78989 if (flags & MSG_PEEK) {
78990 - if (*off >= skb->len) {
78991 + if (*off >= skb->len && skb->len) {
78992 *off -= skb->len;
78993 continue;
78994 }
78995 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
78996 }
78997
78998 kfree_skb(skb);
78999 - atomic_inc(&sk->sk_drops);
79000 + atomic_inc_unchecked(&sk->sk_drops);
79001 sk_mem_reclaim_partial(sk);
79002
79003 return err;
79004 diff --git a/net/core/dev.c b/net/core/dev.c
79005 index 3470794..eb5008c 100644
79006 --- a/net/core/dev.c
79007 +++ b/net/core/dev.c
79008 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79009 if (no_module && capable(CAP_NET_ADMIN))
79010 no_module = request_module("netdev-%s", name);
79011 if (no_module && capable(CAP_SYS_MODULE)) {
79012 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
79013 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
79014 +#else
79015 if (!request_module("%s", name))
79016 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79017 name);
79018 +#endif
79019 }
79020 }
79021 EXPORT_SYMBOL(dev_load);
79022 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79023 {
79024 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79025 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79026 - atomic_long_inc(&dev->rx_dropped);
79027 + atomic_long_inc_unchecked(&dev->rx_dropped);
79028 kfree_skb(skb);
79029 return NET_RX_DROP;
79030 }
79031 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79032 nf_reset(skb);
79033
79034 if (unlikely(!is_skb_forwardable(dev, skb))) {
79035 - atomic_long_inc(&dev->rx_dropped);
79036 + atomic_long_inc_unchecked(&dev->rx_dropped);
79037 kfree_skb(skb);
79038 return NET_RX_DROP;
79039 }
79040 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79041
79042 struct dev_gso_cb {
79043 void (*destructor)(struct sk_buff *skb);
79044 -};
79045 +} __no_const;
79046
79047 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79048
79049 @@ -2955,7 +2959,7 @@ enqueue:
79050
79051 local_irq_restore(flags);
79052
79053 - atomic_long_inc(&skb->dev->rx_dropped);
79054 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79055 kfree_skb(skb);
79056 return NET_RX_DROP;
79057 }
79058 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79059 }
79060 EXPORT_SYMBOL(netif_rx_ni);
79061
79062 -static void net_tx_action(struct softirq_action *h)
79063 +static void net_tx_action(void)
79064 {
79065 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79066
79067 @@ -3358,7 +3362,7 @@ ncls:
79068 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79069 } else {
79070 drop:
79071 - atomic_long_inc(&skb->dev->rx_dropped);
79072 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79073 kfree_skb(skb);
79074 /* Jamal, now you will not able to escape explaining
79075 * me how you were going to use this. :-)
79076 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79077 }
79078 EXPORT_SYMBOL(netif_napi_del);
79079
79080 -static void net_rx_action(struct softirq_action *h)
79081 +static void net_rx_action(void)
79082 {
79083 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79084 unsigned long time_limit = jiffies + 2;
79085 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79086 else
79087 seq_printf(seq, "%04x", ntohs(pt->type));
79088
79089 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79090 + seq_printf(seq, " %-8s %p\n",
79091 + pt->dev ? pt->dev->name : "", NULL);
79092 +#else
79093 seq_printf(seq, " %-8s %pF\n",
79094 pt->dev ? pt->dev->name : "", pt->func);
79095 +#endif
79096 }
79097
79098 return 0;
79099 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79100 } else {
79101 netdev_stats_to_stats64(storage, &dev->stats);
79102 }
79103 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79104 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79105 return storage;
79106 }
79107 EXPORT_SYMBOL(dev_get_stats);
79108 diff --git a/net/core/flow.c b/net/core/flow.c
79109 index e318c7e..168b1d0 100644
79110 --- a/net/core/flow.c
79111 +++ b/net/core/flow.c
79112 @@ -61,7 +61,7 @@ struct flow_cache {
79113 struct timer_list rnd_timer;
79114 };
79115
79116 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
79117 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79118 EXPORT_SYMBOL(flow_cache_genid);
79119 static struct flow_cache flow_cache_global;
79120 static struct kmem_cache *flow_cachep __read_mostly;
79121 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79122
79123 static int flow_entry_valid(struct flow_cache_entry *fle)
79124 {
79125 - if (atomic_read(&flow_cache_genid) != fle->genid)
79126 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79127 return 0;
79128 if (fle->object && !fle->object->ops->check(fle->object))
79129 return 0;
79130 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79131 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79132 fcp->hash_count++;
79133 }
79134 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79135 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79136 flo = fle->object;
79137 if (!flo)
79138 goto ret_object;
79139 @@ -280,7 +280,7 @@ nocache:
79140 }
79141 flo = resolver(net, key, family, dir, flo, ctx);
79142 if (fle) {
79143 - fle->genid = atomic_read(&flow_cache_genid);
79144 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
79145 if (!IS_ERR(flo))
79146 fle->object = flo;
79147 else
79148 diff --git a/net/core/iovec.c b/net/core/iovec.c
79149 index 7e7aeb0..2a998cb 100644
79150 --- a/net/core/iovec.c
79151 +++ b/net/core/iovec.c
79152 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79153 if (m->msg_namelen) {
79154 if (mode == VERIFY_READ) {
79155 void __user *namep;
79156 - namep = (void __user __force *) m->msg_name;
79157 + namep = (void __force_user *) m->msg_name;
79158 err = move_addr_to_kernel(namep, m->msg_namelen,
79159 address);
79160 if (err < 0)
79161 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79162 }
79163
79164 size = m->msg_iovlen * sizeof(struct iovec);
79165 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79166 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79167 return -EFAULT;
79168
79169 m->msg_iov = iov;
79170 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79171 index fad649a..df5891e 100644
79172 --- a/net/core/rtnetlink.c
79173 +++ b/net/core/rtnetlink.c
79174 @@ -58,7 +58,7 @@ struct rtnl_link {
79175 rtnl_doit_func doit;
79176 rtnl_dumpit_func dumpit;
79177 rtnl_calcit_func calcit;
79178 -};
79179 +} __no_const;
79180
79181 static DEFINE_MUTEX(rtnl_mutex);
79182
79183 diff --git a/net/core/scm.c b/net/core/scm.c
79184 index ab57084..0190c8f 100644
79185 --- a/net/core/scm.c
79186 +++ b/net/core/scm.c
79187 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79188 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79189 {
79190 struct cmsghdr __user *cm
79191 - = (__force struct cmsghdr __user *)msg->msg_control;
79192 + = (struct cmsghdr __force_user *)msg->msg_control;
79193 struct cmsghdr cmhdr;
79194 int cmlen = CMSG_LEN(len);
79195 int err;
79196 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79197 err = -EFAULT;
79198 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79199 goto out;
79200 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79201 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79202 goto out;
79203 cmlen = CMSG_SPACE(len);
79204 if (msg->msg_controllen < cmlen)
79205 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79206 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79207 {
79208 struct cmsghdr __user *cm
79209 - = (__force struct cmsghdr __user*)msg->msg_control;
79210 + = (struct cmsghdr __force_user *)msg->msg_control;
79211
79212 int fdmax = 0;
79213 int fdnum = scm->fp->count;
79214 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79215 if (fdnum < fdmax)
79216 fdmax = fdnum;
79217
79218 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79219 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79220 i++, cmfptr++)
79221 {
79222 struct socket *sock;
79223 diff --git a/net/core/sock.c b/net/core/sock.c
79224 index 8a146cf..ee08914d 100644
79225 --- a/net/core/sock.c
79226 +++ b/net/core/sock.c
79227 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79228 struct sk_buff_head *list = &sk->sk_receive_queue;
79229
79230 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79231 - atomic_inc(&sk->sk_drops);
79232 + atomic_inc_unchecked(&sk->sk_drops);
79233 trace_sock_rcvqueue_full(sk, skb);
79234 return -ENOMEM;
79235 }
79236 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79237 return err;
79238
79239 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79240 - atomic_inc(&sk->sk_drops);
79241 + atomic_inc_unchecked(&sk->sk_drops);
79242 return -ENOBUFS;
79243 }
79244
79245 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79246 skb_dst_force(skb);
79247
79248 spin_lock_irqsave(&list->lock, flags);
79249 - skb->dropcount = atomic_read(&sk->sk_drops);
79250 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79251 __skb_queue_tail(list, skb);
79252 spin_unlock_irqrestore(&list->lock, flags);
79253
79254 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79255 skb->dev = NULL;
79256
79257 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79258 - atomic_inc(&sk->sk_drops);
79259 + atomic_inc_unchecked(&sk->sk_drops);
79260 goto discard_and_relse;
79261 }
79262 if (nested)
79263 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79264 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79265 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79266 bh_unlock_sock(sk);
79267 - atomic_inc(&sk->sk_drops);
79268 + atomic_inc_unchecked(&sk->sk_drops);
79269 goto discard_and_relse;
79270 }
79271
79272 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79273 struct timeval tm;
79274 } v;
79275
79276 - int lv = sizeof(int);
79277 - int len;
79278 + unsigned int lv = sizeof(int);
79279 + unsigned int len;
79280
79281 if (get_user(len, optlen))
79282 return -EFAULT;
79283 - if (len < 0)
79284 + if (len > INT_MAX)
79285 return -EINVAL;
79286
79287 memset(&v, 0, sizeof(v));
79288 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79289
79290 case SO_PEERNAME:
79291 {
79292 - char address[128];
79293 + char address[_K_SS_MAXSIZE];
79294
79295 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79296 return -ENOTCONN;
79297 - if (lv < len)
79298 + if (lv < len || sizeof address < len)
79299 return -EINVAL;
79300 if (copy_to_user(optval, address, len))
79301 return -EFAULT;
79302 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79303
79304 if (len > lv)
79305 len = lv;
79306 - if (copy_to_user(optval, &v, len))
79307 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
79308 return -EFAULT;
79309 lenout:
79310 if (put_user(len, optlen))
79311 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79312 */
79313 smp_wmb();
79314 atomic_set(&sk->sk_refcnt, 1);
79315 - atomic_set(&sk->sk_drops, 0);
79316 + atomic_set_unchecked(&sk->sk_drops, 0);
79317 }
79318 EXPORT_SYMBOL(sock_init_data);
79319
79320 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79321 index 602cd63..05c6c60 100644
79322 --- a/net/core/sock_diag.c
79323 +++ b/net/core/sock_diag.c
79324 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79325
79326 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79327 {
79328 +#ifndef CONFIG_GRKERNSEC_HIDESYM
79329 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79330 cookie[1] != INET_DIAG_NOCOOKIE) &&
79331 ((u32)(unsigned long)sk != cookie[0] ||
79332 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79333 return -ESTALE;
79334 else
79335 +#endif
79336 return 0;
79337 }
79338 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79339
79340 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79341 {
79342 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79343 + cookie[0] = 0;
79344 + cookie[1] = 0;
79345 +#else
79346 cookie[0] = (u32)(unsigned long)sk;
79347 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79348 +#endif
79349 }
79350 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79351
79352 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79353 index a55eecc..dd8428c 100644
79354 --- a/net/decnet/sysctl_net_decnet.c
79355 +++ b/net/decnet/sysctl_net_decnet.c
79356 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79357
79358 if (len > *lenp) len = *lenp;
79359
79360 - if (copy_to_user(buffer, addr, len))
79361 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
79362 return -EFAULT;
79363
79364 *lenp = len;
79365 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79366
79367 if (len > *lenp) len = *lenp;
79368
79369 - if (copy_to_user(buffer, devname, len))
79370 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
79371 return -EFAULT;
79372
79373 *lenp = len;
79374 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79375 index 2a6abc1..c379ba7 100644
79376 --- a/net/ipv4/devinet.c
79377 +++ b/net/ipv4/devinet.c
79378 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79379 if (!ifa) {
79380 ret = -ENOBUFS;
79381 ifa = inet_alloc_ifa();
79382 + if (!ifa)
79383 + break;
79384 INIT_HLIST_NODE(&ifa->hash);
79385 - if (!ifa)
79386 - break;
79387 if (colon)
79388 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79389 else
79390 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79391 index 825c608..750ff29 100644
79392 --- a/net/ipv4/fib_frontend.c
79393 +++ b/net/ipv4/fib_frontend.c
79394 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79395 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79396 fib_sync_up(dev);
79397 #endif
79398 - atomic_inc(&net->ipv4.dev_addr_genid);
79399 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79400 rt_cache_flush(dev_net(dev));
79401 break;
79402 case NETDEV_DOWN:
79403 fib_del_ifaddr(ifa, NULL);
79404 - atomic_inc(&net->ipv4.dev_addr_genid);
79405 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79406 if (ifa->ifa_dev->ifa_list == NULL) {
79407 /* Last address was deleted from this interface.
79408 * Disable IP.
79409 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79410 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79411 fib_sync_up(dev);
79412 #endif
79413 - atomic_inc(&net->ipv4.dev_addr_genid);
79414 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79415 rt_cache_flush(net);
79416 break;
79417 case NETDEV_DOWN:
79418 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79419 index 71b125c..f4c70b0 100644
79420 --- a/net/ipv4/fib_semantics.c
79421 +++ b/net/ipv4/fib_semantics.c
79422 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79423 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79424 nh->nh_gw,
79425 nh->nh_parent->fib_scope);
79426 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79427 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79428
79429 return nh->nh_saddr;
79430 }
79431 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79432 index 7880af9..70f92a3 100644
79433 --- a/net/ipv4/inet_hashtables.c
79434 +++ b/net/ipv4/inet_hashtables.c
79435 @@ -18,12 +18,15 @@
79436 #include <linux/sched.h>
79437 #include <linux/slab.h>
79438 #include <linux/wait.h>
79439 +#include <linux/security.h>
79440
79441 #include <net/inet_connection_sock.h>
79442 #include <net/inet_hashtables.h>
79443 #include <net/secure_seq.h>
79444 #include <net/ip.h>
79445
79446 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79447 +
79448 /*
79449 * Allocate and initialize a new local port bind bucket.
79450 * The bindhash mutex for snum's hash chain must be held here.
79451 @@ -530,6 +533,8 @@ ok:
79452 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79453 spin_unlock(&head->lock);
79454
79455 + gr_update_task_in_ip_table(current, inet_sk(sk));
79456 +
79457 if (tw) {
79458 inet_twsk_deschedule(tw, death_row);
79459 while (twrefcnt) {
79460 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79461 index 000e3d2..5472da3 100644
79462 --- a/net/ipv4/inetpeer.c
79463 +++ b/net/ipv4/inetpeer.c
79464 @@ -503,8 +503,8 @@ relookup:
79465 if (p) {
79466 p->daddr = *daddr;
79467 atomic_set(&p->refcnt, 1);
79468 - atomic_set(&p->rid, 0);
79469 - atomic_set(&p->ip_id_count,
79470 + atomic_set_unchecked(&p->rid, 0);
79471 + atomic_set_unchecked(&p->ip_id_count,
79472 (daddr->family == AF_INET) ?
79473 secure_ip_id(daddr->addr.a4) :
79474 secure_ipv6_id(daddr->addr.a6));
79475 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79476 index 8d5cc75..821fd11 100644
79477 --- a/net/ipv4/ip_fragment.c
79478 +++ b/net/ipv4/ip_fragment.c
79479 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79480 return 0;
79481
79482 start = qp->rid;
79483 - end = atomic_inc_return(&peer->rid);
79484 + end = atomic_inc_return_unchecked(&peer->rid);
79485 qp->rid = end;
79486
79487 rc = qp->q.fragments && (end - start) > max;
79488 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79489 index e95d72b..5268ac0 100644
79490 --- a/net/ipv4/ip_sockglue.c
79491 +++ b/net/ipv4/ip_sockglue.c
79492 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79493 len = min_t(unsigned int, len, opt->optlen);
79494 if (put_user(len, optlen))
79495 return -EFAULT;
79496 - if (copy_to_user(optval, opt->__data, len))
79497 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79498 + copy_to_user(optval, opt->__data, len))
79499 return -EFAULT;
79500 return 0;
79501 }
79502 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79503 if (sk->sk_type != SOCK_STREAM)
79504 return -ENOPROTOOPT;
79505
79506 - msg.msg_control = optval;
79507 + msg.msg_control = (void __force_kernel *)optval;
79508 msg.msg_controllen = len;
79509 msg.msg_flags = flags;
79510
79511 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79512 index 798358b..73570b7 100644
79513 --- a/net/ipv4/ipconfig.c
79514 +++ b/net/ipv4/ipconfig.c
79515 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79516
79517 mm_segment_t oldfs = get_fs();
79518 set_fs(get_ds());
79519 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79520 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79521 set_fs(oldfs);
79522 return res;
79523 }
79524 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79525
79526 mm_segment_t oldfs = get_fs();
79527 set_fs(get_ds());
79528 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79529 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79530 set_fs(oldfs);
79531 return res;
79532 }
79533 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79534
79535 mm_segment_t oldfs = get_fs();
79536 set_fs(get_ds());
79537 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79538 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79539 set_fs(oldfs);
79540 return res;
79541 }
79542 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79543 index 97e61ea..cac1bbb 100644
79544 --- a/net/ipv4/netfilter/arp_tables.c
79545 +++ b/net/ipv4/netfilter/arp_tables.c
79546 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79547 #endif
79548
79549 static int get_info(struct net *net, void __user *user,
79550 - const int *len, int compat)
79551 + int len, int compat)
79552 {
79553 char name[XT_TABLE_MAXNAMELEN];
79554 struct xt_table *t;
79555 int ret;
79556
79557 - if (*len != sizeof(struct arpt_getinfo)) {
79558 - duprintf("length %u != %Zu\n", *len,
79559 + if (len != sizeof(struct arpt_getinfo)) {
79560 + duprintf("length %u != %Zu\n", len,
79561 sizeof(struct arpt_getinfo));
79562 return -EINVAL;
79563 }
79564 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79565 info.size = private->size;
79566 strcpy(info.name, name);
79567
79568 - if (copy_to_user(user, &info, *len) != 0)
79569 + if (copy_to_user(user, &info, len) != 0)
79570 ret = -EFAULT;
79571 else
79572 ret = 0;
79573 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79574
79575 switch (cmd) {
79576 case ARPT_SO_GET_INFO:
79577 - ret = get_info(sock_net(sk), user, len, 1);
79578 + ret = get_info(sock_net(sk), user, *len, 1);
79579 break;
79580 case ARPT_SO_GET_ENTRIES:
79581 ret = compat_get_entries(sock_net(sk), user, len);
79582 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79583
79584 switch (cmd) {
79585 case ARPT_SO_GET_INFO:
79586 - ret = get_info(sock_net(sk), user, len, 0);
79587 + ret = get_info(sock_net(sk), user, *len, 0);
79588 break;
79589
79590 case ARPT_SO_GET_ENTRIES:
79591 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79592 index 170b1fd..6105b91 100644
79593 --- a/net/ipv4/netfilter/ip_tables.c
79594 +++ b/net/ipv4/netfilter/ip_tables.c
79595 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79596 #endif
79597
79598 static int get_info(struct net *net, void __user *user,
79599 - const int *len, int compat)
79600 + int len, int compat)
79601 {
79602 char name[XT_TABLE_MAXNAMELEN];
79603 struct xt_table *t;
79604 int ret;
79605
79606 - if (*len != sizeof(struct ipt_getinfo)) {
79607 - duprintf("length %u != %zu\n", *len,
79608 + if (len != sizeof(struct ipt_getinfo)) {
79609 + duprintf("length %u != %zu\n", len,
79610 sizeof(struct ipt_getinfo));
79611 return -EINVAL;
79612 }
79613 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79614 info.size = private->size;
79615 strcpy(info.name, name);
79616
79617 - if (copy_to_user(user, &info, *len) != 0)
79618 + if (copy_to_user(user, &info, len) != 0)
79619 ret = -EFAULT;
79620 else
79621 ret = 0;
79622 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79623
79624 switch (cmd) {
79625 case IPT_SO_GET_INFO:
79626 - ret = get_info(sock_net(sk), user, len, 1);
79627 + ret = get_info(sock_net(sk), user, *len, 1);
79628 break;
79629 case IPT_SO_GET_ENTRIES:
79630 ret = compat_get_entries(sock_net(sk), user, len);
79631 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79632
79633 switch (cmd) {
79634 case IPT_SO_GET_INFO:
79635 - ret = get_info(sock_net(sk), user, len, 0);
79636 + ret = get_info(sock_net(sk), user, *len, 0);
79637 break;
79638
79639 case IPT_SO_GET_ENTRIES:
79640 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79641 index 6f9c072..38ea6c6 100644
79642 --- a/net/ipv4/ping.c
79643 +++ b/net/ipv4/ping.c
79644 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79645 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79646 0, sock_i_ino(sp),
79647 atomic_read(&sp->sk_refcnt), sp,
79648 - atomic_read(&sp->sk_drops), len);
79649 + atomic_read_unchecked(&sp->sk_drops), len);
79650 }
79651
79652 static int ping_seq_show(struct seq_file *seq, void *v)
79653 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79654 index 6f08991..55867ad 100644
79655 --- a/net/ipv4/raw.c
79656 +++ b/net/ipv4/raw.c
79657 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79658 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79659 {
79660 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79661 - atomic_inc(&sk->sk_drops);
79662 + atomic_inc_unchecked(&sk->sk_drops);
79663 kfree_skb(skb);
79664 return NET_RX_DROP;
79665 }
79666 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79667
79668 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79669 {
79670 + struct icmp_filter filter;
79671 +
79672 if (optlen > sizeof(struct icmp_filter))
79673 optlen = sizeof(struct icmp_filter);
79674 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79675 + if (copy_from_user(&filter, optval, optlen))
79676 return -EFAULT;
79677 + raw_sk(sk)->filter = filter;
79678 return 0;
79679 }
79680
79681 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79682 {
79683 int len, ret = -EFAULT;
79684 + struct icmp_filter filter;
79685
79686 if (get_user(len, optlen))
79687 goto out;
79688 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79689 if (len > sizeof(struct icmp_filter))
79690 len = sizeof(struct icmp_filter);
79691 ret = -EFAULT;
79692 - if (put_user(len, optlen) ||
79693 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79694 + filter = raw_sk(sk)->filter;
79695 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79696 goto out;
79697 ret = 0;
79698 out: return ret;
79699 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79700 0, 0L, 0,
79701 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79702 0, sock_i_ino(sp),
79703 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79704 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79705 }
79706
79707 static int raw_seq_show(struct seq_file *seq, void *v)
79708 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79709 index 0fdfe4c..e7ea542 100644
79710 --- a/net/ipv4/route.c
79711 +++ b/net/ipv4/route.c
79712 @@ -2579,7 +2579,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79713
79714 static __net_init int rt_genid_init(struct net *net)
79715 {
79716 - atomic_set(&net->rt_genid, 0);
79717 + atomic_set_unchecked(&net->rt_genid, 0);
79718 get_random_bytes(&net->ipv4.dev_addr_genid,
79719 sizeof(net->ipv4.dev_addr_genid));
79720 return 0;
79721 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79722 index beabc80..48a6a10 100644
79723 --- a/net/ipv4/tcp_input.c
79724 +++ b/net/ipv4/tcp_input.c
79725 @@ -4709,7 +4709,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79726 * simplifies code)
79727 */
79728 static void
79729 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79730 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79731 struct sk_buff *head, struct sk_buff *tail,
79732 u32 start, u32 end)
79733 {
79734 @@ -5541,6 +5541,9 @@ slow_path:
79735 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79736 goto csum_error;
79737
79738 + if (!th->ack)
79739 + goto discard;
79740 +
79741 /*
79742 * Standard slow path.
79743 */
79744 @@ -5549,7 +5552,7 @@ slow_path:
79745 return 0;
79746
79747 step5:
79748 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79749 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79750 goto discard;
79751
79752 /* ts_recent update must be made after we are sure that the packet
79753 @@ -5840,6 +5843,7 @@ discard:
79754 tcp_paws_reject(&tp->rx_opt, 0))
79755 goto discard_and_undo;
79756
79757 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79758 if (th->syn) {
79759 /* We see SYN without ACK. It is attempt of
79760 * simultaneous connect with crossed SYNs.
79761 @@ -5890,6 +5894,7 @@ discard:
79762 goto discard;
79763 #endif
79764 }
79765 +#endif
79766 /* "fifth, if neither of the SYN or RST bits is set then
79767 * drop the segment and return."
79768 */
79769 @@ -5934,7 +5939,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79770 goto discard;
79771
79772 if (th->syn) {
79773 - if (th->fin)
79774 + if (th->fin || th->urg || th->psh)
79775 goto discard;
79776 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79777 return 1;
79778 @@ -5981,11 +5986,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79779 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79780 goto discard;
79781 }
79782 +
79783 + if (!th->ack)
79784 + goto discard;
79785 +
79786 if (!tcp_validate_incoming(sk, skb, th, 0))
79787 return 0;
79788
79789 /* step 5: check the ACK field */
79790 - if (th->ack) {
79791 + if (true) {
79792 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79793
79794 switch (sk->sk_state) {
79795 @@ -6135,8 +6144,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79796 }
79797 break;
79798 }
79799 - } else
79800 - goto discard;
79801 + }
79802
79803 /* ts_recent update must be made after we are sure that the packet
79804 * is in window.
79805 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79806 index e637770..364ff02 100644
79807 --- a/net/ipv4/tcp_ipv4.c
79808 +++ b/net/ipv4/tcp_ipv4.c
79809 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79810 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79811
79812
79813 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79814 +extern int grsec_enable_blackhole;
79815 +#endif
79816 +
79817 #ifdef CONFIG_TCP_MD5SIG
79818 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79819 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79820 @@ -1898,6 +1902,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79821 return 0;
79822
79823 reset:
79824 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79825 + if (!grsec_enable_blackhole)
79826 +#endif
79827 tcp_v4_send_reset(rsk, skb);
79828 discard:
79829 kfree_skb(skb);
79830 @@ -1998,12 +2005,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79831 TCP_SKB_CB(skb)->sacked = 0;
79832
79833 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79834 - if (!sk)
79835 + if (!sk) {
79836 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79837 + ret = 1;
79838 +#endif
79839 goto no_tcp_socket;
79840 -
79841 + }
79842 process:
79843 - if (sk->sk_state == TCP_TIME_WAIT)
79844 + if (sk->sk_state == TCP_TIME_WAIT) {
79845 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79846 + ret = 2;
79847 +#endif
79848 goto do_time_wait;
79849 + }
79850
79851 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
79852 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79853 @@ -2054,6 +2068,10 @@ no_tcp_socket:
79854 bad_packet:
79855 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79856 } else {
79857 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79858 + if (!grsec_enable_blackhole || (ret == 1 &&
79859 + (skb->dev->flags & IFF_LOOPBACK)))
79860 +#endif
79861 tcp_v4_send_reset(NULL, skb);
79862 }
79863
79864 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
79865 index a7302d9..e3ec754 100644
79866 --- a/net/ipv4/tcp_minisocks.c
79867 +++ b/net/ipv4/tcp_minisocks.c
79868 @@ -27,6 +27,10 @@
79869 #include <net/inet_common.h>
79870 #include <net/xfrm.h>
79871
79872 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79873 +extern int grsec_enable_blackhole;
79874 +#endif
79875 +
79876 int sysctl_tcp_syncookies __read_mostly = 1;
79877 EXPORT_SYMBOL(sysctl_tcp_syncookies);
79878
79879 @@ -742,7 +746,10 @@ embryonic_reset:
79880 * avoid becoming vulnerable to outside attack aiming at
79881 * resetting legit local connections.
79882 */
79883 - req->rsk_ops->send_reset(sk, skb);
79884 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79885 + if (!grsec_enable_blackhole)
79886 +#endif
79887 + req->rsk_ops->send_reset(sk, skb);
79888 } else if (fastopen) { /* received a valid RST pkt */
79889 reqsk_fastopen_remove(sk, req, true);
79890 tcp_reset(sk);
79891 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
79892 index 4526fe6..1a34e43 100644
79893 --- a/net/ipv4/tcp_probe.c
79894 +++ b/net/ipv4/tcp_probe.c
79895 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
79896 if (cnt + width >= len)
79897 break;
79898
79899 - if (copy_to_user(buf + cnt, tbuf, width))
79900 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
79901 return -EFAULT;
79902 cnt += width;
79903 }
79904 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
79905 index d47c1b4..b0584de 100644
79906 --- a/net/ipv4/tcp_timer.c
79907 +++ b/net/ipv4/tcp_timer.c
79908 @@ -22,6 +22,10 @@
79909 #include <linux/gfp.h>
79910 #include <net/tcp.h>
79911
79912 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79913 +extern int grsec_lastack_retries;
79914 +#endif
79915 +
79916 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
79917 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
79918 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
79919 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
79920 }
79921 }
79922
79923 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79924 + if ((sk->sk_state == TCP_LAST_ACK) &&
79925 + (grsec_lastack_retries > 0) &&
79926 + (grsec_lastack_retries < retry_until))
79927 + retry_until = grsec_lastack_retries;
79928 +#endif
79929 +
79930 if (retransmits_timed_out(sk, retry_until,
79931 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
79932 /* Has it gone just too far? */
79933 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
79934 index 1f4d405..3524677 100644
79935 --- a/net/ipv4/udp.c
79936 +++ b/net/ipv4/udp.c
79937 @@ -87,6 +87,7 @@
79938 #include <linux/types.h>
79939 #include <linux/fcntl.h>
79940 #include <linux/module.h>
79941 +#include <linux/security.h>
79942 #include <linux/socket.h>
79943 #include <linux/sockios.h>
79944 #include <linux/igmp.h>
79945 @@ -111,6 +112,10 @@
79946 #include <trace/events/skb.h>
79947 #include "udp_impl.h"
79948
79949 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79950 +extern int grsec_enable_blackhole;
79951 +#endif
79952 +
79953 struct udp_table udp_table __read_mostly;
79954 EXPORT_SYMBOL(udp_table);
79955
79956 @@ -569,6 +574,9 @@ found:
79957 return s;
79958 }
79959
79960 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
79961 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
79962 +
79963 /*
79964 * This routine is called by the ICMP module when it gets some
79965 * sort of error condition. If err < 0 then the socket should
79966 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
79967 dport = usin->sin_port;
79968 if (dport == 0)
79969 return -EINVAL;
79970 +
79971 + err = gr_search_udp_sendmsg(sk, usin);
79972 + if (err)
79973 + return err;
79974 } else {
79975 if (sk->sk_state != TCP_ESTABLISHED)
79976 return -EDESTADDRREQ;
79977 +
79978 + err = gr_search_udp_sendmsg(sk, NULL);
79979 + if (err)
79980 + return err;
79981 +
79982 daddr = inet->inet_daddr;
79983 dport = inet->inet_dport;
79984 /* Open fast path for connected socket.
79985 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
79986 udp_lib_checksum_complete(skb)) {
79987 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79988 IS_UDPLITE(sk));
79989 - atomic_inc(&sk->sk_drops);
79990 + atomic_inc_unchecked(&sk->sk_drops);
79991 __skb_unlink(skb, rcvq);
79992 __skb_queue_tail(&list_kill, skb);
79993 }
79994 @@ -1194,6 +1211,10 @@ try_again:
79995 if (!skb)
79996 goto out;
79997
79998 + err = gr_search_udp_recvmsg(sk, skb);
79999 + if (err)
80000 + goto out_free;
80001 +
80002 ulen = skb->len - sizeof(struct udphdr);
80003 copied = len;
80004 if (copied > ulen)
80005 @@ -1227,7 +1248,7 @@ try_again:
80006 if (unlikely(err)) {
80007 trace_kfree_skb(skb, udp_recvmsg);
80008 if (!peeked) {
80009 - atomic_inc(&sk->sk_drops);
80010 + atomic_inc_unchecked(&sk->sk_drops);
80011 UDP_INC_STATS_USER(sock_net(sk),
80012 UDP_MIB_INERRORS, is_udplite);
80013 }
80014 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80015
80016 drop:
80017 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80018 - atomic_inc(&sk->sk_drops);
80019 + atomic_inc_unchecked(&sk->sk_drops);
80020 kfree_skb(skb);
80021 return -1;
80022 }
80023 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80024 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80025
80026 if (!skb1) {
80027 - atomic_inc(&sk->sk_drops);
80028 + atomic_inc_unchecked(&sk->sk_drops);
80029 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80030 IS_UDPLITE(sk));
80031 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80032 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80033 goto csum_error;
80034
80035 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80036 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80037 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80038 +#endif
80039 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80040
80041 /*
80042 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80043 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80044 0, sock_i_ino(sp),
80045 atomic_read(&sp->sk_refcnt), sp,
80046 - atomic_read(&sp->sk_drops), len);
80047 + atomic_read_unchecked(&sp->sk_drops), len);
80048 }
80049
80050 int udp4_seq_show(struct seq_file *seq, void *v)
80051 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80052 index a468a36..b50ffde 100644
80053 --- a/net/ipv6/addrconf.c
80054 +++ b/net/ipv6/addrconf.c
80055 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80056 p.iph.ihl = 5;
80057 p.iph.protocol = IPPROTO_IPV6;
80058 p.iph.ttl = 64;
80059 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80060 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80061
80062 if (ops->ndo_do_ioctl) {
80063 mm_segment_t oldfs = get_fs();
80064 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80065 index a23350c..899c62c 100644
80066 --- a/net/ipv6/ip6_gre.c
80067 +++ b/net/ipv6/ip6_gre.c
80068 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80069 }
80070
80071
80072 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
80073 +static struct inet6_protocol ip6gre_protocol = {
80074 .handler = ip6gre_rcv,
80075 .err_handler = ip6gre_err,
80076 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80077 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80078 index e02faed..9780f28 100644
80079 --- a/net/ipv6/ipv6_sockglue.c
80080 +++ b/net/ipv6/ipv6_sockglue.c
80081 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80082 if (sk->sk_type != SOCK_STREAM)
80083 return -ENOPROTOOPT;
80084
80085 - msg.msg_control = optval;
80086 + msg.msg_control = (void __force_kernel *)optval;
80087 msg.msg_controllen = len;
80088 msg.msg_flags = flags;
80089
80090 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80091 index d7cb045..8c0ded6 100644
80092 --- a/net/ipv6/netfilter/ip6_tables.c
80093 +++ b/net/ipv6/netfilter/ip6_tables.c
80094 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80095 #endif
80096
80097 static int get_info(struct net *net, void __user *user,
80098 - const int *len, int compat)
80099 + int len, int compat)
80100 {
80101 char name[XT_TABLE_MAXNAMELEN];
80102 struct xt_table *t;
80103 int ret;
80104
80105 - if (*len != sizeof(struct ip6t_getinfo)) {
80106 - duprintf("length %u != %zu\n", *len,
80107 + if (len != sizeof(struct ip6t_getinfo)) {
80108 + duprintf("length %u != %zu\n", len,
80109 sizeof(struct ip6t_getinfo));
80110 return -EINVAL;
80111 }
80112 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80113 info.size = private->size;
80114 strcpy(info.name, name);
80115
80116 - if (copy_to_user(user, &info, *len) != 0)
80117 + if (copy_to_user(user, &info, len) != 0)
80118 ret = -EFAULT;
80119 else
80120 ret = 0;
80121 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80122
80123 switch (cmd) {
80124 case IP6T_SO_GET_INFO:
80125 - ret = get_info(sock_net(sk), user, len, 1);
80126 + ret = get_info(sock_net(sk), user, *len, 1);
80127 break;
80128 case IP6T_SO_GET_ENTRIES:
80129 ret = compat_get_entries(sock_net(sk), user, len);
80130 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80131
80132 switch (cmd) {
80133 case IP6T_SO_GET_INFO:
80134 - ret = get_info(sock_net(sk), user, len, 0);
80135 + ret = get_info(sock_net(sk), user, *len, 0);
80136 break;
80137
80138 case IP6T_SO_GET_ENTRIES:
80139 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80140 index d8e95c7..81422bc 100644
80141 --- a/net/ipv6/raw.c
80142 +++ b/net/ipv6/raw.c
80143 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80144 {
80145 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80146 skb_checksum_complete(skb)) {
80147 - atomic_inc(&sk->sk_drops);
80148 + atomic_inc_unchecked(&sk->sk_drops);
80149 kfree_skb(skb);
80150 return NET_RX_DROP;
80151 }
80152 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80153 struct raw6_sock *rp = raw6_sk(sk);
80154
80155 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80156 - atomic_inc(&sk->sk_drops);
80157 + atomic_inc_unchecked(&sk->sk_drops);
80158 kfree_skb(skb);
80159 return NET_RX_DROP;
80160 }
80161 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80162
80163 if (inet->hdrincl) {
80164 if (skb_checksum_complete(skb)) {
80165 - atomic_inc(&sk->sk_drops);
80166 + atomic_inc_unchecked(&sk->sk_drops);
80167 kfree_skb(skb);
80168 return NET_RX_DROP;
80169 }
80170 @@ -604,7 +604,7 @@ out:
80171 return err;
80172 }
80173
80174 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80175 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80176 struct flowi6 *fl6, struct dst_entry **dstp,
80177 unsigned int flags)
80178 {
80179 @@ -916,12 +916,15 @@ do_confirm:
80180 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80181 char __user *optval, int optlen)
80182 {
80183 + struct icmp6_filter filter;
80184 +
80185 switch (optname) {
80186 case ICMPV6_FILTER:
80187 if (optlen > sizeof(struct icmp6_filter))
80188 optlen = sizeof(struct icmp6_filter);
80189 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80190 + if (copy_from_user(&filter, optval, optlen))
80191 return -EFAULT;
80192 + raw6_sk(sk)->filter = filter;
80193 return 0;
80194 default:
80195 return -ENOPROTOOPT;
80196 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80197 char __user *optval, int __user *optlen)
80198 {
80199 int len;
80200 + struct icmp6_filter filter;
80201
80202 switch (optname) {
80203 case ICMPV6_FILTER:
80204 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80205 len = sizeof(struct icmp6_filter);
80206 if (put_user(len, optlen))
80207 return -EFAULT;
80208 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80209 + filter = raw6_sk(sk)->filter;
80210 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80211 return -EFAULT;
80212 return 0;
80213 default:
80214 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80215 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80216 0,
80217 sock_i_ino(sp),
80218 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80219 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80220 }
80221
80222 static int raw6_seq_show(struct seq_file *seq, void *v)
80223 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80224 index 73f2a6b..f8049a1 100644
80225 --- a/net/ipv6/tcp_ipv6.c
80226 +++ b/net/ipv6/tcp_ipv6.c
80227 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80228 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80229 }
80230
80231 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80232 +extern int grsec_enable_blackhole;
80233 +#endif
80234 +
80235 static void tcp_v6_hash(struct sock *sk)
80236 {
80237 if (sk->sk_state != TCP_CLOSE) {
80238 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80239 return 0;
80240
80241 reset:
80242 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80243 + if (!grsec_enable_blackhole)
80244 +#endif
80245 tcp_v6_send_reset(sk, skb);
80246 discard:
80247 if (opt_skb)
80248 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80249 TCP_SKB_CB(skb)->sacked = 0;
80250
80251 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80252 - if (!sk)
80253 + if (!sk) {
80254 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80255 + ret = 1;
80256 +#endif
80257 goto no_tcp_socket;
80258 + }
80259
80260 process:
80261 - if (sk->sk_state == TCP_TIME_WAIT)
80262 + if (sk->sk_state == TCP_TIME_WAIT) {
80263 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80264 + ret = 2;
80265 +#endif
80266 goto do_time_wait;
80267 + }
80268
80269 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80270 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80271 @@ -1660,6 +1675,10 @@ no_tcp_socket:
80272 bad_packet:
80273 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80274 } else {
80275 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80276 + if (!grsec_enable_blackhole || (ret == 1 &&
80277 + (skb->dev->flags & IFF_LOOPBACK)))
80278 +#endif
80279 tcp_v6_send_reset(NULL, skb);
80280 }
80281
80282 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80283 index fc99972..69397e8 100644
80284 --- a/net/ipv6/udp.c
80285 +++ b/net/ipv6/udp.c
80286 @@ -51,6 +51,10 @@
80287 #include <trace/events/skb.h>
80288 #include "udp_impl.h"
80289
80290 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80291 +extern int grsec_enable_blackhole;
80292 +#endif
80293 +
80294 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80295 {
80296 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80297 @@ -395,7 +399,7 @@ try_again:
80298 if (unlikely(err)) {
80299 trace_kfree_skb(skb, udpv6_recvmsg);
80300 if (!peeked) {
80301 - atomic_inc(&sk->sk_drops);
80302 + atomic_inc_unchecked(&sk->sk_drops);
80303 if (is_udp4)
80304 UDP_INC_STATS_USER(sock_net(sk),
80305 UDP_MIB_INERRORS,
80306 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80307 return rc;
80308 drop:
80309 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80310 - atomic_inc(&sk->sk_drops);
80311 + atomic_inc_unchecked(&sk->sk_drops);
80312 kfree_skb(skb);
80313 return -1;
80314 }
80315 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80316 if (likely(skb1 == NULL))
80317 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80318 if (!skb1) {
80319 - atomic_inc(&sk->sk_drops);
80320 + atomic_inc_unchecked(&sk->sk_drops);
80321 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80322 IS_UDPLITE(sk));
80323 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80324 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80325 goto discard;
80326
80327 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80328 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80329 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80330 +#endif
80331 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80332
80333 kfree_skb(skb);
80334 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80335 0,
80336 sock_i_ino(sp),
80337 atomic_read(&sp->sk_refcnt), sp,
80338 - atomic_read(&sp->sk_drops));
80339 + atomic_read_unchecked(&sp->sk_drops));
80340 }
80341
80342 int udp6_seq_show(struct seq_file *seq, void *v)
80343 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80344 index 496ce2c..f79fac8 100644
80345 --- a/net/irda/ircomm/ircomm_tty.c
80346 +++ b/net/irda/ircomm/ircomm_tty.c
80347 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80348 add_wait_queue(&port->open_wait, &wait);
80349
80350 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80351 - __FILE__, __LINE__, tty->driver->name, port->count);
80352 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80353
80354 spin_lock_irqsave(&port->lock, flags);
80355 if (!tty_hung_up_p(filp)) {
80356 extra_count = 1;
80357 - port->count--;
80358 + atomic_dec(&port->count);
80359 }
80360 spin_unlock_irqrestore(&port->lock, flags);
80361 port->blocked_open++;
80362 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80363 }
80364
80365 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80366 - __FILE__, __LINE__, tty->driver->name, port->count);
80367 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80368
80369 schedule();
80370 }
80371 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80372 if (extra_count) {
80373 /* ++ is not atomic, so this should be protected - Jean II */
80374 spin_lock_irqsave(&port->lock, flags);
80375 - port->count++;
80376 + atomic_inc(&port->count);
80377 spin_unlock_irqrestore(&port->lock, flags);
80378 }
80379 port->blocked_open--;
80380
80381 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80382 - __FILE__, __LINE__, tty->driver->name, port->count);
80383 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80384
80385 if (!retval)
80386 port->flags |= ASYNC_NORMAL_ACTIVE;
80387 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80388
80389 /* ++ is not atomic, so this should be protected - Jean II */
80390 spin_lock_irqsave(&self->port.lock, flags);
80391 - self->port.count++;
80392 + atomic_inc(&self->port.count);
80393 spin_unlock_irqrestore(&self->port.lock, flags);
80394 tty_port_tty_set(&self->port, tty);
80395
80396 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80397 - self->line, self->port.count);
80398 + self->line, atomic_read(&self->port.count));
80399
80400 /* Not really used by us, but lets do it anyway */
80401 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80402 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80403 tty_kref_put(port->tty);
80404 }
80405 port->tty = NULL;
80406 - port->count = 0;
80407 + atomic_set(&port->count, 0);
80408 spin_unlock_irqrestore(&port->lock, flags);
80409
80410 wake_up_interruptible(&port->open_wait);
80411 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80412 seq_putc(m, '\n');
80413
80414 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80415 - seq_printf(m, "Open count: %d\n", self->port.count);
80416 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80417 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80418 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80419
80420 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80421 index cd6f7a9..e63fe89 100644
80422 --- a/net/iucv/af_iucv.c
80423 +++ b/net/iucv/af_iucv.c
80424 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80425
80426 write_lock_bh(&iucv_sk_list.lock);
80427
80428 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80429 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80430 while (__iucv_get_sock_by_name(name)) {
80431 sprintf(name, "%08x",
80432 - atomic_inc_return(&iucv_sk_list.autobind_name));
80433 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80434 }
80435
80436 write_unlock_bh(&iucv_sk_list.lock);
80437 diff --git a/net/key/af_key.c b/net/key/af_key.c
80438 index 08897a3..0b812ab 100644
80439 --- a/net/key/af_key.c
80440 +++ b/net/key/af_key.c
80441 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80442 static u32 get_acqseq(void)
80443 {
80444 u32 res;
80445 - static atomic_t acqseq;
80446 + static atomic_unchecked_t acqseq;
80447
80448 do {
80449 - res = atomic_inc_return(&acqseq);
80450 + res = atomic_inc_return_unchecked(&acqseq);
80451 } while (!res);
80452 return res;
80453 }
80454 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80455 index 494da7f..6ce2ffd 100644
80456 --- a/net/mac80211/cfg.c
80457 +++ b/net/mac80211/cfg.c
80458 @@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80459 else
80460 local->probe_req_reg--;
80461
80462 - if (!local->open_count)
80463 + if (!local_read(&local->open_count))
80464 break;
80465
80466 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80467 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80468 index 493e2e8..be76574 100644
80469 --- a/net/mac80211/ieee80211_i.h
80470 +++ b/net/mac80211/ieee80211_i.h
80471 @@ -28,6 +28,7 @@
80472 #include <net/ieee80211_radiotap.h>
80473 #include <net/cfg80211.h>
80474 #include <net/mac80211.h>
80475 +#include <asm/local.h>
80476 #include "key.h"
80477 #include "sta_info.h"
80478 #include "debug.h"
80479 @@ -852,7 +853,7 @@ struct ieee80211_local {
80480 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80481 spinlock_t queue_stop_reason_lock;
80482
80483 - int open_count;
80484 + local_t open_count;
80485 int monitors, cooked_mntrs;
80486 /* number of interfaces with corresponding FIF_ flags */
80487 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80488 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80489 index 0f5af91..4dba9e7 100644
80490 --- a/net/mac80211/iface.c
80491 +++ b/net/mac80211/iface.c
80492 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80493 break;
80494 }
80495
80496 - if (local->open_count == 0) {
80497 + if (local_read(&local->open_count) == 0) {
80498 res = drv_start(local);
80499 if (res)
80500 goto err_del_bss;
80501 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80502 break;
80503 }
80504
80505 - if (local->monitors == 0 && local->open_count == 0) {
80506 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80507 res = ieee80211_add_virtual_monitor(local);
80508 if (res)
80509 goto err_stop;
80510 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80511 mutex_unlock(&local->mtx);
80512
80513 if (coming_up)
80514 - local->open_count++;
80515 + local_inc(&local->open_count);
80516
80517 if (hw_reconf_flags)
80518 ieee80211_hw_config(local, hw_reconf_flags);
80519 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80520 err_del_interface:
80521 drv_remove_interface(local, sdata);
80522 err_stop:
80523 - if (!local->open_count)
80524 + if (!local_read(&local->open_count))
80525 drv_stop(local);
80526 err_del_bss:
80527 sdata->bss = NULL;
80528 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80529 }
80530
80531 if (going_down)
80532 - local->open_count--;
80533 + local_dec(&local->open_count);
80534
80535 switch (sdata->vif.type) {
80536 case NL80211_IFTYPE_AP_VLAN:
80537 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80538
80539 ieee80211_recalc_ps(local, -1);
80540
80541 - if (local->open_count == 0) {
80542 + if (local_read(&local->open_count) == 0) {
80543 if (local->ops->napi_poll)
80544 napi_disable(&local->napi);
80545 ieee80211_clear_tx_pending(local);
80546 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80547 }
80548 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80549
80550 - if (local->monitors == local->open_count && local->monitors > 0)
80551 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80552 ieee80211_add_virtual_monitor(local);
80553 }
80554
80555 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80556 index f57f597..e0a7c03 100644
80557 --- a/net/mac80211/main.c
80558 +++ b/net/mac80211/main.c
80559 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80560 local->hw.conf.power_level = power;
80561 }
80562
80563 - if (changed && local->open_count) {
80564 + if (changed && local_read(&local->open_count)) {
80565 ret = drv_config(local, changed);
80566 /*
80567 * Goal:
80568 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80569 index 5c572e7..ecf75ce 100644
80570 --- a/net/mac80211/pm.c
80571 +++ b/net/mac80211/pm.c
80572 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80573 struct ieee80211_sub_if_data *sdata;
80574 struct sta_info *sta;
80575
80576 - if (!local->open_count)
80577 + if (!local_read(&local->open_count))
80578 goto suspend;
80579
80580 ieee80211_scan_cancel(local);
80581 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80582 cancel_work_sync(&local->dynamic_ps_enable_work);
80583 del_timer_sync(&local->dynamic_ps_timer);
80584
80585 - local->wowlan = wowlan && local->open_count;
80586 + local->wowlan = wowlan && local_read(&local->open_count);
80587 if (local->wowlan) {
80588 int err = drv_suspend(local, wowlan);
80589 if (err < 0) {
80590 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80591 drv_remove_interface(local, sdata);
80592
80593 /* stop hardware - this must stop RX */
80594 - if (local->open_count)
80595 + if (local_read(&local->open_count))
80596 ieee80211_stop_device(local);
80597
80598 suspend:
80599 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80600 index 3313c11..bec9f17 100644
80601 --- a/net/mac80211/rate.c
80602 +++ b/net/mac80211/rate.c
80603 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80604
80605 ASSERT_RTNL();
80606
80607 - if (local->open_count)
80608 + if (local_read(&local->open_count))
80609 return -EBUSY;
80610
80611 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80612 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80613 index c97a065..ff61928 100644
80614 --- a/net/mac80211/rc80211_pid_debugfs.c
80615 +++ b/net/mac80211/rc80211_pid_debugfs.c
80616 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80617
80618 spin_unlock_irqrestore(&events->lock, status);
80619
80620 - if (copy_to_user(buf, pb, p))
80621 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80622 return -EFAULT;
80623
80624 return p;
80625 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80626 index 0151ae3..26709d3 100644
80627 --- a/net/mac80211/util.c
80628 +++ b/net/mac80211/util.c
80629 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80630 }
80631 #endif
80632 /* everything else happens only if HW was up & running */
80633 - if (!local->open_count)
80634 + if (!local_read(&local->open_count))
80635 goto wake_up;
80636
80637 /*
80638 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80639 index 49e96df..63a51c3 100644
80640 --- a/net/netfilter/Kconfig
80641 +++ b/net/netfilter/Kconfig
80642 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80643
80644 To compile it as a module, choose M here. If unsure, say N.
80645
80646 +config NETFILTER_XT_MATCH_GRADM
80647 + tristate '"gradm" match support'
80648 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80649 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80650 + ---help---
80651 + The gradm match allows to match on grsecurity RBAC being enabled.
80652 + It is useful when iptables rules are applied early on bootup to
80653 + prevent connections to the machine (except from a trusted host)
80654 + while the RBAC system is disabled.
80655 +
80656 config NETFILTER_XT_MATCH_HASHLIMIT
80657 tristate '"hashlimit" match support'
80658 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80659 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80660 index 3259697..54d5393 100644
80661 --- a/net/netfilter/Makefile
80662 +++ b/net/netfilter/Makefile
80663 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80664 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80665 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80666 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80667 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80668 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80669 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80670 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80671 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80672 index 1548df9..98ad9b4 100644
80673 --- a/net/netfilter/ipvs/ip_vs_conn.c
80674 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80675 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80676 /* Increase the refcnt counter of the dest */
80677 atomic_inc(&dest->refcnt);
80678
80679 - conn_flags = atomic_read(&dest->conn_flags);
80680 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80681 if (cp->protocol != IPPROTO_UDP)
80682 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80683 flags = cp->flags;
80684 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80685 atomic_set(&cp->refcnt, 1);
80686
80687 atomic_set(&cp->n_control, 0);
80688 - atomic_set(&cp->in_pkts, 0);
80689 + atomic_set_unchecked(&cp->in_pkts, 0);
80690
80691 atomic_inc(&ipvs->conn_count);
80692 if (flags & IP_VS_CONN_F_NO_CPORT)
80693 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80694
80695 /* Don't drop the entry if its number of incoming packets is not
80696 located in [0, 8] */
80697 - i = atomic_read(&cp->in_pkts);
80698 + i = atomic_read_unchecked(&cp->in_pkts);
80699 if (i > 8 || i < 0) return 0;
80700
80701 if (!todrop_rate[i]) return 0;
80702 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80703 index 58918e2..4d177a9 100644
80704 --- a/net/netfilter/ipvs/ip_vs_core.c
80705 +++ b/net/netfilter/ipvs/ip_vs_core.c
80706 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80707 ret = cp->packet_xmit(skb, cp, pd->pp);
80708 /* do not touch skb anymore */
80709
80710 - atomic_inc(&cp->in_pkts);
80711 + atomic_inc_unchecked(&cp->in_pkts);
80712 ip_vs_conn_put(cp);
80713 return ret;
80714 }
80715 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80716 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80717 pkts = sysctl_sync_threshold(ipvs);
80718 else
80719 - pkts = atomic_add_return(1, &cp->in_pkts);
80720 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80721
80722 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80723 ip_vs_sync_conn(net, cp, pkts);
80724 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80725 index c4ee437..a774a74 100644
80726 --- a/net/netfilter/ipvs/ip_vs_ctl.c
80727 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
80728 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80729 ip_vs_rs_hash(ipvs, dest);
80730 write_unlock_bh(&ipvs->rs_lock);
80731 }
80732 - atomic_set(&dest->conn_flags, conn_flags);
80733 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
80734
80735 /* bind the service */
80736 if (!dest->svc) {
80737 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80738 " %-7s %-6d %-10d %-10d\n",
80739 &dest->addr.in6,
80740 ntohs(dest->port),
80741 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80742 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80743 atomic_read(&dest->weight),
80744 atomic_read(&dest->activeconns),
80745 atomic_read(&dest->inactconns));
80746 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80747 "%-7s %-6d %-10d %-10d\n",
80748 ntohl(dest->addr.ip),
80749 ntohs(dest->port),
80750 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80751 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80752 atomic_read(&dest->weight),
80753 atomic_read(&dest->activeconns),
80754 atomic_read(&dest->inactconns));
80755 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80756
80757 entry.addr = dest->addr.ip;
80758 entry.port = dest->port;
80759 - entry.conn_flags = atomic_read(&dest->conn_flags);
80760 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80761 entry.weight = atomic_read(&dest->weight);
80762 entry.u_threshold = dest->u_threshold;
80763 entry.l_threshold = dest->l_threshold;
80764 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80765 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80766 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80767 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80768 - (atomic_read(&dest->conn_flags) &
80769 + (atomic_read_unchecked(&dest->conn_flags) &
80770 IP_VS_CONN_F_FWD_MASK)) ||
80771 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80772 atomic_read(&dest->weight)) ||
80773 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80774 index effa10c..9058928 100644
80775 --- a/net/netfilter/ipvs/ip_vs_sync.c
80776 +++ b/net/netfilter/ipvs/ip_vs_sync.c
80777 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80778 cp = cp->control;
80779 if (cp) {
80780 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80781 - pkts = atomic_add_return(1, &cp->in_pkts);
80782 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80783 else
80784 pkts = sysctl_sync_threshold(ipvs);
80785 ip_vs_sync_conn(net, cp->control, pkts);
80786 @@ -758,7 +758,7 @@ control:
80787 if (!cp)
80788 return;
80789 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80790 - pkts = atomic_add_return(1, &cp->in_pkts);
80791 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80792 else
80793 pkts = sysctl_sync_threshold(ipvs);
80794 goto sloop;
80795 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80796
80797 if (opt)
80798 memcpy(&cp->in_seq, opt, sizeof(*opt));
80799 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80800 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80801 cp->state = state;
80802 cp->old_state = cp->state;
80803 /*
80804 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80805 index cc4c809..50f8fe5 100644
80806 --- a/net/netfilter/ipvs/ip_vs_xmit.c
80807 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
80808 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80809 else
80810 rc = NF_ACCEPT;
80811 /* do not touch skb anymore */
80812 - atomic_inc(&cp->in_pkts);
80813 + atomic_inc_unchecked(&cp->in_pkts);
80814 goto out;
80815 }
80816
80817 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80818 else
80819 rc = NF_ACCEPT;
80820 /* do not touch skb anymore */
80821 - atomic_inc(&cp->in_pkts);
80822 + atomic_inc_unchecked(&cp->in_pkts);
80823 goto out;
80824 }
80825
80826 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80827 index ec02168..f0caab6 100644
80828 --- a/net/netfilter/nf_conntrack_core.c
80829 +++ b/net/netfilter/nf_conntrack_core.c
80830 @@ -1533,6 +1533,10 @@ err_extend:
80831 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80832 #define DYING_NULLS_VAL ((1<<30)+1)
80833
80834 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80835 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80836 +#endif
80837 +
80838 static int nf_conntrack_init_net(struct net *net)
80839 {
80840 int ret;
80841 @@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
80842 goto err_stat;
80843 }
80844
80845 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80846 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
80847 +#else
80848 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
80849 +#endif
80850 if (!net->ct.slabname) {
80851 ret = -ENOMEM;
80852 goto err_slabname;
80853 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
80854 index 92fd8ec..3f6ea4b 100644
80855 --- a/net/netfilter/nfnetlink_log.c
80856 +++ b/net/netfilter/nfnetlink_log.c
80857 @@ -72,7 +72,7 @@ struct nfulnl_instance {
80858 };
80859
80860 static DEFINE_SPINLOCK(instances_lock);
80861 -static atomic_t global_seq;
80862 +static atomic_unchecked_t global_seq;
80863
80864 #define INSTANCE_BUCKETS 16
80865 static struct hlist_head instance_table[INSTANCE_BUCKETS];
80866 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
80867 /* global sequence number */
80868 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
80869 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
80870 - htonl(atomic_inc_return(&global_seq))))
80871 + htonl(atomic_inc_return_unchecked(&global_seq))))
80872 goto nla_put_failure;
80873
80874 if (data_len) {
80875 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
80876 new file mode 100644
80877 index 0000000..c566332
80878 --- /dev/null
80879 +++ b/net/netfilter/xt_gradm.c
80880 @@ -0,0 +1,51 @@
80881 +/*
80882 + * gradm match for netfilter
80883 + * Copyright © Zbigniew Krzystolik, 2010
80884 + *
80885 + * This program is free software; you can redistribute it and/or modify
80886 + * it under the terms of the GNU General Public License; either version
80887 + * 2 or 3 as published by the Free Software Foundation.
80888 + */
80889 +#include <linux/module.h>
80890 +#include <linux/moduleparam.h>
80891 +#include <linux/skbuff.h>
80892 +#include <linux/netfilter/x_tables.h>
80893 +#include <linux/grsecurity.h>
80894 +#include <linux/netfilter/xt_gradm.h>
80895 +
80896 +static bool
80897 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
80898 +{
80899 + const struct xt_gradm_mtinfo *info = par->matchinfo;
80900 + bool retval = false;
80901 + if (gr_acl_is_enabled())
80902 + retval = true;
80903 + return retval ^ info->invflags;
80904 +}
80905 +
80906 +static struct xt_match gradm_mt_reg __read_mostly = {
80907 + .name = "gradm",
80908 + .revision = 0,
80909 + .family = NFPROTO_UNSPEC,
80910 + .match = gradm_mt,
80911 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
80912 + .me = THIS_MODULE,
80913 +};
80914 +
80915 +static int __init gradm_mt_init(void)
80916 +{
80917 + return xt_register_match(&gradm_mt_reg);
80918 +}
80919 +
80920 +static void __exit gradm_mt_exit(void)
80921 +{
80922 + xt_unregister_match(&gradm_mt_reg);
80923 +}
80924 +
80925 +module_init(gradm_mt_init);
80926 +module_exit(gradm_mt_exit);
80927 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
80928 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
80929 +MODULE_LICENSE("GPL");
80930 +MODULE_ALIAS("ipt_gradm");
80931 +MODULE_ALIAS("ip6t_gradm");
80932 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
80933 index 4fe4fb4..87a89e5 100644
80934 --- a/net/netfilter/xt_statistic.c
80935 +++ b/net/netfilter/xt_statistic.c
80936 @@ -19,7 +19,7 @@
80937 #include <linux/module.h>
80938
80939 struct xt_statistic_priv {
80940 - atomic_t count;
80941 + atomic_unchecked_t count;
80942 } ____cacheline_aligned_in_smp;
80943
80944 MODULE_LICENSE("GPL");
80945 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
80946 break;
80947 case XT_STATISTIC_MODE_NTH:
80948 do {
80949 - oval = atomic_read(&info->master->count);
80950 + oval = atomic_read_unchecked(&info->master->count);
80951 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
80952 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
80953 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
80954 if (nval == 0)
80955 ret = !ret;
80956 break;
80957 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
80958 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
80959 if (info->master == NULL)
80960 return -ENOMEM;
80961 - atomic_set(&info->master->count, info->u.nth.count);
80962 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
80963
80964 return 0;
80965 }
80966 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
80967 index 4da797f..eb1df70 100644
80968 --- a/net/netlink/af_netlink.c
80969 +++ b/net/netlink/af_netlink.c
80970 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
80971 sk->sk_error_report(sk);
80972 }
80973 }
80974 - atomic_inc(&sk->sk_drops);
80975 + atomic_inc_unchecked(&sk->sk_drops);
80976 }
80977
80978 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
80979 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
80980 sk_wmem_alloc_get(s),
80981 nlk->cb,
80982 atomic_read(&s->sk_refcnt),
80983 - atomic_read(&s->sk_drops),
80984 + atomic_read_unchecked(&s->sk_drops),
80985 sock_i_ino(s)
80986 );
80987
80988 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
80989 index 7261eb8..44e8ac6 100644
80990 --- a/net/netrom/af_netrom.c
80991 +++ b/net/netrom/af_netrom.c
80992 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
80993 struct sock *sk = sock->sk;
80994 struct nr_sock *nr = nr_sk(sk);
80995
80996 + memset(sax, 0, sizeof(*sax));
80997 lock_sock(sk);
80998 if (peer != 0) {
80999 if (sk->sk_state != TCP_ESTABLISHED) {
81000 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81001 *uaddr_len = sizeof(struct full_sockaddr_ax25);
81002 } else {
81003 sax->fsa_ax25.sax25_family = AF_NETROM;
81004 - sax->fsa_ax25.sax25_ndigis = 0;
81005 sax->fsa_ax25.sax25_call = nr->source_addr;
81006 *uaddr_len = sizeof(struct sockaddr_ax25);
81007 }
81008 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
81009 index 5db6316..c9bf90e 100644
81010 --- a/net/packet/af_packet.c
81011 +++ b/net/packet/af_packet.c
81012 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81013
81014 spin_lock(&sk->sk_receive_queue.lock);
81015 po->stats.tp_packets++;
81016 - skb->dropcount = atomic_read(&sk->sk_drops);
81017 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
81018 __skb_queue_tail(&sk->sk_receive_queue, skb);
81019 spin_unlock(&sk->sk_receive_queue.lock);
81020 sk->sk_data_ready(sk, skb->len);
81021 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81022 drop_n_acct:
81023 spin_lock(&sk->sk_receive_queue.lock);
81024 po->stats.tp_drops++;
81025 - atomic_inc(&sk->sk_drops);
81026 + atomic_inc_unchecked(&sk->sk_drops);
81027 spin_unlock(&sk->sk_receive_queue.lock);
81028
81029 drop_n_restore:
81030 @@ -2539,6 +2539,7 @@ out:
81031
81032 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81033 {
81034 + struct sock_extended_err ee;
81035 struct sock_exterr_skb *serr;
81036 struct sk_buff *skb, *skb2;
81037 int copied, err;
81038 @@ -2560,8 +2561,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81039 sock_recv_timestamp(msg, sk, skb);
81040
81041 serr = SKB_EXT_ERR(skb);
81042 + ee = serr->ee;
81043 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
81044 - sizeof(serr->ee), &serr->ee);
81045 + sizeof ee, &ee);
81046
81047 msg->msg_flags |= MSG_ERRQUEUE;
81048 err = copied;
81049 @@ -3173,7 +3175,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81050 case PACKET_HDRLEN:
81051 if (len > sizeof(int))
81052 len = sizeof(int);
81053 - if (copy_from_user(&val, optval, len))
81054 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
81055 return -EFAULT;
81056 switch (val) {
81057 case TPACKET_V1:
81058 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81059 len = lv;
81060 if (put_user(len, optlen))
81061 return -EFAULT;
81062 - if (copy_to_user(optval, data, len))
81063 + if (len > sizeof(st) || copy_to_user(optval, data, len))
81064 return -EFAULT;
81065 return 0;
81066 }
81067 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
81068 index 5a940db..f0b9c12 100644
81069 --- a/net/phonet/af_phonet.c
81070 +++ b/net/phonet/af_phonet.c
81071 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
81072 {
81073 struct phonet_protocol *pp;
81074
81075 - if (protocol >= PHONET_NPROTO)
81076 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81077 return NULL;
81078
81079 rcu_read_lock();
81080 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
81081 {
81082 int err = 0;
81083
81084 - if (protocol >= PHONET_NPROTO)
81085 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81086 return -EINVAL;
81087
81088 err = proto_register(pp->prot, 1);
81089 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
81090 index 576f22c..bc7a71b 100644
81091 --- a/net/phonet/pep.c
81092 +++ b/net/phonet/pep.c
81093 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81094
81095 case PNS_PEP_CTRL_REQ:
81096 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
81097 - atomic_inc(&sk->sk_drops);
81098 + atomic_inc_unchecked(&sk->sk_drops);
81099 break;
81100 }
81101 __skb_pull(skb, 4);
81102 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81103 }
81104
81105 if (pn->rx_credits == 0) {
81106 - atomic_inc(&sk->sk_drops);
81107 + atomic_inc_unchecked(&sk->sk_drops);
81108 err = -ENOBUFS;
81109 break;
81110 }
81111 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
81112 }
81113
81114 if (pn->rx_credits == 0) {
81115 - atomic_inc(&sk->sk_drops);
81116 + atomic_inc_unchecked(&sk->sk_drops);
81117 err = NET_RX_DROP;
81118 break;
81119 }
81120 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
81121 index b7e9827..c264c85 100644
81122 --- a/net/phonet/socket.c
81123 +++ b/net/phonet/socket.c
81124 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
81125 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
81126 sock_i_ino(sk),
81127 atomic_read(&sk->sk_refcnt), sk,
81128 - atomic_read(&sk->sk_drops), &len);
81129 + atomic_read_unchecked(&sk->sk_drops), &len);
81130 }
81131 seq_printf(seq, "%*s\n", 127 - len, "");
81132 return 0;
81133 diff --git a/net/rds/cong.c b/net/rds/cong.c
81134 index e5b65ac..f3b6fb7 100644
81135 --- a/net/rds/cong.c
81136 +++ b/net/rds/cong.c
81137 @@ -78,7 +78,7 @@
81138 * finds that the saved generation number is smaller than the global generation
81139 * number, it wakes up the process.
81140 */
81141 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
81142 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
81143
81144 /*
81145 * Congestion monitoring
81146 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
81147 rdsdebug("waking map %p for %pI4\n",
81148 map, &map->m_addr);
81149 rds_stats_inc(s_cong_update_received);
81150 - atomic_inc(&rds_cong_generation);
81151 + atomic_inc_unchecked(&rds_cong_generation);
81152 if (waitqueue_active(&map->m_waitq))
81153 wake_up(&map->m_waitq);
81154 if (waitqueue_active(&rds_poll_waitq))
81155 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
81156
81157 int rds_cong_updated_since(unsigned long *recent)
81158 {
81159 - unsigned long gen = atomic_read(&rds_cong_generation);
81160 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
81161
81162 if (likely(*recent == gen))
81163 return 0;
81164 diff --git a/net/rds/ib.h b/net/rds/ib.h
81165 index 8d2b3d5..227ec5b 100644
81166 --- a/net/rds/ib.h
81167 +++ b/net/rds/ib.h
81168 @@ -128,7 +128,7 @@ struct rds_ib_connection {
81169 /* sending acks */
81170 unsigned long i_ack_flags;
81171 #ifdef KERNEL_HAS_ATOMIC64
81172 - atomic64_t i_ack_next; /* next ACK to send */
81173 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81174 #else
81175 spinlock_t i_ack_lock; /* protect i_ack_next */
81176 u64 i_ack_next; /* next ACK to send */
81177 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
81178 index a1e1162..265e129 100644
81179 --- a/net/rds/ib_cm.c
81180 +++ b/net/rds/ib_cm.c
81181 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
81182 /* Clear the ACK state */
81183 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81184 #ifdef KERNEL_HAS_ATOMIC64
81185 - atomic64_set(&ic->i_ack_next, 0);
81186 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81187 #else
81188 ic->i_ack_next = 0;
81189 #endif
81190 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
81191 index 8d19491..05a3e65 100644
81192 --- a/net/rds/ib_recv.c
81193 +++ b/net/rds/ib_recv.c
81194 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81195 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
81196 int ack_required)
81197 {
81198 - atomic64_set(&ic->i_ack_next, seq);
81199 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81200 if (ack_required) {
81201 smp_mb__before_clear_bit();
81202 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81203 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81204 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81205 smp_mb__after_clear_bit();
81206
81207 - return atomic64_read(&ic->i_ack_next);
81208 + return atomic64_read_unchecked(&ic->i_ack_next);
81209 }
81210 #endif
81211
81212 diff --git a/net/rds/iw.h b/net/rds/iw.h
81213 index 04ce3b1..48119a6 100644
81214 --- a/net/rds/iw.h
81215 +++ b/net/rds/iw.h
81216 @@ -134,7 +134,7 @@ struct rds_iw_connection {
81217 /* sending acks */
81218 unsigned long i_ack_flags;
81219 #ifdef KERNEL_HAS_ATOMIC64
81220 - atomic64_t i_ack_next; /* next ACK to send */
81221 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81222 #else
81223 spinlock_t i_ack_lock; /* protect i_ack_next */
81224 u64 i_ack_next; /* next ACK to send */
81225 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
81226 index a91e1db..cf3053f 100644
81227 --- a/net/rds/iw_cm.c
81228 +++ b/net/rds/iw_cm.c
81229 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
81230 /* Clear the ACK state */
81231 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81232 #ifdef KERNEL_HAS_ATOMIC64
81233 - atomic64_set(&ic->i_ack_next, 0);
81234 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81235 #else
81236 ic->i_ack_next = 0;
81237 #endif
81238 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
81239 index 4503335..db566b4 100644
81240 --- a/net/rds/iw_recv.c
81241 +++ b/net/rds/iw_recv.c
81242 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81243 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
81244 int ack_required)
81245 {
81246 - atomic64_set(&ic->i_ack_next, seq);
81247 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81248 if (ack_required) {
81249 smp_mb__before_clear_bit();
81250 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81251 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81252 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81253 smp_mb__after_clear_bit();
81254
81255 - return atomic64_read(&ic->i_ack_next);
81256 + return atomic64_read_unchecked(&ic->i_ack_next);
81257 }
81258 #endif
81259
81260 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
81261 index edac9ef..16bcb98 100644
81262 --- a/net/rds/tcp.c
81263 +++ b/net/rds/tcp.c
81264 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
81265 int val = 1;
81266
81267 set_fs(KERNEL_DS);
81268 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
81269 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
81270 sizeof(val));
81271 set_fs(oldfs);
81272 }
81273 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
81274 index 81cf5a4..b5826ff 100644
81275 --- a/net/rds/tcp_send.c
81276 +++ b/net/rds/tcp_send.c
81277 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
81278
81279 oldfs = get_fs();
81280 set_fs(KERNEL_DS);
81281 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
81282 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
81283 sizeof(val));
81284 set_fs(oldfs);
81285 }
81286 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
81287 index 05996d0..5a1dfe0 100644
81288 --- a/net/rxrpc/af_rxrpc.c
81289 +++ b/net/rxrpc/af_rxrpc.c
81290 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
81291 __be32 rxrpc_epoch;
81292
81293 /* current debugging ID */
81294 -atomic_t rxrpc_debug_id;
81295 +atomic_unchecked_t rxrpc_debug_id;
81296
81297 /* count of skbs currently in use */
81298 atomic_t rxrpc_n_skbs;
81299 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
81300 index e4d9cbc..b229649 100644
81301 --- a/net/rxrpc/ar-ack.c
81302 +++ b/net/rxrpc/ar-ack.c
81303 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81304
81305 _enter("{%d,%d,%d,%d},",
81306 call->acks_hard, call->acks_unacked,
81307 - atomic_read(&call->sequence),
81308 + atomic_read_unchecked(&call->sequence),
81309 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
81310
81311 stop = 0;
81312 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81313
81314 /* each Tx packet has a new serial number */
81315 sp->hdr.serial =
81316 - htonl(atomic_inc_return(&call->conn->serial));
81317 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
81318
81319 hdr = (struct rxrpc_header *) txb->head;
81320 hdr->serial = sp->hdr.serial;
81321 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
81322 */
81323 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
81324 {
81325 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
81326 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
81327 }
81328
81329 /*
81330 @@ -629,7 +629,7 @@ process_further:
81331
81332 latest = ntohl(sp->hdr.serial);
81333 hard = ntohl(ack.firstPacket);
81334 - tx = atomic_read(&call->sequence);
81335 + tx = atomic_read_unchecked(&call->sequence);
81336
81337 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81338 latest,
81339 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
81340 goto maybe_reschedule;
81341
81342 send_ACK_with_skew:
81343 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
81344 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
81345 ntohl(ack.serial));
81346 send_ACK:
81347 mtu = call->conn->trans->peer->if_mtu;
81348 @@ -1173,7 +1173,7 @@ send_ACK:
81349 ackinfo.rxMTU = htonl(5692);
81350 ackinfo.jumbo_max = htonl(4);
81351
81352 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81353 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81354 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81355 ntohl(hdr.serial),
81356 ntohs(ack.maxSkew),
81357 @@ -1191,7 +1191,7 @@ send_ACK:
81358 send_message:
81359 _debug("send message");
81360
81361 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81362 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81363 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
81364 send_message_2:
81365
81366 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
81367 index a3bbb36..3341fb9 100644
81368 --- a/net/rxrpc/ar-call.c
81369 +++ b/net/rxrpc/ar-call.c
81370 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
81371 spin_lock_init(&call->lock);
81372 rwlock_init(&call->state_lock);
81373 atomic_set(&call->usage, 1);
81374 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
81375 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81376 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
81377
81378 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
81379 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
81380 index 4106ca9..a338d7a 100644
81381 --- a/net/rxrpc/ar-connection.c
81382 +++ b/net/rxrpc/ar-connection.c
81383 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
81384 rwlock_init(&conn->lock);
81385 spin_lock_init(&conn->state_lock);
81386 atomic_set(&conn->usage, 1);
81387 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
81388 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81389 conn->avail_calls = RXRPC_MAXCALLS;
81390 conn->size_align = 4;
81391 conn->header_size = sizeof(struct rxrpc_header);
81392 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
81393 index e7ed43a..6afa140 100644
81394 --- a/net/rxrpc/ar-connevent.c
81395 +++ b/net/rxrpc/ar-connevent.c
81396 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
81397
81398 len = iov[0].iov_len + iov[1].iov_len;
81399
81400 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81401 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81402 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
81403
81404 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81405 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
81406 index 529572f..c758ca7 100644
81407 --- a/net/rxrpc/ar-input.c
81408 +++ b/net/rxrpc/ar-input.c
81409 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
81410 /* track the latest serial number on this connection for ACK packet
81411 * information */
81412 serial = ntohl(sp->hdr.serial);
81413 - hi_serial = atomic_read(&call->conn->hi_serial);
81414 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
81415 while (serial > hi_serial)
81416 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
81417 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
81418 serial);
81419
81420 /* request ACK generation for any ACK or DATA packet that requests
81421 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
81422 index a693aca..81e7293 100644
81423 --- a/net/rxrpc/ar-internal.h
81424 +++ b/net/rxrpc/ar-internal.h
81425 @@ -272,8 +272,8 @@ struct rxrpc_connection {
81426 int error; /* error code for local abort */
81427 int debug_id; /* debug ID for printks */
81428 unsigned int call_counter; /* call ID counter */
81429 - atomic_t serial; /* packet serial number counter */
81430 - atomic_t hi_serial; /* highest serial number received */
81431 + atomic_unchecked_t serial; /* packet serial number counter */
81432 + atomic_unchecked_t hi_serial; /* highest serial number received */
81433 u8 avail_calls; /* number of calls available */
81434 u8 size_align; /* data size alignment (for security) */
81435 u8 header_size; /* rxrpc + security header size */
81436 @@ -346,7 +346,7 @@ struct rxrpc_call {
81437 spinlock_t lock;
81438 rwlock_t state_lock; /* lock for state transition */
81439 atomic_t usage;
81440 - atomic_t sequence; /* Tx data packet sequence counter */
81441 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
81442 u32 abort_code; /* local/remote abort code */
81443 enum { /* current state of call */
81444 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
81445 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
81446 */
81447 extern atomic_t rxrpc_n_skbs;
81448 extern __be32 rxrpc_epoch;
81449 -extern atomic_t rxrpc_debug_id;
81450 +extern atomic_unchecked_t rxrpc_debug_id;
81451 extern struct workqueue_struct *rxrpc_workqueue;
81452
81453 /*
81454 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
81455 index 87f7135..74d3703 100644
81456 --- a/net/rxrpc/ar-local.c
81457 +++ b/net/rxrpc/ar-local.c
81458 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
81459 spin_lock_init(&local->lock);
81460 rwlock_init(&local->services_lock);
81461 atomic_set(&local->usage, 1);
81462 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
81463 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81464 memcpy(&local->srx, srx, sizeof(*srx));
81465 }
81466
81467 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
81468 index e1ac183..b43e10e 100644
81469 --- a/net/rxrpc/ar-output.c
81470 +++ b/net/rxrpc/ar-output.c
81471 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
81472 sp->hdr.cid = call->cid;
81473 sp->hdr.callNumber = call->call_id;
81474 sp->hdr.seq =
81475 - htonl(atomic_inc_return(&call->sequence));
81476 + htonl(atomic_inc_return_unchecked(&call->sequence));
81477 sp->hdr.serial =
81478 - htonl(atomic_inc_return(&conn->serial));
81479 + htonl(atomic_inc_return_unchecked(&conn->serial));
81480 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
81481 sp->hdr.userStatus = 0;
81482 sp->hdr.securityIndex = conn->security_ix;
81483 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
81484 index bebaa43..2644591 100644
81485 --- a/net/rxrpc/ar-peer.c
81486 +++ b/net/rxrpc/ar-peer.c
81487 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
81488 INIT_LIST_HEAD(&peer->error_targets);
81489 spin_lock_init(&peer->lock);
81490 atomic_set(&peer->usage, 1);
81491 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
81492 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81493 memcpy(&peer->srx, srx, sizeof(*srx));
81494
81495 rxrpc_assess_MTU_size(peer);
81496 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
81497 index 38047f7..9f48511 100644
81498 --- a/net/rxrpc/ar-proc.c
81499 +++ b/net/rxrpc/ar-proc.c
81500 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
81501 atomic_read(&conn->usage),
81502 rxrpc_conn_states[conn->state],
81503 key_serial(conn->key),
81504 - atomic_read(&conn->serial),
81505 - atomic_read(&conn->hi_serial));
81506 + atomic_read_unchecked(&conn->serial),
81507 + atomic_read_unchecked(&conn->hi_serial));
81508
81509 return 0;
81510 }
81511 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
81512 index 92df566..87ec1bf 100644
81513 --- a/net/rxrpc/ar-transport.c
81514 +++ b/net/rxrpc/ar-transport.c
81515 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
81516 spin_lock_init(&trans->client_lock);
81517 rwlock_init(&trans->conn_lock);
81518 atomic_set(&trans->usage, 1);
81519 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
81520 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81521
81522 if (peer->srx.transport.family == AF_INET) {
81523 switch (peer->srx.transport_type) {
81524 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
81525 index f226709..0e735a8 100644
81526 --- a/net/rxrpc/rxkad.c
81527 +++ b/net/rxrpc/rxkad.c
81528 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
81529
81530 len = iov[0].iov_len + iov[1].iov_len;
81531
81532 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81533 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81534 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
81535
81536 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81537 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
81538
81539 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
81540
81541 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
81542 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81543 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
81544
81545 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
81546 diff --git a/net/sctp/auth.c b/net/sctp/auth.c
81547 index 159b9bc..d8420ae 100644
81548 --- a/net/sctp/auth.c
81549 +++ b/net/sctp/auth.c
81550 @@ -71,7 +71,7 @@ void sctp_auth_key_put(struct sctp_auth_bytes *key)
81551 return;
81552
81553 if (atomic_dec_and_test(&key->refcnt)) {
81554 - kfree(key);
81555 + kzfree(key);
81556 SCTP_DBG_OBJCNT_DEC(keys);
81557 }
81558 }
81559 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
81560 index ea14cb4..834e8e4 100644
81561 --- a/net/sctp/ipv6.c
81562 +++ b/net/sctp/ipv6.c
81563 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
81564
81565 void sctp_v6_pf_exit(void)
81566 {
81567 - list_del(&sctp_af_inet6.list);
81568 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
81569 }
81570
81571 /* Initialize IPv6 support and register with socket layer. */
81572 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
81573 index 9966e7b..540c575 100644
81574 --- a/net/sctp/proc.c
81575 +++ b/net/sctp/proc.c
81576 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
81577 seq_printf(seq,
81578 "%8pK %8pK %-3d %-3d %-2d %-4d "
81579 "%4d %8d %8d %7d %5lu %-5d %5d ",
81580 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
81581 + assoc, sk,
81582 + sctp_sk(sk)->type, sk->sk_state,
81583 assoc->state, hash,
81584 assoc->assoc_id,
81585 assoc->sndbuf_used,
81586 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
81587 index 2d51842..150ba5c 100644
81588 --- a/net/sctp/protocol.c
81589 +++ b/net/sctp/protocol.c
81590 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
81591 return 0;
81592 }
81593
81594 - INIT_LIST_HEAD(&af->list);
81595 - list_add_tail(&af->list, &sctp_address_families);
81596 + pax_open_kernel();
81597 + INIT_LIST_HEAD((struct list_head *)&af->list);
81598 + pax_close_kernel();
81599 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
81600 return 1;
81601 }
81602
81603 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
81604
81605 static void sctp_v4_pf_exit(void)
81606 {
81607 - list_del(&sctp_af_inet.list);
81608 + pax_list_del((struct list_head *)&sctp_af_inet.list);
81609 }
81610
81611 static int sctp_v4_protosw_init(void)
81612 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
81613 index 9261d9a..0a6ae623 100644
81614 --- a/net/sctp/socket.c
81615 +++ b/net/sctp/socket.c
81616 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
81617 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
81618 if (space_left < addrlen)
81619 return -ENOMEM;
81620 + if (addrlen > sizeof(temp) || addrlen < 0)
81621 + return -EFAULT;
81622 if (copy_to_user(to, &temp, addrlen))
81623 return -EFAULT;
81624 to += addrlen;
81625 diff --git a/net/socket.c b/net/socket.c
81626 index d92c490..b4bc863 100644
81627 --- a/net/socket.c
81628 +++ b/net/socket.c
81629 @@ -89,6 +89,7 @@
81630 #include <linux/magic.h>
81631 #include <linux/slab.h>
81632 #include <linux/xattr.h>
81633 +#include <linux/in.h>
81634
81635 #include <asm/uaccess.h>
81636 #include <asm/unistd.h>
81637 @@ -106,6 +107,8 @@
81638 #include <linux/sockios.h>
81639 #include <linux/atalk.h>
81640
81641 +#include <linux/grsock.h>
81642 +
81643 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
81644 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
81645 unsigned long nr_segs, loff_t pos);
81646 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
81647 &sockfs_dentry_operations, SOCKFS_MAGIC);
81648 }
81649
81650 -static struct vfsmount *sock_mnt __read_mostly;
81651 +struct vfsmount *sock_mnt __read_mostly;
81652
81653 static struct file_system_type sock_fs_type = {
81654 .name = "sockfs",
81655 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
81656 return -EAFNOSUPPORT;
81657 if (type < 0 || type >= SOCK_MAX)
81658 return -EINVAL;
81659 + if (protocol < 0)
81660 + return -EINVAL;
81661
81662 /* Compatibility.
81663
81664 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
81665 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
81666 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
81667
81668 + if(!gr_search_socket(family, type, protocol)) {
81669 + retval = -EACCES;
81670 + goto out;
81671 + }
81672 +
81673 + if (gr_handle_sock_all(family, type, protocol)) {
81674 + retval = -EACCES;
81675 + goto out;
81676 + }
81677 +
81678 retval = sock_create(family, type, protocol, &sock);
81679 if (retval < 0)
81680 goto out;
81681 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81682 if (sock) {
81683 err = move_addr_to_kernel(umyaddr, addrlen, &address);
81684 if (err >= 0) {
81685 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
81686 + err = -EACCES;
81687 + goto error;
81688 + }
81689 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
81690 + if (err)
81691 + goto error;
81692 +
81693 err = security_socket_bind(sock,
81694 (struct sockaddr *)&address,
81695 addrlen);
81696 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81697 (struct sockaddr *)
81698 &address, addrlen);
81699 }
81700 +error:
81701 fput_light(sock->file, fput_needed);
81702 }
81703 return err;
81704 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
81705 if ((unsigned int)backlog > somaxconn)
81706 backlog = somaxconn;
81707
81708 + if (gr_handle_sock_server_other(sock->sk)) {
81709 + err = -EPERM;
81710 + goto error;
81711 + }
81712 +
81713 + err = gr_search_listen(sock);
81714 + if (err)
81715 + goto error;
81716 +
81717 err = security_socket_listen(sock, backlog);
81718 if (!err)
81719 err = sock->ops->listen(sock, backlog);
81720
81721 +error:
81722 fput_light(sock->file, fput_needed);
81723 }
81724 return err;
81725 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81726 newsock->type = sock->type;
81727 newsock->ops = sock->ops;
81728
81729 + if (gr_handle_sock_server_other(sock->sk)) {
81730 + err = -EPERM;
81731 + sock_release(newsock);
81732 + goto out_put;
81733 + }
81734 +
81735 + err = gr_search_accept(sock);
81736 + if (err) {
81737 + sock_release(newsock);
81738 + goto out_put;
81739 + }
81740 +
81741 /*
81742 * We don't need try_module_get here, as the listening socket (sock)
81743 * has the protocol module (sock->ops->owner) held.
81744 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81745 fd_install(newfd, newfile);
81746 err = newfd;
81747
81748 + gr_attach_curr_ip(newsock->sk);
81749 +
81750 out_put:
81751 fput_light(sock->file, fput_needed);
81752 out:
81753 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81754 int, addrlen)
81755 {
81756 struct socket *sock;
81757 + struct sockaddr *sck;
81758 struct sockaddr_storage address;
81759 int err, fput_needed;
81760
81761 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81762 if (err < 0)
81763 goto out_put;
81764
81765 + sck = (struct sockaddr *)&address;
81766 +
81767 + if (gr_handle_sock_client(sck)) {
81768 + err = -EACCES;
81769 + goto out_put;
81770 + }
81771 +
81772 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
81773 + if (err)
81774 + goto out_put;
81775 +
81776 err =
81777 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
81778 if (err)
81779 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
81780 * checking falls down on this.
81781 */
81782 if (copy_from_user(ctl_buf,
81783 - (void __user __force *)msg_sys->msg_control,
81784 + (void __force_user *)msg_sys->msg_control,
81785 ctl_len))
81786 goto out_freectl;
81787 msg_sys->msg_control = ctl_buf;
81788 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
81789 * kernel msghdr to use the kernel address space)
81790 */
81791
81792 - uaddr = (__force void __user *)msg_sys->msg_name;
81793 + uaddr = (void __force_user *)msg_sys->msg_name;
81794 uaddr_len = COMPAT_NAMELEN(msg);
81795 if (MSG_CMSG_COMPAT & flags) {
81796 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
81797 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81798 }
81799
81800 ifr = compat_alloc_user_space(buf_size);
81801 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
81802 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
81803
81804 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
81805 return -EFAULT;
81806 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81807 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
81808
81809 if (copy_in_user(rxnfc, compat_rxnfc,
81810 - (void *)(&rxnfc->fs.m_ext + 1) -
81811 - (void *)rxnfc) ||
81812 + (void __user *)(&rxnfc->fs.m_ext + 1) -
81813 + (void __user *)rxnfc) ||
81814 copy_in_user(&rxnfc->fs.ring_cookie,
81815 &compat_rxnfc->fs.ring_cookie,
81816 - (void *)(&rxnfc->fs.location + 1) -
81817 - (void *)&rxnfc->fs.ring_cookie) ||
81818 + (void __user *)(&rxnfc->fs.location + 1) -
81819 + (void __user *)&rxnfc->fs.ring_cookie) ||
81820 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
81821 sizeof(rxnfc->rule_cnt)))
81822 return -EFAULT;
81823 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81824
81825 if (convert_out) {
81826 if (copy_in_user(compat_rxnfc, rxnfc,
81827 - (const void *)(&rxnfc->fs.m_ext + 1) -
81828 - (const void *)rxnfc) ||
81829 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
81830 + (const void __user *)rxnfc) ||
81831 copy_in_user(&compat_rxnfc->fs.ring_cookie,
81832 &rxnfc->fs.ring_cookie,
81833 - (const void *)(&rxnfc->fs.location + 1) -
81834 - (const void *)&rxnfc->fs.ring_cookie) ||
81835 + (const void __user *)(&rxnfc->fs.location + 1) -
81836 + (const void __user *)&rxnfc->fs.ring_cookie) ||
81837 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
81838 sizeof(rxnfc->rule_cnt)))
81839 return -EFAULT;
81840 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
81841 old_fs = get_fs();
81842 set_fs(KERNEL_DS);
81843 err = dev_ioctl(net, cmd,
81844 - (struct ifreq __user __force *) &kifr);
81845 + (struct ifreq __force_user *) &kifr);
81846 set_fs(old_fs);
81847
81848 return err;
81849 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
81850
81851 old_fs = get_fs();
81852 set_fs(KERNEL_DS);
81853 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
81854 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
81855 set_fs(old_fs);
81856
81857 if (cmd == SIOCGIFMAP && !err) {
81858 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
81859 ret |= __get_user(rtdev, &(ur4->rt_dev));
81860 if (rtdev) {
81861 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
81862 - r4.rt_dev = (char __user __force *)devname;
81863 + r4.rt_dev = (char __force_user *)devname;
81864 devname[15] = 0;
81865 } else
81866 r4.rt_dev = NULL;
81867 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
81868 int __user *uoptlen;
81869 int err;
81870
81871 - uoptval = (char __user __force *) optval;
81872 - uoptlen = (int __user __force *) optlen;
81873 + uoptval = (char __force_user *) optval;
81874 + uoptlen = (int __force_user *) optlen;
81875
81876 set_fs(KERNEL_DS);
81877 if (level == SOL_SOCKET)
81878 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
81879 char __user *uoptval;
81880 int err;
81881
81882 - uoptval = (char __user __force *) optval;
81883 + uoptval = (char __force_user *) optval;
81884
81885 set_fs(KERNEL_DS);
81886 if (level == SOL_SOCKET)
81887 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
81888 index 7865b44..174662e 100644
81889 --- a/net/sunrpc/sched.c
81890 +++ b/net/sunrpc/sched.c
81891 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
81892 #ifdef RPC_DEBUG
81893 static void rpc_task_set_debuginfo(struct rpc_task *task)
81894 {
81895 - static atomic_t rpc_pid;
81896 + static atomic_unchecked_t rpc_pid;
81897
81898 - task->tk_pid = atomic_inc_return(&rpc_pid);
81899 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
81900 }
81901 #else
81902 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
81903 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
81904 index 8343737..677025e 100644
81905 --- a/net/sunrpc/xprtrdma/svc_rdma.c
81906 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
81907 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
81908 static unsigned int min_max_inline = 4096;
81909 static unsigned int max_max_inline = 65536;
81910
81911 -atomic_t rdma_stat_recv;
81912 -atomic_t rdma_stat_read;
81913 -atomic_t rdma_stat_write;
81914 -atomic_t rdma_stat_sq_starve;
81915 -atomic_t rdma_stat_rq_starve;
81916 -atomic_t rdma_stat_rq_poll;
81917 -atomic_t rdma_stat_rq_prod;
81918 -atomic_t rdma_stat_sq_poll;
81919 -atomic_t rdma_stat_sq_prod;
81920 +atomic_unchecked_t rdma_stat_recv;
81921 +atomic_unchecked_t rdma_stat_read;
81922 +atomic_unchecked_t rdma_stat_write;
81923 +atomic_unchecked_t rdma_stat_sq_starve;
81924 +atomic_unchecked_t rdma_stat_rq_starve;
81925 +atomic_unchecked_t rdma_stat_rq_poll;
81926 +atomic_unchecked_t rdma_stat_rq_prod;
81927 +atomic_unchecked_t rdma_stat_sq_poll;
81928 +atomic_unchecked_t rdma_stat_sq_prod;
81929
81930 /* Temporary NFS request map and context caches */
81931 struct kmem_cache *svc_rdma_map_cachep;
81932 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
81933 len -= *ppos;
81934 if (len > *lenp)
81935 len = *lenp;
81936 - if (len && copy_to_user(buffer, str_buf, len))
81937 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
81938 return -EFAULT;
81939 *lenp = len;
81940 *ppos += len;
81941 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
81942 {
81943 .procname = "rdma_stat_read",
81944 .data = &rdma_stat_read,
81945 - .maxlen = sizeof(atomic_t),
81946 + .maxlen = sizeof(atomic_unchecked_t),
81947 .mode = 0644,
81948 .proc_handler = read_reset_stat,
81949 },
81950 {
81951 .procname = "rdma_stat_recv",
81952 .data = &rdma_stat_recv,
81953 - .maxlen = sizeof(atomic_t),
81954 + .maxlen = sizeof(atomic_unchecked_t),
81955 .mode = 0644,
81956 .proc_handler = read_reset_stat,
81957 },
81958 {
81959 .procname = "rdma_stat_write",
81960 .data = &rdma_stat_write,
81961 - .maxlen = sizeof(atomic_t),
81962 + .maxlen = sizeof(atomic_unchecked_t),
81963 .mode = 0644,
81964 .proc_handler = read_reset_stat,
81965 },
81966 {
81967 .procname = "rdma_stat_sq_starve",
81968 .data = &rdma_stat_sq_starve,
81969 - .maxlen = sizeof(atomic_t),
81970 + .maxlen = sizeof(atomic_unchecked_t),
81971 .mode = 0644,
81972 .proc_handler = read_reset_stat,
81973 },
81974 {
81975 .procname = "rdma_stat_rq_starve",
81976 .data = &rdma_stat_rq_starve,
81977 - .maxlen = sizeof(atomic_t),
81978 + .maxlen = sizeof(atomic_unchecked_t),
81979 .mode = 0644,
81980 .proc_handler = read_reset_stat,
81981 },
81982 {
81983 .procname = "rdma_stat_rq_poll",
81984 .data = &rdma_stat_rq_poll,
81985 - .maxlen = sizeof(atomic_t),
81986 + .maxlen = sizeof(atomic_unchecked_t),
81987 .mode = 0644,
81988 .proc_handler = read_reset_stat,
81989 },
81990 {
81991 .procname = "rdma_stat_rq_prod",
81992 .data = &rdma_stat_rq_prod,
81993 - .maxlen = sizeof(atomic_t),
81994 + .maxlen = sizeof(atomic_unchecked_t),
81995 .mode = 0644,
81996 .proc_handler = read_reset_stat,
81997 },
81998 {
81999 .procname = "rdma_stat_sq_poll",
82000 .data = &rdma_stat_sq_poll,
82001 - .maxlen = sizeof(atomic_t),
82002 + .maxlen = sizeof(atomic_unchecked_t),
82003 .mode = 0644,
82004 .proc_handler = read_reset_stat,
82005 },
82006 {
82007 .procname = "rdma_stat_sq_prod",
82008 .data = &rdma_stat_sq_prod,
82009 - .maxlen = sizeof(atomic_t),
82010 + .maxlen = sizeof(atomic_unchecked_t),
82011 .mode = 0644,
82012 .proc_handler = read_reset_stat,
82013 },
82014 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82015 index 41cb63b..c4a1489 100644
82016 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82017 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82018 @@ -501,7 +501,7 @@ next_sge:
82019 svc_rdma_put_context(ctxt, 0);
82020 goto out;
82021 }
82022 - atomic_inc(&rdma_stat_read);
82023 + atomic_inc_unchecked(&rdma_stat_read);
82024
82025 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
82026 chl_map->ch[ch_no].count -= read_wr.num_sge;
82027 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82028 dto_q);
82029 list_del_init(&ctxt->dto_q);
82030 } else {
82031 - atomic_inc(&rdma_stat_rq_starve);
82032 + atomic_inc_unchecked(&rdma_stat_rq_starve);
82033 clear_bit(XPT_DATA, &xprt->xpt_flags);
82034 ctxt = NULL;
82035 }
82036 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82037 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
82038 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
82039 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
82040 - atomic_inc(&rdma_stat_recv);
82041 + atomic_inc_unchecked(&rdma_stat_recv);
82042
82043 /* Build up the XDR from the receive buffers. */
82044 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
82045 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82046 index 42eb7ba..c887c45 100644
82047 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82048 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82049 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
82050 write_wr.wr.rdma.remote_addr = to;
82051
82052 /* Post It */
82053 - atomic_inc(&rdma_stat_write);
82054 + atomic_inc_unchecked(&rdma_stat_write);
82055 if (svc_rdma_send(xprt, &write_wr))
82056 goto err;
82057 return 0;
82058 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82059 index 62e4f9b..dd3f2d7 100644
82060 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
82061 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82062 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82063 return;
82064
82065 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
82066 - atomic_inc(&rdma_stat_rq_poll);
82067 + atomic_inc_unchecked(&rdma_stat_rq_poll);
82068
82069 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
82070 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
82071 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82072 }
82073
82074 if (ctxt)
82075 - atomic_inc(&rdma_stat_rq_prod);
82076 + atomic_inc_unchecked(&rdma_stat_rq_prod);
82077
82078 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
82079 /*
82080 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82081 return;
82082
82083 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
82084 - atomic_inc(&rdma_stat_sq_poll);
82085 + atomic_inc_unchecked(&rdma_stat_sq_poll);
82086 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
82087 if (wc.status != IB_WC_SUCCESS)
82088 /* Close the transport */
82089 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82090 }
82091
82092 if (ctxt)
82093 - atomic_inc(&rdma_stat_sq_prod);
82094 + atomic_inc_unchecked(&rdma_stat_sq_prod);
82095 }
82096
82097 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
82098 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
82099 spin_lock_bh(&xprt->sc_lock);
82100 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
82101 spin_unlock_bh(&xprt->sc_lock);
82102 - atomic_inc(&rdma_stat_sq_starve);
82103 + atomic_inc_unchecked(&rdma_stat_sq_starve);
82104
82105 /* See if we can opportunistically reap SQ WR to make room */
82106 sq_cq_reap(xprt);
82107 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
82108 index e3a6e37..be2ea77 100644
82109 --- a/net/sysctl_net.c
82110 +++ b/net/sysctl_net.c
82111 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
82112 struct ctl_table *table)
82113 {
82114 /* Allow network administrator to have same access as root. */
82115 - if (capable(CAP_NET_ADMIN)) {
82116 + if (capable_nolog(CAP_NET_ADMIN)) {
82117 int mode = (table->mode >> 6) & 7;
82118 return (mode << 6) | (mode << 3) | mode;
82119 }
82120 diff --git a/net/tipc/link.c b/net/tipc/link.c
82121 index a79c755..eca357d 100644
82122 --- a/net/tipc/link.c
82123 +++ b/net/tipc/link.c
82124 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
82125 struct tipc_msg fragm_hdr;
82126 struct sk_buff *buf, *buf_chain, *prev;
82127 u32 fragm_crs, fragm_rest, hsz, sect_rest;
82128 - const unchar *sect_crs;
82129 + const unchar __user *sect_crs;
82130 int curr_sect;
82131 u32 fragm_no;
82132
82133 @@ -1210,7 +1210,7 @@ again:
82134
82135 if (!sect_rest) {
82136 sect_rest = msg_sect[++curr_sect].iov_len;
82137 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
82138 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
82139 }
82140
82141 if (sect_rest < fragm_rest)
82142 @@ -1229,7 +1229,7 @@ error:
82143 }
82144 } else
82145 skb_copy_to_linear_data_offset(buf, fragm_crs,
82146 - sect_crs, sz);
82147 + (const void __force_kernel *)sect_crs, sz);
82148 sect_crs += sz;
82149 sect_rest -= sz;
82150 fragm_crs += sz;
82151 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
82152 index f2db8a8..9245aa4 100644
82153 --- a/net/tipc/msg.c
82154 +++ b/net/tipc/msg.c
82155 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
82156 msg_sect[cnt].iov_len);
82157 else
82158 skb_copy_to_linear_data_offset(*buf, pos,
82159 - msg_sect[cnt].iov_base,
82160 + (const void __force_kernel *)msg_sect[cnt].iov_base,
82161 msg_sect[cnt].iov_len);
82162 pos += msg_sect[cnt].iov_len;
82163 }
82164 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
82165 index 0f7d0d0..00f89bf 100644
82166 --- a/net/tipc/subscr.c
82167 +++ b/net/tipc/subscr.c
82168 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
82169 {
82170 struct iovec msg_sect;
82171
82172 - msg_sect.iov_base = (void *)&sub->evt;
82173 + msg_sect.iov_base = (void __force_user *)&sub->evt;
82174 msg_sect.iov_len = sizeof(struct tipc_event);
82175
82176 sub->evt.event = htohl(event, sub->swap);
82177 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82178 index 5b5c876..3127bf7 100644
82179 --- a/net/unix/af_unix.c
82180 +++ b/net/unix/af_unix.c
82181 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
82182 err = -ECONNREFUSED;
82183 if (!S_ISSOCK(inode->i_mode))
82184 goto put_fail;
82185 +
82186 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82187 + err = -EACCES;
82188 + goto put_fail;
82189 + }
82190 +
82191 u = unix_find_socket_byinode(inode);
82192 if (!u)
82193 goto put_fail;
82194 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
82195 if (u) {
82196 struct dentry *dentry;
82197 dentry = unix_sk(u)->path.dentry;
82198 +
82199 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
82200 + err = -EPERM;
82201 + sock_put(u);
82202 + goto fail;
82203 + }
82204 +
82205 if (dentry)
82206 touch_atime(&unix_sk(u)->path);
82207 } else
82208 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
82209 */
82210 err = security_path_mknod(&path, dentry, mode, 0);
82211 if (!err) {
82212 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
82213 + err = -EACCES;
82214 + goto out;
82215 + }
82216 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
82217 if (!err) {
82218 res->mnt = mntget(path.mnt);
82219 res->dentry = dget(dentry);
82220 + gr_handle_create(dentry, path.mnt);
82221 }
82222 }
82223 +out:
82224 done_path_create(&path, dentry);
82225 return err;
82226 }
82227 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
82228 index c8717c1..08539f5 100644
82229 --- a/net/wireless/wext-core.c
82230 +++ b/net/wireless/wext-core.c
82231 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82232 */
82233
82234 /* Support for very large requests */
82235 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
82236 - (user_length > descr->max_tokens)) {
82237 + if (user_length > descr->max_tokens) {
82238 /* Allow userspace to GET more than max so
82239 * we can support any size GET requests.
82240 * There is still a limit : -ENOMEM.
82241 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82242 }
82243 }
82244
82245 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
82246 - /*
82247 - * If this is a GET, but not NOMAX, it means that the extra
82248 - * data is not bounded by userspace, but by max_tokens. Thus
82249 - * set the length to max_tokens. This matches the extra data
82250 - * allocation.
82251 - * The driver should fill it with the number of tokens it
82252 - * provided, and it may check iwp->length rather than having
82253 - * knowledge of max_tokens. If the driver doesn't change the
82254 - * iwp->length, this ioctl just copies back max_token tokens
82255 - * filled with zeroes. Hopefully the driver isn't claiming
82256 - * them to be valid data.
82257 - */
82258 - iwp->length = descr->max_tokens;
82259 - }
82260 -
82261 err = handler(dev, info, (union iwreq_data *) iwp, extra);
82262
82263 iwp->length += essid_compat;
82264 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
82265 index 41eabc4..8d4e6d6 100644
82266 --- a/net/xfrm/xfrm_policy.c
82267 +++ b/net/xfrm/xfrm_policy.c
82268 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
82269 {
82270 policy->walk.dead = 1;
82271
82272 - atomic_inc(&policy->genid);
82273 + atomic_inc_unchecked(&policy->genid);
82274
82275 if (del_timer(&policy->timer))
82276 xfrm_pol_put(policy);
82277 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
82278 hlist_add_head(&policy->bydst, chain);
82279 xfrm_pol_hold(policy);
82280 net->xfrm.policy_count[dir]++;
82281 - atomic_inc(&flow_cache_genid);
82282 + atomic_inc_unchecked(&flow_cache_genid);
82283 rt_genid_bump(net);
82284 if (delpol)
82285 __xfrm_policy_unlink(delpol, dir);
82286 @@ -1550,7 +1550,7 @@ free_dst:
82287 goto out;
82288 }
82289
82290 -static int inline
82291 +static inline int
82292 xfrm_dst_alloc_copy(void **target, const void *src, int size)
82293 {
82294 if (!*target) {
82295 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
82296 return 0;
82297 }
82298
82299 -static int inline
82300 +static inline int
82301 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82302 {
82303 #ifdef CONFIG_XFRM_SUB_POLICY
82304 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82305 #endif
82306 }
82307
82308 -static int inline
82309 +static inline int
82310 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
82311 {
82312 #ifdef CONFIG_XFRM_SUB_POLICY
82313 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
82314
82315 xdst->num_pols = num_pols;
82316 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
82317 - xdst->policy_genid = atomic_read(&pols[0]->genid);
82318 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
82319
82320 return xdst;
82321 }
82322 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
82323 if (xdst->xfrm_genid != dst->xfrm->genid)
82324 return 0;
82325 if (xdst->num_pols > 0 &&
82326 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
82327 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
82328 return 0;
82329
82330 mtu = dst_mtu(dst->child);
82331 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
82332 sizeof(pol->xfrm_vec[i].saddr));
82333 pol->xfrm_vec[i].encap_family = mp->new_family;
82334 /* flush bundles */
82335 - atomic_inc(&pol->genid);
82336 + atomic_inc_unchecked(&pol->genid);
82337 }
82338 }
82339
82340 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
82341 index 3459692..eefb515 100644
82342 --- a/net/xfrm/xfrm_state.c
82343 +++ b/net/xfrm/xfrm_state.c
82344 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
82345 if (!try_module_get(afinfo->owner))
82346 goto out;
82347
82348 - mode->afinfo = afinfo;
82349 + pax_open_kernel();
82350 + *(void **)&mode->afinfo = afinfo;
82351 + pax_close_kernel();
82352 modemap[mode->encap] = mode;
82353 err = 0;
82354
82355 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
82356 index 0e801c3..5c8ad3b 100644
82357 --- a/scripts/Makefile.build
82358 +++ b/scripts/Makefile.build
82359 @@ -111,7 +111,7 @@ endif
82360 endif
82361
82362 # Do not include host rules unless needed
82363 -ifneq ($(hostprogs-y)$(hostprogs-m),)
82364 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
82365 include scripts/Makefile.host
82366 endif
82367
82368 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
82369 index 686cb0d..9d653bf 100644
82370 --- a/scripts/Makefile.clean
82371 +++ b/scripts/Makefile.clean
82372 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
82373 __clean-files := $(extra-y) $(always) \
82374 $(targets) $(clean-files) \
82375 $(host-progs) \
82376 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
82377 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
82378 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
82379
82380 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
82381
82382 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
82383 index 1ac414f..38575f7 100644
82384 --- a/scripts/Makefile.host
82385 +++ b/scripts/Makefile.host
82386 @@ -31,6 +31,8 @@
82387 # Note: Shared libraries consisting of C++ files are not supported
82388
82389 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
82390 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
82391 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
82392
82393 # C code
82394 # Executables compiled from a single .c file
82395 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
82396 # Shared libaries (only .c supported)
82397 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
82398 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
82399 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
82400 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
82401 # Remove .so files from "xxx-objs"
82402 host-cobjs := $(filter-out %.so,$(host-cobjs))
82403 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
82404
82405 -#Object (.o) files used by the shared libaries
82406 +# Object (.o) files used by the shared libaries
82407 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
82408 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
82409
82410 # output directory for programs/.o files
82411 # hostprogs-y := tools/build may have been specified. Retrieve directory
82412 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82413 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
82414 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
82415 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
82416 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
82417 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
82418 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
82419 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
82420
82421 obj-dirs += $(host-objdirs)
82422 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
82423 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
82424 $(call if_changed_dep,host-cshobjs)
82425
82426 +# Compile .c file, create position independent .o file
82427 +# host-cxxshobjs -> .o
82428 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
82429 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
82430 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
82431 + $(call if_changed_dep,host-cxxshobjs)
82432 +
82433 # Link a shared library, based on position independent .o files
82434 # *.o -> .so shared library (host-cshlib)
82435 quiet_cmd_host-cshlib = HOSTLLD -shared $@
82436 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
82437 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
82438 $(call if_changed,host-cshlib)
82439
82440 +# Link a shared library, based on position independent .o files
82441 +# *.o -> .so shared library (host-cxxshlib)
82442 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
82443 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
82444 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
82445 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
82446 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
82447 + $(call if_changed,host-cxxshlib)
82448 +
82449 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
82450 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
82451 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
82452
82453 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
82454 index cb1f50c..cef2a7c 100644
82455 --- a/scripts/basic/fixdep.c
82456 +++ b/scripts/basic/fixdep.c
82457 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
82458 /*
82459 * Lookup a value in the configuration string.
82460 */
82461 -static int is_defined_config(const char *name, int len, unsigned int hash)
82462 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
82463 {
82464 struct item *aux;
82465
82466 @@ -211,10 +211,10 @@ static void clear_config(void)
82467 /*
82468 * Record the use of a CONFIG_* word.
82469 */
82470 -static void use_config(const char *m, int slen)
82471 +static void use_config(const char *m, unsigned int slen)
82472 {
82473 unsigned int hash = strhash(m, slen);
82474 - int c, i;
82475 + unsigned int c, i;
82476
82477 if (is_defined_config(m, slen, hash))
82478 return;
82479 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
82480
82481 static void parse_config_file(const char *map, size_t len)
82482 {
82483 - const int *end = (const int *) (map + len);
82484 + const unsigned int *end = (const unsigned int *) (map + len);
82485 /* start at +1, so that p can never be < map */
82486 - const int *m = (const int *) map + 1;
82487 + const unsigned int *m = (const unsigned int *) map + 1;
82488 const char *p, *q;
82489
82490 for (; m < end; m++) {
82491 @@ -406,7 +406,7 @@ static void print_deps(void)
82492 static void traps(void)
82493 {
82494 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
82495 - int *p = (int *)test;
82496 + unsigned int *p = (unsigned int *)test;
82497
82498 if (*p != INT_CONF) {
82499 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
82500 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
82501 new file mode 100644
82502 index 0000000..008ac1a
82503 --- /dev/null
82504 +++ b/scripts/gcc-plugin.sh
82505 @@ -0,0 +1,17 @@
82506 +#!/bin/bash
82507 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
82508 +#include "gcc-plugin.h"
82509 +#include "tree.h"
82510 +#include "tm.h"
82511 +#include "rtl.h"
82512 +#ifdef ENABLE_BUILD_WITH_CXX
82513 +#warning $2
82514 +#else
82515 +#warning $1
82516 +#endif
82517 +EOF`
82518 +if [ $? -eq 0 ]
82519 +then
82520 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
82521 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
82522 +fi
82523 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
82524 index b3d907e..a4782ab 100644
82525 --- a/scripts/link-vmlinux.sh
82526 +++ b/scripts/link-vmlinux.sh
82527 @@ -152,7 +152,7 @@ else
82528 fi;
82529
82530 # final build of init/
82531 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
82532 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
82533
82534 kallsymso=""
82535 kallsyms_vmlinux=""
82536 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
82537 index df4fc23..0ea719d 100644
82538 --- a/scripts/mod/file2alias.c
82539 +++ b/scripts/mod/file2alias.c
82540 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
82541 unsigned long size, unsigned long id_size,
82542 void *symval)
82543 {
82544 - int i;
82545 + unsigned int i;
82546
82547 if (size % id_size || size < id_size) {
82548 if (cross_build != 0)
82549 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
82550 /* USB is special because the bcdDevice can be matched against a numeric range */
82551 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
82552 static void do_usb_entry(struct usb_device_id *id,
82553 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
82554 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
82555 unsigned char range_lo, unsigned char range_hi,
82556 unsigned char max, struct module *mod)
82557 {
82558 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
82559 {
82560 unsigned int devlo, devhi;
82561 unsigned char chi, clo, max;
82562 - int ndigits;
82563 + unsigned int ndigits;
82564
82565 id->match_flags = TO_NATIVE(id->match_flags);
82566 id->idVendor = TO_NATIVE(id->idVendor);
82567 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
82568 for (i = 0; i < count; i++) {
82569 const char *id = (char *)devs[i].id;
82570 char acpi_id[sizeof(devs[0].id)];
82571 - int j;
82572 + unsigned int j;
82573
82574 buf_printf(&mod->dev_table_buf,
82575 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82576 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82577
82578 for (j = 0; j < PNP_MAX_DEVICES; j++) {
82579 const char *id = (char *)card->devs[j].id;
82580 - int i2, j2;
82581 + unsigned int i2, j2;
82582 int dup = 0;
82583
82584 if (!id[0])
82585 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82586 /* add an individual alias for every device entry */
82587 if (!dup) {
82588 char acpi_id[sizeof(card->devs[0].id)];
82589 - int k;
82590 + unsigned int k;
82591
82592 buf_printf(&mod->dev_table_buf,
82593 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82594 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
82595 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
82596 char *alias)
82597 {
82598 - int i, j;
82599 + unsigned int i, j;
82600
82601 sprintf(alias, "dmi*");
82602
82603 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
82604 index 0d93856..e828363 100644
82605 --- a/scripts/mod/modpost.c
82606 +++ b/scripts/mod/modpost.c
82607 @@ -933,6 +933,7 @@ enum mismatch {
82608 ANY_INIT_TO_ANY_EXIT,
82609 ANY_EXIT_TO_ANY_INIT,
82610 EXPORT_TO_INIT_EXIT,
82611 + DATA_TO_TEXT
82612 };
82613
82614 struct sectioncheck {
82615 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
82616 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
82617 .mismatch = EXPORT_TO_INIT_EXIT,
82618 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
82619 +},
82620 +/* Do not reference code from writable data */
82621 +{
82622 + .fromsec = { DATA_SECTIONS, NULL },
82623 + .tosec = { TEXT_SECTIONS, NULL },
82624 + .mismatch = DATA_TO_TEXT
82625 }
82626 };
82627
82628 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
82629 continue;
82630 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
82631 continue;
82632 - if (sym->st_value == addr)
82633 - return sym;
82634 /* Find a symbol nearby - addr are maybe negative */
82635 d = sym->st_value - addr;
82636 + if (d == 0)
82637 + return sym;
82638 if (d < 0)
82639 d = addr - sym->st_value;
82640 if (d < distance) {
82641 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
82642 tosym, prl_to, prl_to, tosym);
82643 free(prl_to);
82644 break;
82645 + case DATA_TO_TEXT:
82646 +#if 0
82647 + fprintf(stderr,
82648 + "The %s %s:%s references\n"
82649 + "the %s %s:%s%s\n",
82650 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82651 +#endif
82652 + break;
82653 }
82654 fprintf(stderr, "\n");
82655 }
82656 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
82657 static void check_sec_ref(struct module *mod, const char *modname,
82658 struct elf_info *elf)
82659 {
82660 - int i;
82661 + unsigned int i;
82662 Elf_Shdr *sechdrs = elf->sechdrs;
82663
82664 /* Walk through all sections */
82665 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
82666 va_end(ap);
82667 }
82668
82669 -void buf_write(struct buffer *buf, const char *s, int len)
82670 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
82671 {
82672 if (buf->size - buf->pos < len) {
82673 buf->size += len + SZ;
82674 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
82675 if (fstat(fileno(file), &st) < 0)
82676 goto close_write;
82677
82678 - if (st.st_size != b->pos)
82679 + if (st.st_size != (off_t)b->pos)
82680 goto close_write;
82681
82682 tmp = NOFAIL(malloc(b->pos));
82683 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
82684 index 51207e4..f7d603d 100644
82685 --- a/scripts/mod/modpost.h
82686 +++ b/scripts/mod/modpost.h
82687 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
82688
82689 struct buffer {
82690 char *p;
82691 - int pos;
82692 - int size;
82693 + unsigned int pos;
82694 + unsigned int size;
82695 };
82696
82697 void __attribute__((format(printf, 2, 3)))
82698 buf_printf(struct buffer *buf, const char *fmt, ...);
82699
82700 void
82701 -buf_write(struct buffer *buf, const char *s, int len);
82702 +buf_write(struct buffer *buf, const char *s, unsigned int len);
82703
82704 struct module {
82705 struct module *next;
82706 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
82707 index 9dfcd6d..099068e 100644
82708 --- a/scripts/mod/sumversion.c
82709 +++ b/scripts/mod/sumversion.c
82710 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
82711 goto out;
82712 }
82713
82714 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
82715 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
82716 warn("writing sum in %s failed: %s\n",
82717 filename, strerror(errno));
82718 goto out;
82719 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
82720 index 5c11312..72742b5 100644
82721 --- a/scripts/pnmtologo.c
82722 +++ b/scripts/pnmtologo.c
82723 @@ -237,14 +237,14 @@ static void write_header(void)
82724 fprintf(out, " * Linux logo %s\n", logoname);
82725 fputs(" */\n\n", out);
82726 fputs("#include <linux/linux_logo.h>\n\n", out);
82727 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
82728 + fprintf(out, "static unsigned char %s_data[] = {\n",
82729 logoname);
82730 }
82731
82732 static void write_footer(void)
82733 {
82734 fputs("\n};\n\n", out);
82735 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
82736 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
82737 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
82738 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
82739 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
82740 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
82741 fputs("\n};\n\n", out);
82742
82743 /* write logo clut */
82744 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
82745 + fprintf(out, "static unsigned char %s_clut[] = {\n",
82746 logoname);
82747 write_hex_cnt = 0;
82748 for (i = 0; i < logo_clutsize; i++) {
82749 diff --git a/security/Kconfig b/security/Kconfig
82750 index e9c6ac7..01c698c 100644
82751 --- a/security/Kconfig
82752 +++ b/security/Kconfig
82753 @@ -4,6 +4,902 @@
82754
82755 menu "Security options"
82756
82757 +menu "Grsecurity"
82758 +
82759 + config ARCH_TRACK_EXEC_LIMIT
82760 + bool
82761 +
82762 + config PAX_KERNEXEC_PLUGIN
82763 + bool
82764 +
82765 + config PAX_PER_CPU_PGD
82766 + bool
82767 +
82768 + config TASK_SIZE_MAX_SHIFT
82769 + int
82770 + depends on X86_64
82771 + default 47 if !PAX_PER_CPU_PGD
82772 + default 42 if PAX_PER_CPU_PGD
82773 +
82774 + config PAX_ENABLE_PAE
82775 + bool
82776 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
82777 +
82778 + config PAX_USERCOPY_SLABS
82779 + bool
82780 +
82781 +config GRKERNSEC
82782 + bool "Grsecurity"
82783 + select CRYPTO
82784 + select CRYPTO_SHA256
82785 + select PROC_FS
82786 + select STOP_MACHINE
82787 + help
82788 + If you say Y here, you will be able to configure many features
82789 + that will enhance the security of your system. It is highly
82790 + recommended that you say Y here and read through the help
82791 + for each option so that you fully understand the features and
82792 + can evaluate their usefulness for your machine.
82793 +
82794 +choice
82795 + prompt "Configuration Method"
82796 + depends on GRKERNSEC
82797 + default GRKERNSEC_CONFIG_CUSTOM
82798 + help
82799 +
82800 +config GRKERNSEC_CONFIG_AUTO
82801 + bool "Automatic"
82802 + help
82803 + If you choose this configuration method, you'll be able to answer a small
82804 + number of simple questions about how you plan to use this kernel.
82805 + The settings of grsecurity and PaX will be automatically configured for
82806 + the highest commonly-used settings within the provided constraints.
82807 +
82808 + If you require additional configuration, custom changes can still be made
82809 + from the "custom configuration" menu.
82810 +
82811 +config GRKERNSEC_CONFIG_CUSTOM
82812 + bool "Custom"
82813 + help
82814 + If you choose this configuration method, you'll be able to configure all
82815 + grsecurity and PaX settings manually. Via this method, no options are
82816 + automatically enabled.
82817 +
82818 +endchoice
82819 +
82820 +choice
82821 + prompt "Usage Type"
82822 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82823 + default GRKERNSEC_CONFIG_SERVER
82824 + help
82825 +
82826 +config GRKERNSEC_CONFIG_SERVER
82827 + bool "Server"
82828 + help
82829 + Choose this option if you plan to use this kernel on a server.
82830 +
82831 +config GRKERNSEC_CONFIG_DESKTOP
82832 + bool "Desktop"
82833 + help
82834 + Choose this option if you plan to use this kernel on a desktop.
82835 +
82836 +endchoice
82837 +
82838 +choice
82839 + prompt "Virtualization Type"
82840 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
82841 + default GRKERNSEC_CONFIG_VIRT_NONE
82842 + help
82843 +
82844 +config GRKERNSEC_CONFIG_VIRT_NONE
82845 + bool "None"
82846 + help
82847 + Choose this option if this kernel will be run on bare metal.
82848 +
82849 +config GRKERNSEC_CONFIG_VIRT_GUEST
82850 + bool "Guest"
82851 + help
82852 + Choose this option if this kernel will be run as a VM guest.
82853 +
82854 +config GRKERNSEC_CONFIG_VIRT_HOST
82855 + bool "Host"
82856 + help
82857 + Choose this option if this kernel will be run as a VM host.
82858 +
82859 +endchoice
82860 +
82861 +choice
82862 + prompt "Virtualization Hardware"
82863 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82864 + help
82865 +
82866 +config GRKERNSEC_CONFIG_VIRT_EPT
82867 + bool "EPT/RVI Processor Support"
82868 + depends on X86
82869 + help
82870 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
82871 + hardware virtualization. This allows for additional kernel hardening protections
82872 + to operate without additional performance impact.
82873 +
82874 + To see if your Intel processor supports EPT, see:
82875 + http://ark.intel.com/Products/VirtualizationTechnology
82876 + (Most Core i3/5/7 support EPT)
82877 +
82878 + To see if your AMD processor supports RVI, see:
82879 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
82880 +
82881 +config GRKERNSEC_CONFIG_VIRT_SOFT
82882 + bool "First-gen/No Hardware Virtualization"
82883 + help
82884 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
82885 + support hardware virtualization or doesn't support the EPT/RVI extensions.
82886 +
82887 +endchoice
82888 +
82889 +choice
82890 + prompt "Virtualization Software"
82891 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82892 + help
82893 +
82894 +config GRKERNSEC_CONFIG_VIRT_XEN
82895 + bool "Xen"
82896 + help
82897 + Choose this option if this kernel is running as a Xen guest or host.
82898 +
82899 +config GRKERNSEC_CONFIG_VIRT_VMWARE
82900 + bool "VMWare"
82901 + help
82902 + Choose this option if this kernel is running as a VMWare guest or host.
82903 +
82904 +config GRKERNSEC_CONFIG_VIRT_KVM
82905 + bool "KVM"
82906 + help
82907 + Choose this option if this kernel is running as a KVM guest or host.
82908 +
82909 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
82910 + bool "VirtualBox"
82911 + help
82912 + Choose this option if this kernel is running as a VirtualBox guest or host.
82913 +
82914 +endchoice
82915 +
82916 +choice
82917 + prompt "Required Priorities"
82918 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82919 + default GRKERNSEC_CONFIG_PRIORITY_PERF
82920 + help
82921 +
82922 +config GRKERNSEC_CONFIG_PRIORITY_PERF
82923 + bool "Performance"
82924 + help
82925 + Choose this option if performance is of highest priority for this deployment
82926 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
82927 + and freed memory sanitizing will be disabled.
82928 +
82929 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
82930 + bool "Security"
82931 + help
82932 + Choose this option if security is of highest priority for this deployment of
82933 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
82934 + be enabled for this kernel. In a worst-case scenario, these features can
82935 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
82936 +
82937 +endchoice
82938 +
82939 +menu "Default Special Groups"
82940 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82941 +
82942 +config GRKERNSEC_PROC_GID
82943 + int "GID exempted from /proc restrictions"
82944 + default 1001
82945 + help
82946 + Setting this GID determines which group will be exempted from
82947 + grsecurity's /proc restrictions, allowing users of the specified
82948 + group to view network statistics and the existence of other users'
82949 + processes on the system. This GID may also be chosen at boot time
82950 + via "grsec_proc_gid=" on the kernel commandline.
82951 +
82952 +config GRKERNSEC_TPE_UNTRUSTED_GID
82953 + int "GID for TPE-untrusted users"
82954 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
82955 + default 1005
82956 + help
82957 + Setting this GID determines which group untrusted users should
82958 + be added to. These users will be placed under grsecurity's Trusted Path
82959 + Execution mechanism, preventing them from executing their own binaries.
82960 + The users will only be able to execute binaries in directories owned and
82961 + writable only by the root user. If the sysctl option is enabled, a sysctl
82962 + option with name "tpe_gid" is created.
82963 +
82964 +config GRKERNSEC_TPE_TRUSTED_GID
82965 + int "GID for TPE-trusted users"
82966 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
82967 + default 1005
82968 + help
82969 + Setting this GID determines what group TPE restrictions will be
82970 + *disabled* for. If the sysctl option is enabled, a sysctl option
82971 + with name "tpe_gid" is created.
82972 +
82973 +config GRKERNSEC_SYMLINKOWN_GID
82974 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
82975 + depends on GRKERNSEC_CONFIG_SERVER
82976 + default 1006
82977 + help
82978 + Setting this GID determines what group kernel-enforced
82979 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
82980 + is enabled, a sysctl option with name "symlinkown_gid" is created.
82981 +
82982 +
82983 +endmenu
82984 +
82985 +menu "Customize Configuration"
82986 +depends on GRKERNSEC
82987 +
82988 +menu "PaX"
82989 +
82990 +config PAX
82991 + bool "Enable various PaX features"
82992 + default y if GRKERNSEC_CONFIG_AUTO
82993 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
82994 + help
82995 + This allows you to enable various PaX features. PaX adds
82996 + intrusion prevention mechanisms to the kernel that reduce
82997 + the risks posed by exploitable memory corruption bugs.
82998 +
82999 +menu "PaX Control"
83000 + depends on PAX
83001 +
83002 +config PAX_SOFTMODE
83003 + bool 'Support soft mode'
83004 + help
83005 + Enabling this option will allow you to run PaX in soft mode, that
83006 + is, PaX features will not be enforced by default, only on executables
83007 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
83008 + support as they are the only way to mark executables for soft mode use.
83009 +
83010 + Soft mode can be activated by using the "pax_softmode=1" kernel command
83011 + line option on boot. Furthermore you can control various PaX features
83012 + at runtime via the entries in /proc/sys/kernel/pax.
83013 +
83014 +config PAX_EI_PAX
83015 + bool 'Use legacy ELF header marking'
83016 + default y if GRKERNSEC_CONFIG_AUTO
83017 + help
83018 + Enabling this option will allow you to control PaX features on
83019 + a per executable basis via the 'chpax' utility available at
83020 + http://pax.grsecurity.net/. The control flags will be read from
83021 + an otherwise reserved part of the ELF header. This marking has
83022 + numerous drawbacks (no support for soft-mode, toolchain does not
83023 + know about the non-standard use of the ELF header) therefore it
83024 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
83025 + support.
83026 +
83027 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
83028 + support as well, they will override the legacy EI_PAX marks.
83029 +
83030 + If you enable none of the marking options then all applications
83031 + will run with PaX enabled on them by default.
83032 +
83033 +config PAX_PT_PAX_FLAGS
83034 + bool 'Use ELF program header marking'
83035 + default y if GRKERNSEC_CONFIG_AUTO
83036 + help
83037 + Enabling this option will allow you to control PaX features on
83038 + a per executable basis via the 'paxctl' utility available at
83039 + http://pax.grsecurity.net/. The control flags will be read from
83040 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
83041 + has the benefits of supporting both soft mode and being fully
83042 + integrated into the toolchain (the binutils patch is available
83043 + from http://pax.grsecurity.net).
83044 +
83045 + Note that if you enable the legacy EI_PAX marking support as well,
83046 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
83047 +
83048 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83049 + must make sure that the marks are the same if a binary has both marks.
83050 +
83051 + If you enable none of the marking options then all applications
83052 + will run with PaX enabled on them by default.
83053 +
83054 +config PAX_XATTR_PAX_FLAGS
83055 + bool 'Use filesystem extended attributes marking'
83056 + default y if GRKERNSEC_CONFIG_AUTO
83057 + select CIFS_XATTR if CIFS
83058 + select EXT2_FS_XATTR if EXT2_FS
83059 + select EXT3_FS_XATTR if EXT3_FS
83060 + select EXT4_FS_XATTR if EXT4_FS
83061 + select JFFS2_FS_XATTR if JFFS2_FS
83062 + select REISERFS_FS_XATTR if REISERFS_FS
83063 + select SQUASHFS_XATTR if SQUASHFS
83064 + select TMPFS_XATTR if TMPFS
83065 + select UBIFS_FS_XATTR if UBIFS_FS
83066 + help
83067 + Enabling this option will allow you to control PaX features on
83068 + a per executable basis via the 'setfattr' utility. The control
83069 + flags will be read from the user.pax.flags extended attribute of
83070 + the file. This marking has the benefit of supporting binary-only
83071 + applications that self-check themselves (e.g., skype) and would
83072 + not tolerate chpax/paxctl changes. The main drawback is that
83073 + extended attributes are not supported by some filesystems (e.g.,
83074 + isofs, udf, vfat) so copying files through such filesystems will
83075 + lose the extended attributes and these PaX markings.
83076 +
83077 + Note that if you enable the legacy EI_PAX marking support as well,
83078 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
83079 +
83080 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83081 + must make sure that the marks are the same if a binary has both marks.
83082 +
83083 + If you enable none of the marking options then all applications
83084 + will run with PaX enabled on them by default.
83085 +
83086 +choice
83087 + prompt 'MAC system integration'
83088 + default PAX_HAVE_ACL_FLAGS
83089 + help
83090 + Mandatory Access Control systems have the option of controlling
83091 + PaX flags on a per executable basis, choose the method supported
83092 + by your particular system.
83093 +
83094 + - "none": if your MAC system does not interact with PaX,
83095 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
83096 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
83097 +
83098 + NOTE: this option is for developers/integrators only.
83099 +
83100 + config PAX_NO_ACL_FLAGS
83101 + bool 'none'
83102 +
83103 + config PAX_HAVE_ACL_FLAGS
83104 + bool 'direct'
83105 +
83106 + config PAX_HOOK_ACL_FLAGS
83107 + bool 'hook'
83108 +endchoice
83109 +
83110 +endmenu
83111 +
83112 +menu "Non-executable pages"
83113 + depends on PAX
83114 +
83115 +config PAX_NOEXEC
83116 + bool "Enforce non-executable pages"
83117 + default y if GRKERNSEC_CONFIG_AUTO
83118 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
83119 + help
83120 + By design some architectures do not allow for protecting memory
83121 + pages against execution or even if they do, Linux does not make
83122 + use of this feature. In practice this means that if a page is
83123 + readable (such as the stack or heap) it is also executable.
83124 +
83125 + There is a well known exploit technique that makes use of this
83126 + fact and a common programming mistake where an attacker can
83127 + introduce code of his choice somewhere in the attacked program's
83128 + memory (typically the stack or the heap) and then execute it.
83129 +
83130 + If the attacked program was running with different (typically
83131 + higher) privileges than that of the attacker, then he can elevate
83132 + his own privilege level (e.g. get a root shell, write to files for
83133 + which he does not have write access to, etc).
83134 +
83135 + Enabling this option will let you choose from various features
83136 + that prevent the injection and execution of 'foreign' code in
83137 + a program.
83138 +
83139 + This will also break programs that rely on the old behaviour and
83140 + expect that dynamically allocated memory via the malloc() family
83141 + of functions is executable (which it is not). Notable examples
83142 + are the XFree86 4.x server, the java runtime and wine.
83143 +
83144 +config PAX_PAGEEXEC
83145 + bool "Paging based non-executable pages"
83146 + default y if GRKERNSEC_CONFIG_AUTO
83147 + 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)
83148 + select S390_SWITCH_AMODE if S390
83149 + select S390_EXEC_PROTECT if S390
83150 + select ARCH_TRACK_EXEC_LIMIT if X86_32
83151 + help
83152 + This implementation is based on the paging feature of the CPU.
83153 + On i386 without hardware non-executable bit support there is a
83154 + variable but usually low performance impact, however on Intel's
83155 + P4 core based CPUs it is very high so you should not enable this
83156 + for kernels meant to be used on such CPUs.
83157 +
83158 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
83159 + with hardware non-executable bit support there is no performance
83160 + impact, on ppc the impact is negligible.
83161 +
83162 + Note that several architectures require various emulations due to
83163 + badly designed userland ABIs, this will cause a performance impact
83164 + but will disappear as soon as userland is fixed. For example, ppc
83165 + userland MUST have been built with secure-plt by a recent toolchain.
83166 +
83167 +config PAX_SEGMEXEC
83168 + bool "Segmentation based non-executable pages"
83169 + default y if GRKERNSEC_CONFIG_AUTO
83170 + depends on PAX_NOEXEC && X86_32
83171 + help
83172 + This implementation is based on the segmentation feature of the
83173 + CPU and has a very small performance impact, however applications
83174 + will be limited to a 1.5 GB address space instead of the normal
83175 + 3 GB.
83176 +
83177 +config PAX_EMUTRAMP
83178 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83179 + default y if PARISC
83180 + help
83181 + There are some programs and libraries that for one reason or
83182 + another attempt to execute special small code snippets from
83183 + non-executable memory pages. Most notable examples are the
83184 + signal handler return code generated by the kernel itself and
83185 + the GCC trampolines.
83186 +
83187 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83188 + such programs will no longer work under your kernel.
83189 +
83190 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83191 + utilities to enable trampoline emulation for the affected programs
83192 + yet still have the protection provided by the non-executable pages.
83193 +
83194 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83195 + your system will not even boot.
83196 +
83197 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83198 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83199 + for the affected files.
83200 +
83201 + NOTE: enabling this feature *may* open up a loophole in the
83202 + protection provided by non-executable pages that an attacker
83203 + could abuse. Therefore the best solution is to not have any
83204 + files on your system that would require this option. This can
83205 + be achieved by not using libc5 (which relies on the kernel
83206 + signal handler return code) and not using or rewriting programs
83207 + that make use of the nested function implementation of GCC.
83208 + Skilled users can just fix GCC itself so that it implements
83209 + nested function calls in a way that does not interfere with PaX.
83210 +
83211 +config PAX_EMUSIGRT
83212 + bool "Automatically emulate sigreturn trampolines"
83213 + depends on PAX_EMUTRAMP && PARISC
83214 + default y
83215 + help
83216 + Enabling this option will have the kernel automatically detect
83217 + and emulate signal return trampolines executing on the stack
83218 + that would otherwise lead to task termination.
83219 +
83220 + This solution is intended as a temporary one for users with
83221 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83222 + Modula-3 runtime, etc) or executables linked to such, basically
83223 + everything that does not specify its own SA_RESTORER function in
83224 + normal executable memory like glibc 2.1+ does.
83225 +
83226 + On parisc you MUST enable this option, otherwise your system will
83227 + not even boot.
83228 +
83229 + NOTE: this feature cannot be disabled on a per executable basis
83230 + and since it *does* open up a loophole in the protection provided
83231 + by non-executable pages, the best solution is to not have any
83232 + files on your system that would require this option.
83233 +
83234 +config PAX_MPROTECT
83235 + bool "Restrict mprotect()"
83236 + default y if GRKERNSEC_CONFIG_AUTO
83237 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83238 + help
83239 + Enabling this option will prevent programs from
83240 + - changing the executable status of memory pages that were
83241 + not originally created as executable,
83242 + - making read-only executable pages writable again,
83243 + - creating executable pages from anonymous memory,
83244 + - making read-only-after-relocations (RELRO) data pages writable again.
83245 +
83246 + You should say Y here to complete the protection provided by
83247 + the enforcement of non-executable pages.
83248 +
83249 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83250 + this feature on a per file basis.
83251 +
83252 +config PAX_MPROTECT_COMPAT
83253 + bool "Use legacy/compat protection demoting (read help)"
83254 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83255 + depends on PAX_MPROTECT
83256 + help
83257 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83258 + by sending the proper error code to the application. For some broken
83259 + userland, this can cause problems with Python or other applications. The
83260 + current implementation however allows for applications like clamav to
83261 + detect if JIT compilation/execution is allowed and to fall back gracefully
83262 + to an interpreter-based mode if it does not. While we encourage everyone
83263 + to use the current implementation as-is and push upstream to fix broken
83264 + userland (note that the RWX logging option can assist with this), in some
83265 + environments this may not be possible. Having to disable MPROTECT
83266 + completely on certain binaries reduces the security benefit of PaX,
83267 + so this option is provided for those environments to revert to the old
83268 + behavior.
83269 +
83270 +config PAX_ELFRELOCS
83271 + bool "Allow ELF text relocations (read help)"
83272 + depends on PAX_MPROTECT
83273 + default n
83274 + help
83275 + Non-executable pages and mprotect() restrictions are effective
83276 + in preventing the introduction of new executable code into an
83277 + attacked task's address space. There remain only two venues
83278 + for this kind of attack: if the attacker can execute already
83279 + existing code in the attacked task then he can either have it
83280 + create and mmap() a file containing his code or have it mmap()
83281 + an already existing ELF library that does not have position
83282 + independent code in it and use mprotect() on it to make it
83283 + writable and copy his code there. While protecting against
83284 + the former approach is beyond PaX, the latter can be prevented
83285 + by having only PIC ELF libraries on one's system (which do not
83286 + need to relocate their code). If you are sure this is your case,
83287 + as is the case with all modern Linux distributions, then leave
83288 + this option disabled. You should say 'n' here.
83289 +
83290 +config PAX_ETEXECRELOCS
83291 + bool "Allow ELF ET_EXEC text relocations"
83292 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83293 + select PAX_ELFRELOCS
83294 + default y
83295 + help
83296 + On some architectures there are incorrectly created applications
83297 + that require text relocations and would not work without enabling
83298 + this option. If you are an alpha, ia64 or parisc user, you should
83299 + enable this option and disable it once you have made sure that
83300 + none of your applications need it.
83301 +
83302 +config PAX_EMUPLT
83303 + bool "Automatically emulate ELF PLT"
83304 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83305 + default y
83306 + help
83307 + Enabling this option will have the kernel automatically detect
83308 + and emulate the Procedure Linkage Table entries in ELF files.
83309 + On some architectures such entries are in writable memory, and
83310 + become non-executable leading to task termination. Therefore
83311 + it is mandatory that you enable this option on alpha, parisc,
83312 + sparc and sparc64, otherwise your system would not even boot.
83313 +
83314 + NOTE: this feature *does* open up a loophole in the protection
83315 + provided by the non-executable pages, therefore the proper
83316 + solution is to modify the toolchain to produce a PLT that does
83317 + not need to be writable.
83318 +
83319 +config PAX_DLRESOLVE
83320 + bool 'Emulate old glibc resolver stub'
83321 + depends on PAX_EMUPLT && SPARC
83322 + default n
83323 + help
83324 + This option is needed if userland has an old glibc (before 2.4)
83325 + that puts a 'save' instruction into the runtime generated resolver
83326 + stub that needs special emulation.
83327 +
83328 +config PAX_KERNEXEC
83329 + bool "Enforce non-executable kernel pages"
83330 + 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))
83331 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83332 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83333 + select PAX_KERNEXEC_PLUGIN if X86_64
83334 + help
83335 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83336 + that is, enabling this option will make it harder to inject
83337 + and execute 'foreign' code in kernel memory itself.
83338 +
83339 +choice
83340 + prompt "Return Address Instrumentation Method"
83341 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83342 + depends on PAX_KERNEXEC_PLUGIN
83343 + help
83344 + Select the method used to instrument function pointer dereferences.
83345 + Note that binary modules cannot be instrumented by this approach.
83346 +
83347 + Note that the implementation requires a gcc with plugin support,
83348 + i.e., gcc 4.5 or newer. You may need to install the supporting
83349 + headers explicitly in addition to the normal gcc package.
83350 +
83351 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83352 + bool "bts"
83353 + help
83354 + This method is compatible with binary only modules but has
83355 + a higher runtime overhead.
83356 +
83357 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83358 + bool "or"
83359 + depends on !PARAVIRT
83360 + help
83361 + This method is incompatible with binary only modules but has
83362 + a lower runtime overhead.
83363 +endchoice
83364 +
83365 +config PAX_KERNEXEC_PLUGIN_METHOD
83366 + string
83367 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83368 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83369 + default ""
83370 +
83371 +config PAX_KERNEXEC_MODULE_TEXT
83372 + int "Minimum amount of memory reserved for module code"
83373 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
83374 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83375 + depends on PAX_KERNEXEC && X86_32 && MODULES
83376 + help
83377 + Due to implementation details the kernel must reserve a fixed
83378 + amount of memory for module code at compile time that cannot be
83379 + changed at runtime. Here you can specify the minimum amount
83380 + in MB that will be reserved. Due to the same implementation
83381 + details this size will always be rounded up to the next 2/4 MB
83382 + boundary (depends on PAE) so the actually available memory for
83383 + module code will usually be more than this minimum.
83384 +
83385 + The default 4 MB should be enough for most users but if you have
83386 + an excessive number of modules (e.g., most distribution configs
83387 + compile many drivers as modules) or use huge modules such as
83388 + nvidia's kernel driver, you will need to adjust this amount.
83389 + A good rule of thumb is to look at your currently loaded kernel
83390 + modules and add up their sizes.
83391 +
83392 +endmenu
83393 +
83394 +menu "Address Space Layout Randomization"
83395 + depends on PAX
83396 +
83397 +config PAX_ASLR
83398 + bool "Address Space Layout Randomization"
83399 + default y if GRKERNSEC_CONFIG_AUTO
83400 + help
83401 + Many if not most exploit techniques rely on the knowledge of
83402 + certain addresses in the attacked program. The following options
83403 + will allow the kernel to apply a certain amount of randomization
83404 + to specific parts of the program thereby forcing an attacker to
83405 + guess them in most cases. Any failed guess will most likely crash
83406 + the attacked program which allows the kernel to detect such attempts
83407 + and react on them. PaX itself provides no reaction mechanisms,
83408 + instead it is strongly encouraged that you make use of Nergal's
83409 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83410 + (http://www.grsecurity.net/) built-in crash detection features or
83411 + develop one yourself.
83412 +
83413 + By saying Y here you can choose to randomize the following areas:
83414 + - top of the task's kernel stack
83415 + - top of the task's userland stack
83416 + - base address for mmap() requests that do not specify one
83417 + (this includes all libraries)
83418 + - base address of the main executable
83419 +
83420 + It is strongly recommended to say Y here as address space layout
83421 + randomization has negligible impact on performance yet it provides
83422 + a very effective protection.
83423 +
83424 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83425 + this feature on a per file basis.
83426 +
83427 +config PAX_RANDKSTACK
83428 + bool "Randomize kernel stack base"
83429 + default y if GRKERNSEC_CONFIG_AUTO
83430 + depends on X86_TSC && X86
83431 + help
83432 + By saying Y here the kernel will randomize every task's kernel
83433 + stack on every system call. This will not only force an attacker
83434 + to guess it but also prevent him from making use of possible
83435 + leaked information about it.
83436 +
83437 + Since the kernel stack is a rather scarce resource, randomization
83438 + may cause unexpected stack overflows, therefore you should very
83439 + carefully test your system. Note that once enabled in the kernel
83440 + configuration, this feature cannot be disabled on a per file basis.
83441 +
83442 +config PAX_RANDUSTACK
83443 + bool "Randomize user stack base"
83444 + default y if GRKERNSEC_CONFIG_AUTO
83445 + depends on PAX_ASLR
83446 + help
83447 + By saying Y here the kernel will randomize every task's userland
83448 + stack. The randomization is done in two steps where the second
83449 + one may apply a big amount of shift to the top of the stack and
83450 + cause problems for programs that want to use lots of memory (more
83451 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83452 + For this reason the second step can be controlled by 'chpax' or
83453 + 'paxctl' on a per file basis.
83454 +
83455 +config PAX_RANDMMAP
83456 + bool "Randomize mmap() base"
83457 + default y if GRKERNSEC_CONFIG_AUTO
83458 + depends on PAX_ASLR
83459 + help
83460 + By saying Y here the kernel will use a randomized base address for
83461 + mmap() requests that do not specify one themselves. As a result
83462 + all dynamically loaded libraries will appear at random addresses
83463 + and therefore be harder to exploit by a technique where an attacker
83464 + attempts to execute library code for his purposes (e.g. spawn a
83465 + shell from an exploited program that is running at an elevated
83466 + privilege level).
83467 +
83468 + Furthermore, if a program is relinked as a dynamic ELF file, its
83469 + base address will be randomized as well, completing the full
83470 + randomization of the address space layout. Attacking such programs
83471 + becomes a guess game. You can find an example of doing this at
83472 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
83473 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
83474 +
83475 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
83476 + feature on a per file basis.
83477 +
83478 +endmenu
83479 +
83480 +menu "Miscellaneous hardening features"
83481 +
83482 +config PAX_MEMORY_SANITIZE
83483 + bool "Sanitize all freed memory"
83484 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83485 + depends on !HIBERNATION
83486 + help
83487 + By saying Y here the kernel will erase memory pages as soon as they
83488 + are freed. This in turn reduces the lifetime of data stored in the
83489 + pages, making it less likely that sensitive information such as
83490 + passwords, cryptographic secrets, etc stay in memory for too long.
83491 +
83492 + This is especially useful for programs whose runtime is short, long
83493 + lived processes and the kernel itself benefit from this as long as
83494 + they operate on whole memory pages and ensure timely freeing of pages
83495 + that may hold sensitive information.
83496 +
83497 + The tradeoff is performance impact, on a single CPU system kernel
83498 + compilation sees a 3% slowdown, other systems and workloads may vary
83499 + and you are advised to test this feature on your expected workload
83500 + before deploying it.
83501 +
83502 + Note that this feature does not protect data stored in live pages,
83503 + e.g., process memory swapped to disk may stay there for a long time.
83504 +
83505 +config PAX_MEMORY_STACKLEAK
83506 + bool "Sanitize kernel stack"
83507 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83508 + depends on X86
83509 + help
83510 + By saying Y here the kernel will erase the kernel stack before it
83511 + returns from a system call. This in turn reduces the information
83512 + that a kernel stack leak bug can reveal.
83513 +
83514 + Note that such a bug can still leak information that was put on
83515 + the stack by the current system call (the one eventually triggering
83516 + the bug) but traces of earlier system calls on the kernel stack
83517 + cannot leak anymore.
83518 +
83519 + The tradeoff is performance impact: on a single CPU system kernel
83520 + compilation sees a 1% slowdown, other systems and workloads may vary
83521 + and you are advised to test this feature on your expected workload
83522 + before deploying it.
83523 +
83524 + Note that the full feature requires a gcc with plugin support,
83525 + i.e., gcc 4.5 or newer. You may need to install the supporting
83526 + headers explicitly in addition to the normal gcc package. Using
83527 + older gcc versions means that functions with large enough stack
83528 + frames may leave uninitialized memory behind that may be exposed
83529 + to a later syscall leaking the stack.
83530 +
83531 +config PAX_MEMORY_UDEREF
83532 + bool "Prevent invalid userland pointer dereference"
83533 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
83534 + depends on X86 && !UML_X86 && !XEN
83535 + select PAX_PER_CPU_PGD if X86_64
83536 + help
83537 + By saying Y here the kernel will be prevented from dereferencing
83538 + userland pointers in contexts where the kernel expects only kernel
83539 + pointers. This is both a useful runtime debugging feature and a
83540 + security measure that prevents exploiting a class of kernel bugs.
83541 +
83542 + The tradeoff is that some virtualization solutions may experience
83543 + a huge slowdown and therefore you should not enable this feature
83544 + for kernels meant to run in such environments. Whether a given VM
83545 + solution is affected or not is best determined by simply trying it
83546 + out, the performance impact will be obvious right on boot as this
83547 + mechanism engages from very early on. A good rule of thumb is that
83548 + VMs running on CPUs without hardware virtualization support (i.e.,
83549 + the majority of IA-32 CPUs) will likely experience the slowdown.
83550 +
83551 +config PAX_REFCOUNT
83552 + bool "Prevent various kernel object reference counter overflows"
83553 + default y if GRKERNSEC_CONFIG_AUTO
83554 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
83555 + help
83556 + By saying Y here the kernel will detect and prevent overflowing
83557 + various (but not all) kinds of object reference counters. Such
83558 + overflows can normally occur due to bugs only and are often, if
83559 + not always, exploitable.
83560 +
83561 + The tradeoff is that data structures protected by an overflowed
83562 + refcount will never be freed and therefore will leak memory. Note
83563 + that this leak also happens even without this protection but in
83564 + that case the overflow can eventually trigger the freeing of the
83565 + data structure while it is still being used elsewhere, resulting
83566 + in the exploitable situation that this feature prevents.
83567 +
83568 + Since this has a negligible performance impact, you should enable
83569 + this feature.
83570 +
83571 +config PAX_USERCOPY
83572 + bool "Harden heap object copies between kernel and userland"
83573 + default y if GRKERNSEC_CONFIG_AUTO
83574 + depends on ARM || IA64 || PPC || SPARC || X86
83575 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
83576 + select PAX_USERCOPY_SLABS
83577 + help
83578 + By saying Y here the kernel will enforce the size of heap objects
83579 + when they are copied in either direction between the kernel and
83580 + userland, even if only a part of the heap object is copied.
83581 +
83582 + Specifically, this checking prevents information leaking from the
83583 + kernel heap during kernel to userland copies (if the kernel heap
83584 + object is otherwise fully initialized) and prevents kernel heap
83585 + overflows during userland to kernel copies.
83586 +
83587 + Note that the current implementation provides the strictest bounds
83588 + checks for the SLUB allocator.
83589 +
83590 + Enabling this option also enables per-slab cache protection against
83591 + data in a given cache being copied into/out of via userland
83592 + accessors. Though the whitelist of regions will be reduced over
83593 + time, it notably protects important data structures like task structs.
83594 +
83595 + If frame pointers are enabled on x86, this option will also restrict
83596 + copies into and out of the kernel stack to local variables within a
83597 + single frame.
83598 +
83599 + Since this has a negligible performance impact, you should enable
83600 + this feature.
83601 +
83602 +
83603 +config PAX_USERCOPY_DEBUG
83604 + bool
83605 + depends on X86 && PAX_USERCOPY
83606 + default n
83607 +
83608 +config PAX_SIZE_OVERFLOW
83609 + bool "Prevent various integer overflows in function size parameters"
83610 + default y if GRKERNSEC_CONFIG_AUTO
83611 + depends on X86
83612 + help
83613 + By saying Y here the kernel recomputes expressions of function
83614 + arguments marked by a size_overflow attribute with double integer
83615 + precision (DImode/TImode for 32/64 bit integer types).
83616 +
83617 + The recomputed argument is checked against TYPE_MAX and an event
83618 + is logged on overflow and the triggering process is killed.
83619 +
83620 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
83621 +
83622 + Note that the implementation requires a gcc with plugin support,
83623 + i.e., gcc 4.5 or newer. You may need to install the supporting
83624 + headers explicitly in addition to the normal gcc package.
83625 +
83626 +config PAX_LATENT_ENTROPY
83627 + bool "Generate some entropy during boot"
83628 + default y if GRKERNSEC_CONFIG_AUTO
83629 + help
83630 + By saying Y here the kernel will instrument early boot code to
83631 + extract some entropy from both original and artificially created
83632 + program state. This will help especially embedded systems where
83633 + there is little 'natural' source of entropy normally. The cost
83634 + is some slowdown of the boot process.
83635 +
83636 + Note that the implementation requires a gcc with plugin support,
83637 + i.e., gcc 4.5 or newer. You may need to install the supporting
83638 + headers explicitly in addition to the normal gcc package.
83639 +
83640 + Note that entropy extracted this way is not cryptographically
83641 + secure!
83642 +
83643 +endmenu
83644 +
83645 +endmenu
83646 +
83647 +source grsecurity/Kconfig
83648 +
83649 +endmenu
83650 +
83651 +endmenu
83652 +
83653 source security/keys/Kconfig
83654
83655 config SECURITY_DMESG_RESTRICT
83656 @@ -103,7 +999,7 @@ config INTEL_TXT
83657 config LSM_MMAP_MIN_ADDR
83658 int "Low address space for LSM to protect from user allocation"
83659 depends on SECURITY && SECURITY_SELINUX
83660 - default 32768 if ARM
83661 + default 32768 if ALPHA || ARM || PARISC || SPARC32
83662 default 65536
83663 help
83664 This is the portion of low virtual memory which should be protected
83665 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
83666 index 8c2a7f6..b133ac9 100644
83667 --- a/security/apparmor/lsm.c
83668 +++ b/security/apparmor/lsm.c
83669 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
83670 return error;
83671 }
83672
83673 -static struct security_operations apparmor_ops = {
83674 +static struct security_operations apparmor_ops __read_only = {
83675 .name = "apparmor",
83676
83677 .ptrace_access_check = apparmor_ptrace_access_check,
83678 diff --git a/security/commoncap.c b/security/commoncap.c
83679 index 6dbae46..d5611fd 100644
83680 --- a/security/commoncap.c
83681 +++ b/security/commoncap.c
83682 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
83683 return 0;
83684 }
83685
83686 +/* returns:
83687 + 1 for suid privilege
83688 + 2 for sgid privilege
83689 + 3 for fscap privilege
83690 +*/
83691 +int is_privileged_binary(const struct dentry *dentry)
83692 +{
83693 + struct cpu_vfs_cap_data capdata;
83694 + struct inode *inode = dentry->d_inode;
83695 +
83696 + if (!inode || S_ISDIR(inode->i_mode))
83697 + return 0;
83698 +
83699 + if (inode->i_mode & S_ISUID)
83700 + return 1;
83701 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
83702 + return 2;
83703 +
83704 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
83705 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
83706 + return 3;
83707 + }
83708 +
83709 + return 0;
83710 +}
83711 +
83712 /*
83713 * Attempt to get the on-exec apply capability sets for an executable file from
83714 * its xattrs and, if present, apply them to the proposed credentials being
83715 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
83716 const struct cred *cred = current_cred();
83717 kuid_t root_uid = make_kuid(cred->user_ns, 0);
83718
83719 + if (gr_acl_enable_at_secure())
83720 + return 1;
83721 +
83722 if (!uid_eq(cred->uid, root_uid)) {
83723 if (bprm->cap_effective)
83724 return 1;
83725 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
83726 index 6ee8826..6350060 100644
83727 --- a/security/integrity/ima/ima.h
83728 +++ b/security/integrity/ima/ima.h
83729 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83730 extern spinlock_t ima_queue_lock;
83731
83732 struct ima_h_table {
83733 - atomic_long_t len; /* number of stored measurements in the list */
83734 - atomic_long_t violations;
83735 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
83736 + atomic_long_unchecked_t violations;
83737 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
83738 };
83739 extern struct ima_h_table ima_htable;
83740 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
83741 index b356884..fd9676e 100644
83742 --- a/security/integrity/ima/ima_api.c
83743 +++ b/security/integrity/ima/ima_api.c
83744 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83745 int result;
83746
83747 /* can overflow, only indicator */
83748 - atomic_long_inc(&ima_htable.violations);
83749 + atomic_long_inc_unchecked(&ima_htable.violations);
83750
83751 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
83752 if (!entry) {
83753 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
83754 index 38477c9..87a60c7 100644
83755 --- a/security/integrity/ima/ima_fs.c
83756 +++ b/security/integrity/ima/ima_fs.c
83757 @@ -28,12 +28,12 @@
83758 static int valid_policy = 1;
83759 #define TMPBUFLEN 12
83760 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
83761 - loff_t *ppos, atomic_long_t *val)
83762 + loff_t *ppos, atomic_long_unchecked_t *val)
83763 {
83764 char tmpbuf[TMPBUFLEN];
83765 ssize_t len;
83766
83767 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
83768 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
83769 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
83770 }
83771
83772 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
83773 index 55a6271..ad829c3 100644
83774 --- a/security/integrity/ima/ima_queue.c
83775 +++ b/security/integrity/ima/ima_queue.c
83776 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
83777 INIT_LIST_HEAD(&qe->later);
83778 list_add_tail_rcu(&qe->later, &ima_measurements);
83779
83780 - atomic_long_inc(&ima_htable.len);
83781 + atomic_long_inc_unchecked(&ima_htable.len);
83782 key = ima_hash_key(entry->digest);
83783 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
83784 return 0;
83785 diff --git a/security/keys/compat.c b/security/keys/compat.c
83786 index 1c26176..64a1ba2 100644
83787 --- a/security/keys/compat.c
83788 +++ b/security/keys/compat.c
83789 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
83790 if (ret == 0)
83791 goto no_payload_free;
83792
83793 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83794 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83795
83796 if (iov != iovstack)
83797 kfree(iov);
83798 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
83799 index 5d34b4e..2456674 100644
83800 --- a/security/keys/keyctl.c
83801 +++ b/security/keys/keyctl.c
83802 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
83803 /*
83804 * Copy the iovec data from userspace
83805 */
83806 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83807 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
83808 unsigned ioc)
83809 {
83810 for (; ioc > 0; ioc--) {
83811 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83812 * If successful, 0 will be returned.
83813 */
83814 long keyctl_instantiate_key_common(key_serial_t id,
83815 - const struct iovec *payload_iov,
83816 + const struct iovec __user *payload_iov,
83817 unsigned ioc,
83818 size_t plen,
83819 key_serial_t ringid)
83820 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
83821 [0].iov_len = plen
83822 };
83823
83824 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
83825 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
83826 }
83827
83828 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
83829 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
83830 if (ret == 0)
83831 goto no_payload_free;
83832
83833 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83834 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83835
83836 if (iov != iovstack)
83837 kfree(iov);
83838 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
83839 index 6e42df1..aba52bd 100644
83840 --- a/security/keys/keyring.c
83841 +++ b/security/keys/keyring.c
83842 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
83843 ret = -EFAULT;
83844
83845 for (loop = 0; loop < klist->nkeys; loop++) {
83846 + key_serial_t serial;
83847 key = rcu_deref_link_locked(klist, loop,
83848 keyring);
83849 + serial = key->serial;
83850
83851 tmp = sizeof(key_serial_t);
83852 if (tmp > buflen)
83853 tmp = buflen;
83854
83855 - if (copy_to_user(buffer,
83856 - &key->serial,
83857 - tmp) != 0)
83858 + if (copy_to_user(buffer, &serial, tmp))
83859 goto error;
83860
83861 buflen -= tmp;
83862 diff --git a/security/min_addr.c b/security/min_addr.c
83863 index f728728..6457a0c 100644
83864 --- a/security/min_addr.c
83865 +++ b/security/min_addr.c
83866 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
83867 */
83868 static void update_mmap_min_addr(void)
83869 {
83870 +#ifndef SPARC
83871 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
83872 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
83873 mmap_min_addr = dac_mmap_min_addr;
83874 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
83875 #else
83876 mmap_min_addr = dac_mmap_min_addr;
83877 #endif
83878 +#endif
83879 }
83880
83881 /*
83882 diff --git a/security/security.c b/security/security.c
83883 index 8dcd4ae..1124de7 100644
83884 --- a/security/security.c
83885 +++ b/security/security.c
83886 @@ -20,6 +20,7 @@
83887 #include <linux/ima.h>
83888 #include <linux/evm.h>
83889 #include <linux/fsnotify.h>
83890 +#include <linux/mm.h>
83891 #include <linux/mman.h>
83892 #include <linux/mount.h>
83893 #include <linux/personality.h>
83894 @@ -32,8 +33,8 @@
83895 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
83896 CONFIG_DEFAULT_SECURITY;
83897
83898 -static struct security_operations *security_ops;
83899 -static struct security_operations default_security_ops = {
83900 +static struct security_operations *security_ops __read_only;
83901 +static struct security_operations default_security_ops __read_only = {
83902 .name = "default",
83903 };
83904
83905 @@ -74,7 +75,9 @@ int __init security_init(void)
83906
83907 void reset_security_ops(void)
83908 {
83909 + pax_open_kernel();
83910 security_ops = &default_security_ops;
83911 + pax_close_kernel();
83912 }
83913
83914 /* Save user chosen LSM */
83915 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
83916 index 61a5336..27215d8 100644
83917 --- a/security/selinux/hooks.c
83918 +++ b/security/selinux/hooks.c
83919 @@ -95,8 +95,6 @@
83920
83921 #define NUM_SEL_MNT_OPTS 5
83922
83923 -extern struct security_operations *security_ops;
83924 -
83925 /* SECMARK reference count */
83926 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
83927
83928 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
83929
83930 #endif
83931
83932 -static struct security_operations selinux_ops = {
83933 +static struct security_operations selinux_ops __read_only = {
83934 .name = "selinux",
83935
83936 .ptrace_access_check = selinux_ptrace_access_check,
83937 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
83938 index 65f67cb..3f141ef 100644
83939 --- a/security/selinux/include/xfrm.h
83940 +++ b/security/selinux/include/xfrm.h
83941 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
83942
83943 static inline void selinux_xfrm_notify_policyload(void)
83944 {
83945 - atomic_inc(&flow_cache_genid);
83946 + atomic_inc_unchecked(&flow_cache_genid);
83947 rt_genid_bump(&init_net);
83948 }
83949 #else
83950 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
83951 index 38be92c..21f49ee 100644
83952 --- a/security/smack/smack_lsm.c
83953 +++ b/security/smack/smack_lsm.c
83954 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
83955 return 0;
83956 }
83957
83958 -struct security_operations smack_ops = {
83959 +struct security_operations smack_ops __read_only = {
83960 .name = "smack",
83961
83962 .ptrace_access_check = smack_ptrace_access_check,
83963 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
83964 index a2ee362..5754f34 100644
83965 --- a/security/tomoyo/tomoyo.c
83966 +++ b/security/tomoyo/tomoyo.c
83967 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
83968 * tomoyo_security_ops is a "struct security_operations" which is used for
83969 * registering TOMOYO.
83970 */
83971 -static struct security_operations tomoyo_security_ops = {
83972 +static struct security_operations tomoyo_security_ops __read_only = {
83973 .name = "tomoyo",
83974 .cred_alloc_blank = tomoyo_cred_alloc_blank,
83975 .cred_prepare = tomoyo_cred_prepare,
83976 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
83977 index 20ef514..4182bed 100644
83978 --- a/security/yama/Kconfig
83979 +++ b/security/yama/Kconfig
83980 @@ -1,6 +1,6 @@
83981 config SECURITY_YAMA
83982 bool "Yama support"
83983 - depends on SECURITY
83984 + depends on SECURITY && !GRKERNSEC
83985 select SECURITYFS
83986 select SECURITY_PATH
83987 default n
83988 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
83989 index 4cedc69..e59d8a3 100644
83990 --- a/sound/aoa/codecs/onyx.c
83991 +++ b/sound/aoa/codecs/onyx.c
83992 @@ -54,7 +54,7 @@ struct onyx {
83993 spdif_locked:1,
83994 analog_locked:1,
83995 original_mute:2;
83996 - int open_count;
83997 + local_t open_count;
83998 struct codec_info *codec_info;
83999
84000 /* mutex serializes concurrent access to the device
84001 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
84002 struct onyx *onyx = cii->codec_data;
84003
84004 mutex_lock(&onyx->mutex);
84005 - onyx->open_count++;
84006 + local_inc(&onyx->open_count);
84007 mutex_unlock(&onyx->mutex);
84008
84009 return 0;
84010 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
84011 struct onyx *onyx = cii->codec_data;
84012
84013 mutex_lock(&onyx->mutex);
84014 - onyx->open_count--;
84015 - if (!onyx->open_count)
84016 + if (local_dec_and_test(&onyx->open_count))
84017 onyx->spdif_locked = onyx->analog_locked = 0;
84018 mutex_unlock(&onyx->mutex);
84019
84020 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
84021 index ffd2025..df062c9 100644
84022 --- a/sound/aoa/codecs/onyx.h
84023 +++ b/sound/aoa/codecs/onyx.h
84024 @@ -11,6 +11,7 @@
84025 #include <linux/i2c.h>
84026 #include <asm/pmac_low_i2c.h>
84027 #include <asm/prom.h>
84028 +#include <asm/local.h>
84029
84030 /* PCM3052 register definitions */
84031
84032 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
84033 index 4c1cc51..16040040 100644
84034 --- a/sound/core/oss/pcm_oss.c
84035 +++ b/sound/core/oss/pcm_oss.c
84036 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
84037 if (in_kernel) {
84038 mm_segment_t fs;
84039 fs = snd_enter_user();
84040 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84041 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84042 snd_leave_user(fs);
84043 } else {
84044 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84045 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84046 }
84047 if (ret != -EPIPE && ret != -ESTRPIPE)
84048 break;
84049 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
84050 if (in_kernel) {
84051 mm_segment_t fs;
84052 fs = snd_enter_user();
84053 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84054 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84055 snd_leave_user(fs);
84056 } else {
84057 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84058 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84059 }
84060 if (ret == -EPIPE) {
84061 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
84062 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
84063 struct snd_pcm_plugin_channel *channels;
84064 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
84065 if (!in_kernel) {
84066 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
84067 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
84068 return -EFAULT;
84069 buf = runtime->oss.buffer;
84070 }
84071 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
84072 }
84073 } else {
84074 tmp = snd_pcm_oss_write2(substream,
84075 - (const char __force *)buf,
84076 + (const char __force_kernel *)buf,
84077 runtime->oss.period_bytes, 0);
84078 if (tmp <= 0)
84079 goto err;
84080 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
84081 struct snd_pcm_runtime *runtime = substream->runtime;
84082 snd_pcm_sframes_t frames, frames1;
84083 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
84084 - char __user *final_dst = (char __force __user *)buf;
84085 + char __user *final_dst = (char __force_user *)buf;
84086 if (runtime->oss.plugin_first) {
84087 struct snd_pcm_plugin_channel *channels;
84088 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
84089 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
84090 xfer += tmp;
84091 runtime->oss.buffer_used -= tmp;
84092 } else {
84093 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
84094 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
84095 runtime->oss.period_bytes, 0);
84096 if (tmp <= 0)
84097 goto err;
84098 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
84099 size1);
84100 size1 /= runtime->channels; /* frames */
84101 fs = snd_enter_user();
84102 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
84103 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
84104 snd_leave_user(fs);
84105 }
84106 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
84107 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
84108 index 91cdf943..4085161 100644
84109 --- a/sound/core/pcm_compat.c
84110 +++ b/sound/core/pcm_compat.c
84111 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
84112 int err;
84113
84114 fs = snd_enter_user();
84115 - err = snd_pcm_delay(substream, &delay);
84116 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
84117 snd_leave_user(fs);
84118 if (err < 0)
84119 return err;
84120 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
84121 index f9ddecf..e27404d 100644
84122 --- a/sound/core/pcm_native.c
84123 +++ b/sound/core/pcm_native.c
84124 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
84125 switch (substream->stream) {
84126 case SNDRV_PCM_STREAM_PLAYBACK:
84127 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
84128 - (void __user *)arg);
84129 + (void __force_user *)arg);
84130 break;
84131 case SNDRV_PCM_STREAM_CAPTURE:
84132 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
84133 - (void __user *)arg);
84134 + (void __force_user *)arg);
84135 break;
84136 default:
84137 result = -EINVAL;
84138 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
84139 index 60e8fc1..786abcb 100644
84140 --- a/sound/core/seq/seq_device.c
84141 +++ b/sound/core/seq/seq_device.c
84142 @@ -64,7 +64,7 @@ struct ops_list {
84143 int argsize; /* argument size */
84144
84145 /* operators */
84146 - struct snd_seq_dev_ops ops;
84147 + struct snd_seq_dev_ops *ops;
84148
84149 /* registred devices */
84150 struct list_head dev_list; /* list of devices */
84151 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
84152
84153 mutex_lock(&ops->reg_mutex);
84154 /* copy driver operators */
84155 - ops->ops = *entry;
84156 + ops->ops = entry;
84157 ops->driver |= DRIVER_LOADED;
84158 ops->argsize = argsize;
84159
84160 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
84161 dev->name, ops->id, ops->argsize, dev->argsize);
84162 return -EINVAL;
84163 }
84164 - if (ops->ops.init_device(dev) >= 0) {
84165 + if (ops->ops->init_device(dev) >= 0) {
84166 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
84167 ops->num_init_devices++;
84168 } else {
84169 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
84170 dev->name, ops->id, ops->argsize, dev->argsize);
84171 return -EINVAL;
84172 }
84173 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
84174 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
84175 dev->status = SNDRV_SEQ_DEVICE_FREE;
84176 dev->driver_data = NULL;
84177 ops->num_init_devices--;
84178 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
84179 index 2d5514b..3afae9c 100644
84180 --- a/sound/drivers/mts64.c
84181 +++ b/sound/drivers/mts64.c
84182 @@ -29,6 +29,7 @@
84183 #include <sound/initval.h>
84184 #include <sound/rawmidi.h>
84185 #include <sound/control.h>
84186 +#include <asm/local.h>
84187
84188 #define CARD_NAME "Miditerminal 4140"
84189 #define DRIVER_NAME "MTS64"
84190 @@ -67,7 +68,7 @@ struct mts64 {
84191 struct pardevice *pardev;
84192 int pardev_claimed;
84193
84194 - int open_count;
84195 + local_t open_count;
84196 int current_midi_output_port;
84197 int current_midi_input_port;
84198 u8 mode[MTS64_NUM_INPUT_PORTS];
84199 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84200 {
84201 struct mts64 *mts = substream->rmidi->private_data;
84202
84203 - if (mts->open_count == 0) {
84204 + if (local_read(&mts->open_count) == 0) {
84205 /* We don't need a spinlock here, because this is just called
84206 if the device has not been opened before.
84207 So there aren't any IRQs from the device */
84208 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84209
84210 msleep(50);
84211 }
84212 - ++(mts->open_count);
84213 + local_inc(&mts->open_count);
84214
84215 return 0;
84216 }
84217 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84218 struct mts64 *mts = substream->rmidi->private_data;
84219 unsigned long flags;
84220
84221 - --(mts->open_count);
84222 - if (mts->open_count == 0) {
84223 + if (local_dec_return(&mts->open_count) == 0) {
84224 /* We need the spinlock_irqsave here because we can still
84225 have IRQs at this point */
84226 spin_lock_irqsave(&mts->lock, flags);
84227 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84228
84229 msleep(500);
84230
84231 - } else if (mts->open_count < 0)
84232 - mts->open_count = 0;
84233 + } else if (local_read(&mts->open_count) < 0)
84234 + local_set(&mts->open_count, 0);
84235
84236 return 0;
84237 }
84238 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84239 index b953fb4..1999c01 100644
84240 --- a/sound/drivers/opl4/opl4_lib.c
84241 +++ b/sound/drivers/opl4/opl4_lib.c
84242 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84243 MODULE_DESCRIPTION("OPL4 driver");
84244 MODULE_LICENSE("GPL");
84245
84246 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84247 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84248 {
84249 int timeout = 10;
84250 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84251 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84252 index 8364855..59f2e2b 100644
84253 --- a/sound/drivers/portman2x4.c
84254 +++ b/sound/drivers/portman2x4.c
84255 @@ -48,6 +48,7 @@
84256 #include <sound/initval.h>
84257 #include <sound/rawmidi.h>
84258 #include <sound/control.h>
84259 +#include <asm/local.h>
84260
84261 #define CARD_NAME "Portman 2x4"
84262 #define DRIVER_NAME "portman"
84263 @@ -85,7 +86,7 @@ struct portman {
84264 struct pardevice *pardev;
84265 int pardev_claimed;
84266
84267 - int open_count;
84268 + local_t open_count;
84269 int mode[PORTMAN_NUM_INPUT_PORTS];
84270 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84271 };
84272 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
84273 index ea995af..f1bfa37 100644
84274 --- a/sound/firewire/amdtp.c
84275 +++ b/sound/firewire/amdtp.c
84276 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
84277 ptr = s->pcm_buffer_pointer + data_blocks;
84278 if (ptr >= pcm->runtime->buffer_size)
84279 ptr -= pcm->runtime->buffer_size;
84280 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
84281 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
84282
84283 s->pcm_period_pointer += data_blocks;
84284 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
84285 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
84286 */
84287 void amdtp_out_stream_update(struct amdtp_out_stream *s)
84288 {
84289 - ACCESS_ONCE(s->source_node_id_field) =
84290 + ACCESS_ONCE_RW(s->source_node_id_field) =
84291 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
84292 }
84293 EXPORT_SYMBOL(amdtp_out_stream_update);
84294 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
84295 index b680c5e..061b7a0 100644
84296 --- a/sound/firewire/amdtp.h
84297 +++ b/sound/firewire/amdtp.h
84298 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
84299 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
84300 struct snd_pcm_substream *pcm)
84301 {
84302 - ACCESS_ONCE(s->pcm) = pcm;
84303 + ACCESS_ONCE_RW(s->pcm) = pcm;
84304 }
84305
84306 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
84307 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
84308 index d428ffe..751ef78 100644
84309 --- a/sound/firewire/isight.c
84310 +++ b/sound/firewire/isight.c
84311 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
84312 ptr += count;
84313 if (ptr >= runtime->buffer_size)
84314 ptr -= runtime->buffer_size;
84315 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
84316 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
84317
84318 isight->period_counter += count;
84319 if (isight->period_counter >= runtime->period_size) {
84320 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
84321 if (err < 0)
84322 return err;
84323
84324 - ACCESS_ONCE(isight->pcm_active) = true;
84325 + ACCESS_ONCE_RW(isight->pcm_active) = true;
84326
84327 return 0;
84328 }
84329 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
84330 {
84331 struct isight *isight = substream->private_data;
84332
84333 - ACCESS_ONCE(isight->pcm_active) = false;
84334 + ACCESS_ONCE_RW(isight->pcm_active) = false;
84335
84336 mutex_lock(&isight->mutex);
84337 isight_stop_streaming(isight);
84338 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
84339
84340 switch (cmd) {
84341 case SNDRV_PCM_TRIGGER_START:
84342 - ACCESS_ONCE(isight->pcm_running) = true;
84343 + ACCESS_ONCE_RW(isight->pcm_running) = true;
84344 break;
84345 case SNDRV_PCM_TRIGGER_STOP:
84346 - ACCESS_ONCE(isight->pcm_running) = false;
84347 + ACCESS_ONCE_RW(isight->pcm_running) = false;
84348 break;
84349 default:
84350 return -EINVAL;
84351 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84352 index b2b3c01..e1c1e1f 100644
84353 --- a/sound/oss/sb_audio.c
84354 +++ b/sound/oss/sb_audio.c
84355 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
84356 buf16 = (signed short *)(localbuf + localoffs);
84357 while (c)
84358 {
84359 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84360 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84361 if (copy_from_user(lbuf8,
84362 userbuf+useroffs + p,
84363 locallen))
84364 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84365 index 7d8803a..559f8d0 100644
84366 --- a/sound/oss/swarm_cs4297a.c
84367 +++ b/sound/oss/swarm_cs4297a.c
84368 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
84369 {
84370 struct cs4297a_state *s;
84371 u32 pwr, id;
84372 - mm_segment_t fs;
84373 int rval;
84374 #ifndef CONFIG_BCM_CS4297A_CSWARM
84375 u64 cfg;
84376 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
84377 if (!rval) {
84378 char *sb1250_duart_present;
84379
84380 +#if 0
84381 + mm_segment_t fs;
84382 fs = get_fs();
84383 set_fs(KERNEL_DS);
84384 -#if 0
84385 val = SOUND_MASK_LINE;
84386 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84387 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84388 val = initvol[i].vol;
84389 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84390 }
84391 + set_fs(fs);
84392 // cs4297a_write_ac97(s, 0x18, 0x0808);
84393 #else
84394 // cs4297a_write_ac97(s, 0x5e, 0x180);
84395 cs4297a_write_ac97(s, 0x02, 0x0808);
84396 cs4297a_write_ac97(s, 0x18, 0x0808);
84397 #endif
84398 - set_fs(fs);
84399
84400 list_add(&s->list, &cs4297a_devs);
84401
84402 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
84403 index 4631a23..001ae57 100644
84404 --- a/sound/pci/ymfpci/ymfpci.h
84405 +++ b/sound/pci/ymfpci/ymfpci.h
84406 @@ -358,7 +358,7 @@ struct snd_ymfpci {
84407 spinlock_t reg_lock;
84408 spinlock_t voice_lock;
84409 wait_queue_head_t interrupt_sleep;
84410 - atomic_t interrupt_sleep_count;
84411 + atomic_unchecked_t interrupt_sleep_count;
84412 struct snd_info_entry *proc_entry;
84413 const struct firmware *dsp_microcode;
84414 const struct firmware *controller_microcode;
84415 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
84416 index 3a6f03f..bc5c86c 100644
84417 --- a/sound/pci/ymfpci/ymfpci_main.c
84418 +++ b/sound/pci/ymfpci/ymfpci_main.c
84419 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
84420 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
84421 break;
84422 }
84423 - if (atomic_read(&chip->interrupt_sleep_count)) {
84424 - atomic_set(&chip->interrupt_sleep_count, 0);
84425 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84426 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84427 wake_up(&chip->interrupt_sleep);
84428 }
84429 __end:
84430 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
84431 continue;
84432 init_waitqueue_entry(&wait, current);
84433 add_wait_queue(&chip->interrupt_sleep, &wait);
84434 - atomic_inc(&chip->interrupt_sleep_count);
84435 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
84436 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
84437 remove_wait_queue(&chip->interrupt_sleep, &wait);
84438 }
84439 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
84440 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
84441 spin_unlock(&chip->reg_lock);
84442
84443 - if (atomic_read(&chip->interrupt_sleep_count)) {
84444 - atomic_set(&chip->interrupt_sleep_count, 0);
84445 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84446 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84447 wake_up(&chip->interrupt_sleep);
84448 }
84449 }
84450 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
84451 spin_lock_init(&chip->reg_lock);
84452 spin_lock_init(&chip->voice_lock);
84453 init_waitqueue_head(&chip->interrupt_sleep);
84454 - atomic_set(&chip->interrupt_sleep_count, 0);
84455 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84456 chip->card = card;
84457 chip->pci = pci;
84458 chip->irq = -1;
84459 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
84460 new file mode 100644
84461 index 0000000..50f2f2f
84462 --- /dev/null
84463 +++ b/tools/gcc/.gitignore
84464 @@ -0,0 +1 @@
84465 +size_overflow_hash.h
84466 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
84467 new file mode 100644
84468 index 0000000..1d09b7e
84469 --- /dev/null
84470 +++ b/tools/gcc/Makefile
84471 @@ -0,0 +1,43 @@
84472 +#CC := gcc
84473 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84474 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84475 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
84476 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
84477 +
84478 +ifeq ($(PLUGINCC),$(HOSTCC))
84479 +HOSTLIBS := hostlibs
84480 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
84481 +else
84482 +HOSTLIBS := hostcxxlibs
84483 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
84484 +endif
84485 +
84486 +$(HOSTLIBS)-y := constify_plugin.so
84487 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
84488 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
84489 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
84490 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
84491 +$(HOSTLIBS)-y += colorize_plugin.so
84492 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
84493 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
84494 +
84495 +always := $($(HOSTLIBS)-y)
84496 +
84497 +constify_plugin-objs := constify_plugin.o
84498 +stackleak_plugin-objs := stackleak_plugin.o
84499 +kallocstat_plugin-objs := kallocstat_plugin.o
84500 +kernexec_plugin-objs := kernexec_plugin.o
84501 +checker_plugin-objs := checker_plugin.o
84502 +colorize_plugin-objs := colorize_plugin.o
84503 +size_overflow_plugin-objs := size_overflow_plugin.o
84504 +latent_entropy_plugin-objs := latent_entropy_plugin.o
84505 +
84506 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
84507 +
84508 +quiet_cmd_build_size_overflow_hash = GENHASH $@
84509 + cmd_build_size_overflow_hash = \
84510 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
84511 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
84512 + $(call if_changed,build_size_overflow_hash)
84513 +
84514 +targets += size_overflow_hash.h
84515 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
84516 new file mode 100644
84517 index 0000000..d41b5af
84518 --- /dev/null
84519 +++ b/tools/gcc/checker_plugin.c
84520 @@ -0,0 +1,171 @@
84521 +/*
84522 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84523 + * Licensed under the GPL v2
84524 + *
84525 + * Note: the choice of the license means that the compilation process is
84526 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84527 + * but for the kernel it doesn't matter since it doesn't link against
84528 + * any of the gcc libraries
84529 + *
84530 + * gcc plugin to implement various sparse (source code checker) features
84531 + *
84532 + * TODO:
84533 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
84534 + *
84535 + * BUGS:
84536 + * - none known
84537 + */
84538 +#include "gcc-plugin.h"
84539 +#include "config.h"
84540 +#include "system.h"
84541 +#include "coretypes.h"
84542 +#include "tree.h"
84543 +#include "tree-pass.h"
84544 +#include "flags.h"
84545 +#include "intl.h"
84546 +#include "toplev.h"
84547 +#include "plugin.h"
84548 +//#include "expr.h" where are you...
84549 +#include "diagnostic.h"
84550 +#include "plugin-version.h"
84551 +#include "tm.h"
84552 +#include "function.h"
84553 +#include "basic-block.h"
84554 +#include "gimple.h"
84555 +#include "rtl.h"
84556 +#include "emit-rtl.h"
84557 +#include "tree-flow.h"
84558 +#include "target.h"
84559 +
84560 +extern void c_register_addr_space (const char *str, addr_space_t as);
84561 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
84562 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
84563 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
84564 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
84565 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
84566 +
84567 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84568 +extern rtx emit_move_insn(rtx x, rtx y);
84569 +
84570 +int plugin_is_GPL_compatible;
84571 +
84572 +static struct plugin_info checker_plugin_info = {
84573 + .version = "201111150100",
84574 +};
84575 +
84576 +#define ADDR_SPACE_KERNEL 0
84577 +#define ADDR_SPACE_FORCE_KERNEL 1
84578 +#define ADDR_SPACE_USER 2
84579 +#define ADDR_SPACE_FORCE_USER 3
84580 +#define ADDR_SPACE_IOMEM 0
84581 +#define ADDR_SPACE_FORCE_IOMEM 0
84582 +#define ADDR_SPACE_PERCPU 0
84583 +#define ADDR_SPACE_FORCE_PERCPU 0
84584 +#define ADDR_SPACE_RCU 0
84585 +#define ADDR_SPACE_FORCE_RCU 0
84586 +
84587 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
84588 +{
84589 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
84590 +}
84591 +
84592 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
84593 +{
84594 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
84595 +}
84596 +
84597 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
84598 +{
84599 + return default_addr_space_valid_pointer_mode(mode, as);
84600 +}
84601 +
84602 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
84603 +{
84604 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
84605 +}
84606 +
84607 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
84608 +{
84609 + return default_addr_space_legitimize_address(x, oldx, mode, as);
84610 +}
84611 +
84612 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
84613 +{
84614 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
84615 + return true;
84616 +
84617 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
84618 + return true;
84619 +
84620 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
84621 + return true;
84622 +
84623 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
84624 + return true;
84625 +
84626 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
84627 + return true;
84628 +
84629 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
84630 + return true;
84631 +
84632 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
84633 + return true;
84634 +
84635 + return subset == superset;
84636 +}
84637 +
84638 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
84639 +{
84640 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
84641 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
84642 +
84643 + return op;
84644 +}
84645 +
84646 +static void register_checker_address_spaces(void *event_data, void *data)
84647 +{
84648 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
84649 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
84650 + c_register_addr_space("__user", ADDR_SPACE_USER);
84651 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
84652 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
84653 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
84654 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
84655 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
84656 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
84657 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
84658 +
84659 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
84660 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
84661 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
84662 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
84663 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
84664 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
84665 + targetm.addr_space.convert = checker_addr_space_convert;
84666 +}
84667 +
84668 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84669 +{
84670 + const char * const plugin_name = plugin_info->base_name;
84671 + const int argc = plugin_info->argc;
84672 + const struct plugin_argument * const argv = plugin_info->argv;
84673 + int i;
84674 +
84675 + if (!plugin_default_version_check(version, &gcc_version)) {
84676 + error(G_("incompatible gcc/plugin versions"));
84677 + return 1;
84678 + }
84679 +
84680 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
84681 +
84682 + for (i = 0; i < argc; ++i)
84683 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84684 +
84685 + if (TARGET_64BIT == 0)
84686 + return 0;
84687 +
84688 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
84689 +
84690 + return 0;
84691 +}
84692 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
84693 new file mode 100644
84694 index 0000000..414fe5e
84695 --- /dev/null
84696 +++ b/tools/gcc/colorize_plugin.c
84697 @@ -0,0 +1,151 @@
84698 +/*
84699 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
84700 + * Licensed under the GPL v2
84701 + *
84702 + * Note: the choice of the license means that the compilation process is
84703 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84704 + * but for the kernel it doesn't matter since it doesn't link against
84705 + * any of the gcc libraries
84706 + *
84707 + * gcc plugin to colorize diagnostic output
84708 + *
84709 + */
84710 +
84711 +#include "gcc-plugin.h"
84712 +#include "config.h"
84713 +#include "system.h"
84714 +#include "coretypes.h"
84715 +#include "tree.h"
84716 +#include "tree-pass.h"
84717 +#include "flags.h"
84718 +#include "intl.h"
84719 +#include "toplev.h"
84720 +#include "plugin.h"
84721 +#include "diagnostic.h"
84722 +#include "plugin-version.h"
84723 +#include "tm.h"
84724 +
84725 +int plugin_is_GPL_compatible;
84726 +
84727 +static struct plugin_info colorize_plugin_info = {
84728 + .version = "201302112000",
84729 + .help = NULL,
84730 +};
84731 +
84732 +#define GREEN "\033[32m\033[2m"
84733 +#define LIGHTGREEN "\033[32m\033[1m"
84734 +#define YELLOW "\033[33m\033[2m"
84735 +#define LIGHTYELLOW "\033[33m\033[1m"
84736 +#define RED "\033[31m\033[2m"
84737 +#define LIGHTRED "\033[31m\033[1m"
84738 +#define BLUE "\033[34m\033[2m"
84739 +#define LIGHTBLUE "\033[34m\033[1m"
84740 +#define BRIGHT "\033[m\033[1m"
84741 +#define NORMAL "\033[m"
84742 +
84743 +static diagnostic_starter_fn old_starter;
84744 +static diagnostic_finalizer_fn old_finalizer;
84745 +
84746 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84747 +{
84748 + const char *color;
84749 + char *newprefix;
84750 +
84751 + switch (diagnostic->kind) {
84752 + case DK_NOTE:
84753 + color = LIGHTBLUE;
84754 + break;
84755 +
84756 + case DK_PEDWARN:
84757 + case DK_WARNING:
84758 + color = LIGHTYELLOW;
84759 + break;
84760 +
84761 + case DK_ERROR:
84762 + case DK_FATAL:
84763 + case DK_ICE:
84764 + case DK_PERMERROR:
84765 + case DK_SORRY:
84766 + color = LIGHTRED;
84767 + break;
84768 +
84769 + default:
84770 + color = NORMAL;
84771 + }
84772 +
84773 + old_starter(context, diagnostic);
84774 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
84775 + return;
84776 + pp_destroy_prefix(context->printer);
84777 + pp_set_prefix(context->printer, newprefix);
84778 +}
84779 +
84780 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84781 +{
84782 + old_finalizer(context, diagnostic);
84783 +}
84784 +
84785 +static void colorize_arm(void)
84786 +{
84787 + old_starter = diagnostic_starter(global_dc);
84788 + old_finalizer = diagnostic_finalizer(global_dc);
84789 +
84790 + diagnostic_starter(global_dc) = start_colorize;
84791 + diagnostic_finalizer(global_dc) = finalize_colorize;
84792 +}
84793 +
84794 +static unsigned int execute_colorize_rearm(void)
84795 +{
84796 + if (diagnostic_starter(global_dc) == start_colorize)
84797 + return 0;
84798 +
84799 + colorize_arm();
84800 + return 0;
84801 +}
84802 +
84803 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
84804 + .pass = {
84805 + .type = SIMPLE_IPA_PASS,
84806 + .name = "colorize_rearm",
84807 +#if BUILDING_GCC_VERSION >= 4008
84808 + .optinfo_flags = OPTGROUP_NONE,
84809 +#endif
84810 + .gate = NULL,
84811 + .execute = execute_colorize_rearm,
84812 + .sub = NULL,
84813 + .next = NULL,
84814 + .static_pass_number = 0,
84815 + .tv_id = TV_NONE,
84816 + .properties_required = 0,
84817 + .properties_provided = 0,
84818 + .properties_destroyed = 0,
84819 + .todo_flags_start = 0,
84820 + .todo_flags_finish = 0
84821 + }
84822 +};
84823 +
84824 +static void colorize_start_unit(void *gcc_data, void *user_data)
84825 +{
84826 + colorize_arm();
84827 +}
84828 +
84829 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84830 +{
84831 + const char * const plugin_name = plugin_info->base_name;
84832 + struct register_pass_info colorize_rearm_pass_info = {
84833 + .pass = &pass_ipa_colorize_rearm.pass,
84834 + .reference_pass_name = "*free_lang_data",
84835 + .ref_pass_instance_number = 1,
84836 + .pos_op = PASS_POS_INSERT_AFTER
84837 + };
84838 +
84839 + if (!plugin_default_version_check(version, &gcc_version)) {
84840 + error(G_("incompatible gcc/plugin versions"));
84841 + return 1;
84842 + }
84843 +
84844 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
84845 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
84846 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
84847 + return 0;
84848 +}
84849 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
84850 new file mode 100644
84851 index 0000000..c415c9d
84852 --- /dev/null
84853 +++ b/tools/gcc/constify_plugin.c
84854 @@ -0,0 +1,359 @@
84855 +/*
84856 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
84857 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
84858 + * Licensed under the GPL v2, or (at your option) v3
84859 + *
84860 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
84861 + *
84862 + * Homepage:
84863 + * http://www.grsecurity.net/~ephox/const_plugin/
84864 + *
84865 + * Usage:
84866 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
84867 + * $ gcc -fplugin=constify_plugin.so test.c -O2
84868 + */
84869 +
84870 +#include "gcc-plugin.h"
84871 +#include "config.h"
84872 +#include "system.h"
84873 +#include "coretypes.h"
84874 +#include "tree.h"
84875 +#include "tree-pass.h"
84876 +#include "flags.h"
84877 +#include "intl.h"
84878 +#include "toplev.h"
84879 +#include "plugin.h"
84880 +#include "diagnostic.h"
84881 +#include "plugin-version.h"
84882 +#include "tm.h"
84883 +#include "function.h"
84884 +#include "basic-block.h"
84885 +#include "gimple.h"
84886 +#include "rtl.h"
84887 +#include "emit-rtl.h"
84888 +#include "tree-flow.h"
84889 +
84890 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
84891 +
84892 +int plugin_is_GPL_compatible;
84893 +
84894 +static struct plugin_info const_plugin_info = {
84895 + .version = "201302112000",
84896 + .help = "no-constify\tturn off constification\n",
84897 +};
84898 +
84899 +static tree get_field_type(tree field)
84900 +{
84901 + return strip_array_types(TREE_TYPE(field));
84902 +}
84903 +
84904 +static bool walk_struct(tree node);
84905 +static void deconstify_tree(tree node);
84906 +
84907 +static void deconstify_type(tree type)
84908 +{
84909 + tree field;
84910 +
84911 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
84912 + tree fieldtype = get_field_type(field);
84913 +
84914 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
84915 + continue;
84916 + if (!TYPE_READONLY(fieldtype))
84917 + continue;
84918 + if (!walk_struct(fieldtype))
84919 + continue;
84920 +
84921 + deconstify_tree(field);
84922 + TREE_READONLY(field) = 0;
84923 + }
84924 + TYPE_READONLY(type) = 0;
84925 + C_TYPE_FIELDS_READONLY(type) = 0;
84926 +}
84927 +
84928 +static void deconstify_tree(tree node)
84929 +{
84930 + tree old_type, new_type, field;
84931 +
84932 +// TREE_READONLY(node) = 0;
84933 + old_type = TREE_TYPE(node);
84934 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
84935 + node = old_type;
84936 + old_type = TREE_TYPE(old_type);
84937 + }
84938 +
84939 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
84940 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
84941 +
84942 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
84943 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
84944 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
84945 + DECL_FIELD_CONTEXT(field) = new_type;
84946 +
84947 + deconstify_type(new_type);
84948 +
84949 + TREE_TYPE(node) = new_type;
84950 +}
84951 +
84952 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84953 +{
84954 + tree type;
84955 +
84956 + *no_add_attrs = true;
84957 + if (TREE_CODE(*node) == FUNCTION_DECL) {
84958 + error("%qE attribute does not apply to functions", name);
84959 + return NULL_TREE;
84960 + }
84961 +
84962 + if (TREE_CODE(*node) == VAR_DECL) {
84963 + error("%qE attribute does not apply to variables", name);
84964 + return NULL_TREE;
84965 + }
84966 +
84967 + if (TYPE_P(*node)) {
84968 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
84969 + *no_add_attrs = false;
84970 + else
84971 + error("%qE attribute applies to struct and union types only", name);
84972 + return NULL_TREE;
84973 + }
84974 +
84975 + type = TREE_TYPE(*node);
84976 +
84977 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
84978 + error("%qE attribute applies to struct and union types only", name);
84979 + return NULL_TREE;
84980 + }
84981 +
84982 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
84983 + error("%qE attribute is already applied to the type", name);
84984 + return NULL_TREE;
84985 + }
84986 +
84987 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
84988 + error("%qE attribute used on type that is not constified", name);
84989 + return NULL_TREE;
84990 + }
84991 +
84992 + if (TREE_CODE(*node) == TYPE_DECL) {
84993 + deconstify_tree(*node);
84994 + return NULL_TREE;
84995 + }
84996 +
84997 + return NULL_TREE;
84998 +}
84999 +
85000 +static void constify_type(tree type)
85001 +{
85002 + TYPE_READONLY(type) = 1;
85003 + C_TYPE_FIELDS_READONLY(type) = 1;
85004 +}
85005 +
85006 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85007 +{
85008 + *no_add_attrs = true;
85009 + if (!TYPE_P(*node)) {
85010 + error("%qE attribute applies to types only", name);
85011 + return NULL_TREE;
85012 + }
85013 +
85014 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
85015 + error("%qE attribute applies to struct and union types only", name);
85016 + return NULL_TREE;
85017 + }
85018 +
85019 + *no_add_attrs = false;
85020 + constify_type(*node);
85021 + return NULL_TREE;
85022 +}
85023 +
85024 +static struct attribute_spec no_const_attr = {
85025 + .name = "no_const",
85026 + .min_length = 0,
85027 + .max_length = 0,
85028 + .decl_required = false,
85029 + .type_required = false,
85030 + .function_type_required = false,
85031 + .handler = handle_no_const_attribute,
85032 +#if BUILDING_GCC_VERSION >= 4007
85033 + .affects_type_identity = true
85034 +#endif
85035 +};
85036 +
85037 +static struct attribute_spec do_const_attr = {
85038 + .name = "do_const",
85039 + .min_length = 0,
85040 + .max_length = 0,
85041 + .decl_required = false,
85042 + .type_required = false,
85043 + .function_type_required = false,
85044 + .handler = handle_do_const_attribute,
85045 +#if BUILDING_GCC_VERSION >= 4007
85046 + .affects_type_identity = true
85047 +#endif
85048 +};
85049 +
85050 +static void register_attributes(void *event_data, void *data)
85051 +{
85052 + register_attribute(&no_const_attr);
85053 + register_attribute(&do_const_attr);
85054 +}
85055 +
85056 +static bool is_fptr(tree field)
85057 +{
85058 + tree ptr = get_field_type(field);
85059 +
85060 + if (TREE_CODE(ptr) != POINTER_TYPE)
85061 + return false;
85062 +
85063 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
85064 +}
85065 +
85066 +static bool walk_struct(tree node)
85067 +{
85068 + tree field;
85069 +
85070 + if (TYPE_FIELDS(node) == NULL_TREE)
85071 + return false;
85072 +
85073 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
85074 + return true;
85075 +
85076 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
85077 + gcc_assert(!TYPE_READONLY(node));
85078 + deconstify_type(node);
85079 + return false;
85080 + }
85081 +
85082 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
85083 + tree type = get_field_type(field);
85084 + enum tree_code code = TREE_CODE(type);
85085 +
85086 + if (node == type)
85087 + return false;
85088 + if (code == RECORD_TYPE || code == UNION_TYPE) {
85089 + if (!(walk_struct(type)))
85090 + return false;
85091 + } else if (!is_fptr(field) && !TREE_READONLY(field))
85092 + return false;
85093 + }
85094 + return true;
85095 +}
85096 +
85097 +static void finish_type(void *event_data, void *data)
85098 +{
85099 + tree type = (tree)event_data;
85100 +
85101 + if (type == NULL_TREE || type == error_mark_node)
85102 + return;
85103 +
85104 + if (TYPE_READONLY(type))
85105 + return;
85106 +
85107 + if (walk_struct(type))
85108 + constify_type(type);
85109 + else
85110 + deconstify_type(type);
85111 +}
85112 +
85113 +static unsigned int check_local_variables(void)
85114 +{
85115 + unsigned int ret = 0;
85116 + tree var;
85117 +
85118 +#if BUILDING_GCC_VERSION == 4005
85119 + tree vars;
85120 +#else
85121 + unsigned int i;
85122 +#endif
85123 +
85124 +#if BUILDING_GCC_VERSION == 4005
85125 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
85126 + var = TREE_VALUE(vars);
85127 +#else
85128 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
85129 +#endif
85130 + tree type = TREE_TYPE(var);
85131 +
85132 + gcc_assert(DECL_P(var));
85133 + if (is_global_var(var))
85134 + continue;
85135 +
85136 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
85137 + continue;
85138 +
85139 + if (!TYPE_READONLY(type))
85140 + continue;
85141 +
85142 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
85143 +// continue;
85144 +
85145 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
85146 + continue;
85147 +
85148 + if (walk_struct(type)) {
85149 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
85150 + ret = 1;
85151 + }
85152 + }
85153 + return ret;
85154 +}
85155 +
85156 +struct gimple_opt_pass pass_local_variable = {
85157 + {
85158 + .type = GIMPLE_PASS,
85159 + .name = "check_local_variables",
85160 +#if BUILDING_GCC_VERSION >= 4008
85161 + .optinfo_flags = OPTGROUP_NONE,
85162 +#endif
85163 + .gate = NULL,
85164 + .execute = check_local_variables,
85165 + .sub = NULL,
85166 + .next = NULL,
85167 + .static_pass_number = 0,
85168 + .tv_id = TV_NONE,
85169 + .properties_required = 0,
85170 + .properties_provided = 0,
85171 + .properties_destroyed = 0,
85172 + .todo_flags_start = 0,
85173 + .todo_flags_finish = 0
85174 + }
85175 +};
85176 +
85177 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85178 +{
85179 + const char * const plugin_name = plugin_info->base_name;
85180 + const int argc = plugin_info->argc;
85181 + const struct plugin_argument * const argv = plugin_info->argv;
85182 + int i;
85183 + bool constify = true;
85184 +
85185 + struct register_pass_info local_variable_pass_info = {
85186 + .pass = &pass_local_variable.pass,
85187 + .reference_pass_name = "ssa",
85188 + .ref_pass_instance_number = 1,
85189 + .pos_op = PASS_POS_INSERT_BEFORE
85190 + };
85191 +
85192 + if (!plugin_default_version_check(version, &gcc_version)) {
85193 + error(G_("incompatible gcc/plugin versions"));
85194 + return 1;
85195 + }
85196 +
85197 + for (i = 0; i < argc; ++i) {
85198 + if (!(strcmp(argv[i].key, "no-constify"))) {
85199 + constify = false;
85200 + continue;
85201 + }
85202 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85203 + }
85204 +
85205 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85206 + if (constify) {
85207 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85208 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85209 + }
85210 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85211 +
85212 + return 0;
85213 +}
85214 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
85215 new file mode 100644
85216 index 0000000..e518932
85217 --- /dev/null
85218 +++ b/tools/gcc/generate_size_overflow_hash.sh
85219 @@ -0,0 +1,94 @@
85220 +#!/bin/bash
85221 +
85222 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
85223 +
85224 +header1="size_overflow_hash.h"
85225 +database="size_overflow_hash.data"
85226 +n=65536
85227 +
85228 +usage() {
85229 +cat <<EOF
85230 +usage: $0 options
85231 +OPTIONS:
85232 + -h|--help help
85233 + -o header file
85234 + -d database file
85235 + -n hash array size
85236 +EOF
85237 + return 0
85238 +}
85239 +
85240 +while true
85241 +do
85242 + case "$1" in
85243 + -h|--help) usage && exit 0;;
85244 + -n) n=$2; shift 2;;
85245 + -o) header1="$2"; shift 2;;
85246 + -d) database="$2"; shift 2;;
85247 + --) shift 1; break ;;
85248 + *) break ;;
85249 + esac
85250 +done
85251 +
85252 +create_defines() {
85253 + for i in `seq 0 31`
85254 + do
85255 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
85256 + done
85257 + echo >> "$header1"
85258 +}
85259 +
85260 +create_structs() {
85261 + rm -f "$header1"
85262 +
85263 + create_defines
85264 +
85265 + cat "$database" | while read data
85266 + do
85267 + data_array=($data)
85268 + struct_hash_name="${data_array[0]}"
85269 + funcn="${data_array[1]}"
85270 + params="${data_array[2]}"
85271 + next="${data_array[4]}"
85272 +
85273 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
85274 +
85275 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
85276 + echo -en "\t.param\t= " >> "$header1"
85277 + line=
85278 + for param_num in ${params//-/ };
85279 + do
85280 + line="${line}PARAM"$param_num"|"
85281 + done
85282 +
85283 + echo -e "${line%?},\n};\n" >> "$header1"
85284 + done
85285 +}
85286 +
85287 +create_headers() {
85288 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
85289 +}
85290 +
85291 +create_array_elements() {
85292 + index=0
85293 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
85294 + do
85295 + data_array=($data)
85296 + i="${data_array[3]}"
85297 + hash="${data_array[0]}"
85298 + while [[ $index -lt $i ]]
85299 + do
85300 + echo -e "\t["$index"]\t= NULL," >> "$header1"
85301 + index=$(($index + 1))
85302 + done
85303 + index=$(($index + 1))
85304 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
85305 + done
85306 + echo '};' >> $header1
85307 +}
85308 +
85309 +create_structs
85310 +create_headers
85311 +create_array_elements
85312 +
85313 +exit 0
85314 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85315 new file mode 100644
85316 index 0000000..568b360
85317 --- /dev/null
85318 +++ b/tools/gcc/kallocstat_plugin.c
85319 @@ -0,0 +1,170 @@
85320 +/*
85321 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
85322 + * Licensed under the GPL v2
85323 + *
85324 + * Note: the choice of the license means that the compilation process is
85325 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85326 + * but for the kernel it doesn't matter since it doesn't link against
85327 + * any of the gcc libraries
85328 + *
85329 + * gcc plugin to find the distribution of k*alloc sizes
85330 + *
85331 + * TODO:
85332 + *
85333 + * BUGS:
85334 + * - none known
85335 + */
85336 +#include "gcc-plugin.h"
85337 +#include "config.h"
85338 +#include "system.h"
85339 +#include "coretypes.h"
85340 +#include "tree.h"
85341 +#include "tree-pass.h"
85342 +#include "flags.h"
85343 +#include "intl.h"
85344 +#include "toplev.h"
85345 +#include "plugin.h"
85346 +//#include "expr.h" where are you...
85347 +#include "diagnostic.h"
85348 +#include "plugin-version.h"
85349 +#include "tm.h"
85350 +#include "function.h"
85351 +#include "basic-block.h"
85352 +#include "gimple.h"
85353 +#include "rtl.h"
85354 +#include "emit-rtl.h"
85355 +
85356 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85357 +
85358 +int plugin_is_GPL_compatible;
85359 +
85360 +static const char * const kalloc_functions[] = {
85361 + "__kmalloc",
85362 + "kmalloc",
85363 + "kmalloc_large",
85364 + "kmalloc_node",
85365 + "kmalloc_order",
85366 + "kmalloc_order_trace",
85367 + "kmalloc_slab",
85368 + "kzalloc",
85369 + "kzalloc_node",
85370 +};
85371 +
85372 +static struct plugin_info kallocstat_plugin_info = {
85373 + .version = "201302112000",
85374 +};
85375 +
85376 +static unsigned int execute_kallocstat(void);
85377 +
85378 +static struct gimple_opt_pass kallocstat_pass = {
85379 + .pass = {
85380 + .type = GIMPLE_PASS,
85381 + .name = "kallocstat",
85382 +#if BUILDING_GCC_VERSION >= 4008
85383 + .optinfo_flags = OPTGROUP_NONE,
85384 +#endif
85385 + .gate = NULL,
85386 + .execute = execute_kallocstat,
85387 + .sub = NULL,
85388 + .next = NULL,
85389 + .static_pass_number = 0,
85390 + .tv_id = TV_NONE,
85391 + .properties_required = 0,
85392 + .properties_provided = 0,
85393 + .properties_destroyed = 0,
85394 + .todo_flags_start = 0,
85395 + .todo_flags_finish = 0
85396 + }
85397 +};
85398 +
85399 +static bool is_kalloc(const char *fnname)
85400 +{
85401 + size_t i;
85402 +
85403 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
85404 + if (!strcmp(fnname, kalloc_functions[i]))
85405 + return true;
85406 + return false;
85407 +}
85408 +
85409 +static unsigned int execute_kallocstat(void)
85410 +{
85411 + basic_block bb;
85412 +
85413 + // 1. loop through BBs and GIMPLE statements
85414 + FOR_EACH_BB(bb) {
85415 + gimple_stmt_iterator gsi;
85416 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85417 + // gimple match:
85418 + tree fndecl, size;
85419 + gimple call_stmt;
85420 + const char *fnname;
85421 +
85422 + // is it a call
85423 + call_stmt = gsi_stmt(gsi);
85424 + if (!is_gimple_call(call_stmt))
85425 + continue;
85426 + fndecl = gimple_call_fndecl(call_stmt);
85427 + if (fndecl == NULL_TREE)
85428 + continue;
85429 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
85430 + continue;
85431 +
85432 + // is it a call to k*alloc
85433 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
85434 + if (!is_kalloc(fnname))
85435 + continue;
85436 +
85437 + // is the size arg the result of a simple const assignment
85438 + size = gimple_call_arg(call_stmt, 0);
85439 + while (true) {
85440 + gimple def_stmt;
85441 + expanded_location xloc;
85442 + size_t size_val;
85443 +
85444 + if (TREE_CODE(size) != SSA_NAME)
85445 + break;
85446 + def_stmt = SSA_NAME_DEF_STMT(size);
85447 + if (!def_stmt || !is_gimple_assign(def_stmt))
85448 + break;
85449 + if (gimple_num_ops(def_stmt) != 2)
85450 + break;
85451 + size = gimple_assign_rhs1(def_stmt);
85452 + if (!TREE_CONSTANT(size))
85453 + continue;
85454 + xloc = expand_location(gimple_location(def_stmt));
85455 + if (!xloc.file)
85456 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85457 + size_val = TREE_INT_CST_LOW(size);
85458 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
85459 + break;
85460 + }
85461 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85462 +//debug_tree(gimple_call_fn(call_stmt));
85463 +//print_node(stderr, "pax", fndecl, 4);
85464 + }
85465 + }
85466 +
85467 + return 0;
85468 +}
85469 +
85470 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85471 +{
85472 + const char * const plugin_name = plugin_info->base_name;
85473 + struct register_pass_info kallocstat_pass_info = {
85474 + .pass = &kallocstat_pass.pass,
85475 + .reference_pass_name = "ssa",
85476 + .ref_pass_instance_number = 1,
85477 + .pos_op = PASS_POS_INSERT_AFTER
85478 + };
85479 +
85480 + if (!plugin_default_version_check(version, &gcc_version)) {
85481 + error(G_("incompatible gcc/plugin versions"));
85482 + return 1;
85483 + }
85484 +
85485 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
85486 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
85487 +
85488 + return 0;
85489 +}
85490 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
85491 new file mode 100644
85492 index 0000000..0408e06
85493 --- /dev/null
85494 +++ b/tools/gcc/kernexec_plugin.c
85495 @@ -0,0 +1,465 @@
85496 +/*
85497 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
85498 + * Licensed under the GPL v2
85499 + *
85500 + * Note: the choice of the license means that the compilation process is
85501 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85502 + * but for the kernel it doesn't matter since it doesn't link against
85503 + * any of the gcc libraries
85504 + *
85505 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
85506 + *
85507 + * TODO:
85508 + *
85509 + * BUGS:
85510 + * - none known
85511 + */
85512 +#include "gcc-plugin.h"
85513 +#include "config.h"
85514 +#include "system.h"
85515 +#include "coretypes.h"
85516 +#include "tree.h"
85517 +#include "tree-pass.h"
85518 +#include "flags.h"
85519 +#include "intl.h"
85520 +#include "toplev.h"
85521 +#include "plugin.h"
85522 +//#include "expr.h" where are you...
85523 +#include "diagnostic.h"
85524 +#include "plugin-version.h"
85525 +#include "tm.h"
85526 +#include "function.h"
85527 +#include "basic-block.h"
85528 +#include "gimple.h"
85529 +#include "rtl.h"
85530 +#include "emit-rtl.h"
85531 +#include "tree-flow.h"
85532 +
85533 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85534 +extern rtx emit_move_insn(rtx x, rtx y);
85535 +
85536 +#if BUILDING_GCC_VERSION <= 4006
85537 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
85538 +#endif
85539 +
85540 +#if BUILDING_GCC_VERSION >= 4008
85541 +#define TODO_dump_func 0
85542 +#endif
85543 +
85544 +int plugin_is_GPL_compatible;
85545 +
85546 +static struct plugin_info kernexec_plugin_info = {
85547 + .version = "201302112000",
85548 + .help = "method=[bts|or]\tinstrumentation method\n"
85549 +};
85550 +
85551 +static unsigned int execute_kernexec_reload(void);
85552 +static unsigned int execute_kernexec_fptr(void);
85553 +static unsigned int execute_kernexec_retaddr(void);
85554 +static bool kernexec_cmodel_check(void);
85555 +
85556 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
85557 +static void (*kernexec_instrument_retaddr)(rtx);
85558 +
85559 +static struct gimple_opt_pass kernexec_reload_pass = {
85560 + .pass = {
85561 + .type = GIMPLE_PASS,
85562 + .name = "kernexec_reload",
85563 +#if BUILDING_GCC_VERSION >= 4008
85564 + .optinfo_flags = OPTGROUP_NONE,
85565 +#endif
85566 + .gate = kernexec_cmodel_check,
85567 + .execute = execute_kernexec_reload,
85568 + .sub = NULL,
85569 + .next = NULL,
85570 + .static_pass_number = 0,
85571 + .tv_id = TV_NONE,
85572 + .properties_required = 0,
85573 + .properties_provided = 0,
85574 + .properties_destroyed = 0,
85575 + .todo_flags_start = 0,
85576 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85577 + }
85578 +};
85579 +
85580 +static struct gimple_opt_pass kernexec_fptr_pass = {
85581 + .pass = {
85582 + .type = GIMPLE_PASS,
85583 + .name = "kernexec_fptr",
85584 +#if BUILDING_GCC_VERSION >= 4008
85585 + .optinfo_flags = OPTGROUP_NONE,
85586 +#endif
85587 + .gate = kernexec_cmodel_check,
85588 + .execute = execute_kernexec_fptr,
85589 + .sub = NULL,
85590 + .next = NULL,
85591 + .static_pass_number = 0,
85592 + .tv_id = TV_NONE,
85593 + .properties_required = 0,
85594 + .properties_provided = 0,
85595 + .properties_destroyed = 0,
85596 + .todo_flags_start = 0,
85597 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85598 + }
85599 +};
85600 +
85601 +static struct rtl_opt_pass kernexec_retaddr_pass = {
85602 + .pass = {
85603 + .type = RTL_PASS,
85604 + .name = "kernexec_retaddr",
85605 +#if BUILDING_GCC_VERSION >= 4008
85606 + .optinfo_flags = OPTGROUP_NONE,
85607 +#endif
85608 + .gate = kernexec_cmodel_check,
85609 + .execute = execute_kernexec_retaddr,
85610 + .sub = NULL,
85611 + .next = NULL,
85612 + .static_pass_number = 0,
85613 + .tv_id = TV_NONE,
85614 + .properties_required = 0,
85615 + .properties_provided = 0,
85616 + .properties_destroyed = 0,
85617 + .todo_flags_start = 0,
85618 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
85619 + }
85620 +};
85621 +
85622 +static bool kernexec_cmodel_check(void)
85623 +{
85624 + tree section;
85625 +
85626 + if (ix86_cmodel != CM_KERNEL)
85627 + return false;
85628 +
85629 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
85630 + if (!section || !TREE_VALUE(section))
85631 + return true;
85632 +
85633 + section = TREE_VALUE(TREE_VALUE(section));
85634 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
85635 + return true;
85636 +
85637 + return false;
85638 +}
85639 +
85640 +/*
85641 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
85642 + */
85643 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
85644 +{
85645 + gimple asm_movabs_stmt;
85646 +
85647 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
85648 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
85649 + gimple_asm_set_volatile(asm_movabs_stmt, true);
85650 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
85651 + update_stmt(asm_movabs_stmt);
85652 +}
85653 +
85654 +/*
85655 + * find all asm() stmts that clobber r10 and add a reload of r10
85656 + */
85657 +static unsigned int execute_kernexec_reload(void)
85658 +{
85659 + basic_block bb;
85660 +
85661 + // 1. loop through BBs and GIMPLE statements
85662 + FOR_EACH_BB(bb) {
85663 + gimple_stmt_iterator gsi;
85664 +
85665 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85666 + // gimple match: __asm__ ("" : : : "r10");
85667 + gimple asm_stmt;
85668 + size_t nclobbers;
85669 +
85670 + // is it an asm ...
85671 + asm_stmt = gsi_stmt(gsi);
85672 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
85673 + continue;
85674 +
85675 + // ... clobbering r10
85676 + nclobbers = gimple_asm_nclobbers(asm_stmt);
85677 + while (nclobbers--) {
85678 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
85679 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
85680 + continue;
85681 + kernexec_reload_fptr_mask(&gsi);
85682 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
85683 + break;
85684 + }
85685 + }
85686 + }
85687 +
85688 + return 0;
85689 +}
85690 +
85691 +/*
85692 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
85693 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
85694 + */
85695 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
85696 +{
85697 + gimple assign_intptr, assign_new_fptr, call_stmt;
85698 + tree intptr, old_fptr, new_fptr, kernexec_mask;
85699 +
85700 + call_stmt = gsi_stmt(*gsi);
85701 + old_fptr = gimple_call_fn(call_stmt);
85702 +
85703 + // create temporary unsigned long variable used for bitops and cast fptr to it
85704 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
85705 +#if BUILDING_GCC_VERSION <= 4007
85706 + add_referenced_var(intptr);
85707 + mark_sym_for_renaming(intptr);
85708 +#endif
85709 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
85710 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85711 + update_stmt(assign_intptr);
85712 +
85713 + // apply logical or to temporary unsigned long and bitmask
85714 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
85715 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
85716 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
85717 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85718 + update_stmt(assign_intptr);
85719 +
85720 + // cast temporary unsigned long back to a temporary fptr variable
85721 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
85722 +#if BUILDING_GCC_VERSION <= 4007
85723 + add_referenced_var(new_fptr);
85724 + mark_sym_for_renaming(new_fptr);
85725 +#endif
85726 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
85727 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
85728 + update_stmt(assign_new_fptr);
85729 +
85730 + // replace call stmt fn with the new fptr
85731 + gimple_call_set_fn(call_stmt, new_fptr);
85732 + update_stmt(call_stmt);
85733 +}
85734 +
85735 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
85736 +{
85737 + gimple asm_or_stmt, call_stmt;
85738 + tree old_fptr, new_fptr, input, output;
85739 +#if BUILDING_GCC_VERSION <= 4007
85740 + VEC(tree, gc) *inputs = NULL;
85741 + VEC(tree, gc) *outputs = NULL;
85742 +#else
85743 + vec<tree, va_gc> *inputs = NULL;
85744 + vec<tree, va_gc> *outputs = NULL;
85745 +#endif
85746 +
85747 + call_stmt = gsi_stmt(*gsi);
85748 + old_fptr = gimple_call_fn(call_stmt);
85749 +
85750 + // create temporary fptr variable
85751 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
85752 +#if BUILDING_GCC_VERSION <= 4007
85753 + add_referenced_var(new_fptr);
85754 + mark_sym_for_renaming(new_fptr);
85755 +#endif
85756 +
85757 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
85758 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
85759 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
85760 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
85761 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
85762 +#if BUILDING_GCC_VERSION <= 4007
85763 + VEC_safe_push(tree, gc, inputs, input);
85764 + VEC_safe_push(tree, gc, outputs, output);
85765 +#else
85766 + vec_safe_push(inputs, input);
85767 + vec_safe_push(outputs, output);
85768 +#endif
85769 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
85770 + gimple_asm_set_volatile(asm_or_stmt, true);
85771 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
85772 + update_stmt(asm_or_stmt);
85773 +
85774 + // replace call stmt fn with the new fptr
85775 + gimple_call_set_fn(call_stmt, new_fptr);
85776 + update_stmt(call_stmt);
85777 +}
85778 +
85779 +/*
85780 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
85781 + */
85782 +static unsigned int execute_kernexec_fptr(void)
85783 +{
85784 + basic_block bb;
85785 +
85786 + // 1. loop through BBs and GIMPLE statements
85787 + FOR_EACH_BB(bb) {
85788 + gimple_stmt_iterator gsi;
85789 +
85790 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85791 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
85792 + tree fn;
85793 + gimple call_stmt;
85794 +
85795 + // is it a call ...
85796 + call_stmt = gsi_stmt(gsi);
85797 + if (!is_gimple_call(call_stmt))
85798 + continue;
85799 + fn = gimple_call_fn(call_stmt);
85800 + if (TREE_CODE(fn) == ADDR_EXPR)
85801 + continue;
85802 + if (TREE_CODE(fn) != SSA_NAME)
85803 + gcc_unreachable();
85804 +
85805 + // ... through a function pointer
85806 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
85807 + fn = SSA_NAME_VAR(fn);
85808 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
85809 + debug_tree(fn);
85810 + gcc_unreachable();
85811 + }
85812 + }
85813 + fn = TREE_TYPE(fn);
85814 + if (TREE_CODE(fn) != POINTER_TYPE)
85815 + continue;
85816 + fn = TREE_TYPE(fn);
85817 + if (TREE_CODE(fn) != FUNCTION_TYPE)
85818 + continue;
85819 +
85820 + kernexec_instrument_fptr(&gsi);
85821 +
85822 +//debug_tree(gimple_call_fn(call_stmt));
85823 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85824 + }
85825 + }
85826 +
85827 + return 0;
85828 +}
85829 +
85830 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
85831 +static void kernexec_instrument_retaddr_bts(rtx insn)
85832 +{
85833 + rtx btsq;
85834 + rtvec argvec, constraintvec, labelvec;
85835 + int line;
85836 +
85837 + // create asm volatile("btsq $63,(%%rsp)":::)
85838 + argvec = rtvec_alloc(0);
85839 + constraintvec = rtvec_alloc(0);
85840 + labelvec = rtvec_alloc(0);
85841 + line = expand_location(RTL_LOCATION(insn)).line;
85842 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85843 + MEM_VOLATILE_P(btsq) = 1;
85844 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
85845 + emit_insn_before(btsq, insn);
85846 +}
85847 +
85848 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
85849 +static void kernexec_instrument_retaddr_or(rtx insn)
85850 +{
85851 + rtx orq;
85852 + rtvec argvec, constraintvec, labelvec;
85853 + int line;
85854 +
85855 + // create asm volatile("orq %%r10,(%%rsp)":::)
85856 + argvec = rtvec_alloc(0);
85857 + constraintvec = rtvec_alloc(0);
85858 + labelvec = rtvec_alloc(0);
85859 + line = expand_location(RTL_LOCATION(insn)).line;
85860 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85861 + MEM_VOLATILE_P(orq) = 1;
85862 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
85863 + emit_insn_before(orq, insn);
85864 +}
85865 +
85866 +/*
85867 + * find all asm level function returns and forcibly set the highest bit of the return address
85868 + */
85869 +static unsigned int execute_kernexec_retaddr(void)
85870 +{
85871 + rtx insn;
85872 +
85873 + // 1. find function returns
85874 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85875 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
85876 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
85877 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
85878 + rtx body;
85879 +
85880 + // is it a retn
85881 + if (!JUMP_P(insn))
85882 + continue;
85883 + body = PATTERN(insn);
85884 + if (GET_CODE(body) == PARALLEL)
85885 + body = XVECEXP(body, 0, 0);
85886 + if (!ANY_RETURN_P(body))
85887 + continue;
85888 + kernexec_instrument_retaddr(insn);
85889 + }
85890 +
85891 +// print_simple_rtl(stderr, get_insns());
85892 +// print_rtl(stderr, get_insns());
85893 +
85894 + return 0;
85895 +}
85896 +
85897 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85898 +{
85899 + const char * const plugin_name = plugin_info->base_name;
85900 + const int argc = plugin_info->argc;
85901 + const struct plugin_argument * const argv = plugin_info->argv;
85902 + int i;
85903 + struct register_pass_info kernexec_reload_pass_info = {
85904 + .pass = &kernexec_reload_pass.pass,
85905 + .reference_pass_name = "ssa",
85906 + .ref_pass_instance_number = 1,
85907 + .pos_op = PASS_POS_INSERT_AFTER
85908 + };
85909 + struct register_pass_info kernexec_fptr_pass_info = {
85910 + .pass = &kernexec_fptr_pass.pass,
85911 + .reference_pass_name = "ssa",
85912 + .ref_pass_instance_number = 1,
85913 + .pos_op = PASS_POS_INSERT_AFTER
85914 + };
85915 + struct register_pass_info kernexec_retaddr_pass_info = {
85916 + .pass = &kernexec_retaddr_pass.pass,
85917 + .reference_pass_name = "pro_and_epilogue",
85918 + .ref_pass_instance_number = 1,
85919 + .pos_op = PASS_POS_INSERT_AFTER
85920 + };
85921 +
85922 + if (!plugin_default_version_check(version, &gcc_version)) {
85923 + error(G_("incompatible gcc/plugin versions"));
85924 + return 1;
85925 + }
85926 +
85927 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
85928 +
85929 + if (TARGET_64BIT == 0)
85930 + return 0;
85931 +
85932 + for (i = 0; i < argc; ++i) {
85933 + if (!strcmp(argv[i].key, "method")) {
85934 + if (!argv[i].value) {
85935 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85936 + continue;
85937 + }
85938 + if (!strcmp(argv[i].value, "bts")) {
85939 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
85940 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
85941 + } else if (!strcmp(argv[i].value, "or")) {
85942 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
85943 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
85944 + fix_register("r10", 1, 1);
85945 + } else
85946 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85947 + continue;
85948 + }
85949 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85950 + }
85951 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
85952 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
85953 +
85954 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
85955 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
85956 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
85957 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
85958 +
85959 + return 0;
85960 +}
85961 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
85962 new file mode 100644
85963 index 0000000..1276616
85964 --- /dev/null
85965 +++ b/tools/gcc/latent_entropy_plugin.c
85966 @@ -0,0 +1,321 @@
85967 +/*
85968 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
85969 + * Licensed under the GPL v2
85970 + *
85971 + * Note: the choice of the license means that the compilation process is
85972 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85973 + * but for the kernel it doesn't matter since it doesn't link against
85974 + * any of the gcc libraries
85975 + *
85976 + * gcc plugin to help generate a little bit of entropy from program state,
85977 + * used during boot in the kernel
85978 + *
85979 + * TODO:
85980 + * - add ipa pass to identify not explicitly marked candidate functions
85981 + * - mix in more program state (function arguments/return values, loop variables, etc)
85982 + * - more instrumentation control via attribute parameters
85983 + *
85984 + * BUGS:
85985 + * - LTO needs -flto-partition=none for now
85986 + */
85987 +#include "gcc-plugin.h"
85988 +#include "config.h"
85989 +#include "system.h"
85990 +#include "coretypes.h"
85991 +#include "tree.h"
85992 +#include "tree-pass.h"
85993 +#include "flags.h"
85994 +#include "intl.h"
85995 +#include "toplev.h"
85996 +#include "plugin.h"
85997 +//#include "expr.h" where are you...
85998 +#include "diagnostic.h"
85999 +#include "plugin-version.h"
86000 +#include "tm.h"
86001 +#include "function.h"
86002 +#include "basic-block.h"
86003 +#include "gimple.h"
86004 +#include "rtl.h"
86005 +#include "emit-rtl.h"
86006 +#include "tree-flow.h"
86007 +
86008 +#if BUILDING_GCC_VERSION >= 4008
86009 +#define TODO_dump_func 0
86010 +#endif
86011 +
86012 +int plugin_is_GPL_compatible;
86013 +
86014 +static tree latent_entropy_decl;
86015 +
86016 +static struct plugin_info latent_entropy_plugin_info = {
86017 + .version = "201302112000",
86018 + .help = NULL
86019 +};
86020 +
86021 +static unsigned int execute_latent_entropy(void);
86022 +static bool gate_latent_entropy(void);
86023 +
86024 +static struct gimple_opt_pass latent_entropy_pass = {
86025 + .pass = {
86026 + .type = GIMPLE_PASS,
86027 + .name = "latent_entropy",
86028 +#if BUILDING_GCC_VERSION >= 4008
86029 + .optinfo_flags = OPTGROUP_NONE,
86030 +#endif
86031 + .gate = gate_latent_entropy,
86032 + .execute = execute_latent_entropy,
86033 + .sub = NULL,
86034 + .next = NULL,
86035 + .static_pass_number = 0,
86036 + .tv_id = TV_NONE,
86037 + .properties_required = PROP_gimple_leh | PROP_cfg,
86038 + .properties_provided = 0,
86039 + .properties_destroyed = 0,
86040 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86041 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86042 + }
86043 +};
86044 +
86045 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86046 +{
86047 + if (TREE_CODE(*node) != FUNCTION_DECL) {
86048 + *no_add_attrs = true;
86049 + error("%qE attribute only applies to functions", name);
86050 + }
86051 + return NULL_TREE;
86052 +}
86053 +
86054 +static struct attribute_spec latent_entropy_attr = {
86055 + .name = "latent_entropy",
86056 + .min_length = 0,
86057 + .max_length = 0,
86058 + .decl_required = true,
86059 + .type_required = false,
86060 + .function_type_required = false,
86061 + .handler = handle_latent_entropy_attribute,
86062 +#if BUILDING_GCC_VERSION >= 4007
86063 + .affects_type_identity = false
86064 +#endif
86065 +};
86066 +
86067 +static void register_attributes(void *event_data, void *data)
86068 +{
86069 + register_attribute(&latent_entropy_attr);
86070 +}
86071 +
86072 +static bool gate_latent_entropy(void)
86073 +{
86074 + tree latent_entropy_attr;
86075 +
86076 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
86077 + return latent_entropy_attr != NULL_TREE;
86078 +}
86079 +
86080 +static unsigned HOST_WIDE_INT seed;
86081 +static unsigned HOST_WIDE_INT get_random_const(void)
86082 +{
86083 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
86084 + return seed;
86085 +}
86086 +
86087 +static enum tree_code get_op(tree *rhs)
86088 +{
86089 + static enum tree_code op;
86090 + unsigned HOST_WIDE_INT random_const;
86091 +
86092 + random_const = get_random_const();
86093 +
86094 + switch (op) {
86095 + case BIT_XOR_EXPR:
86096 + op = PLUS_EXPR;
86097 + break;
86098 +
86099 + case PLUS_EXPR:
86100 + if (rhs) {
86101 + op = LROTATE_EXPR;
86102 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
86103 + break;
86104 + }
86105 +
86106 + case LROTATE_EXPR:
86107 + default:
86108 + op = BIT_XOR_EXPR;
86109 + break;
86110 + }
86111 + if (rhs)
86112 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
86113 + return op;
86114 +}
86115 +
86116 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
86117 +{
86118 + gimple_stmt_iterator gsi;
86119 + gimple assign;
86120 + tree addxorrol, rhs;
86121 + enum tree_code op;
86122 +
86123 + op = get_op(&rhs);
86124 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
86125 + assign = gimple_build_assign(local_entropy, addxorrol);
86126 +#if BUILDING_GCC_VERSION <= 4007
86127 + find_referenced_vars_in(assign);
86128 +#endif
86129 +//debug_bb(bb);
86130 + gsi = gsi_after_labels(bb);
86131 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86132 + update_stmt(assign);
86133 +}
86134 +
86135 +static void perturb_latent_entropy(basic_block bb, tree rhs)
86136 +{
86137 + gimple_stmt_iterator gsi;
86138 + gimple assign;
86139 + tree addxorrol, temp;
86140 +
86141 + // 1. create temporary copy of latent_entropy
86142 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
86143 +#if BUILDING_GCC_VERSION <= 4007
86144 + add_referenced_var(temp);
86145 + mark_sym_for_renaming(temp);
86146 +#endif
86147 +
86148 + // 2. read...
86149 + assign = gimple_build_assign(temp, latent_entropy_decl);
86150 +#if BUILDING_GCC_VERSION <= 4007
86151 + find_referenced_vars_in(assign);
86152 +#endif
86153 + gsi = gsi_after_labels(bb);
86154 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86155 + update_stmt(assign);
86156 +
86157 + // 3. ...modify...
86158 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
86159 + assign = gimple_build_assign(temp, addxorrol);
86160 +#if BUILDING_GCC_VERSION <= 4007
86161 + find_referenced_vars_in(assign);
86162 +#endif
86163 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86164 + update_stmt(assign);
86165 +
86166 + // 4. ...write latent_entropy
86167 + assign = gimple_build_assign(latent_entropy_decl, temp);
86168 +#if BUILDING_GCC_VERSION <= 4007
86169 + find_referenced_vars_in(assign);
86170 +#endif
86171 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86172 + update_stmt(assign);
86173 +}
86174 +
86175 +static unsigned int execute_latent_entropy(void)
86176 +{
86177 + basic_block bb;
86178 + gimple assign;
86179 + gimple_stmt_iterator gsi;
86180 + tree local_entropy;
86181 +
86182 + if (!latent_entropy_decl) {
86183 + struct varpool_node *node;
86184 +
86185 +#if BUILDING_GCC_VERSION <= 4007
86186 + for (node = varpool_nodes; node; node = node->next) {
86187 + tree var = node->decl;
86188 +#else
86189 + FOR_EACH_VARIABLE(node) {
86190 + tree var = node->symbol.decl;
86191 +#endif
86192 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
86193 + continue;
86194 + latent_entropy_decl = var;
86195 +// debug_tree(var);
86196 + break;
86197 + }
86198 + if (!latent_entropy_decl) {
86199 +// debug_tree(current_function_decl);
86200 + return 0;
86201 + }
86202 + }
86203 +
86204 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
86205 +
86206 + // 1. create local entropy variable
86207 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
86208 +#if BUILDING_GCC_VERSION <= 4007
86209 + add_referenced_var(local_entropy);
86210 + mark_sym_for_renaming(local_entropy);
86211 +#endif
86212 +
86213 + // 2. initialize local entropy variable
86214 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86215 + if (dom_info_available_p(CDI_DOMINATORS))
86216 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86217 + gsi = gsi_start_bb(bb);
86218 +
86219 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
86220 +// gimple_set_location(assign, loc);
86221 +#if BUILDING_GCC_VERSION <= 4007
86222 + find_referenced_vars_in(assign);
86223 +#endif
86224 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86225 + update_stmt(assign);
86226 + bb = bb->next_bb;
86227 +
86228 + // 3. instrument each BB with an operation on the local entropy variable
86229 + while (bb != EXIT_BLOCK_PTR) {
86230 + perturb_local_entropy(bb, local_entropy);
86231 + bb = bb->next_bb;
86232 + };
86233 +
86234 + // 4. mix local entropy into the global entropy variable
86235 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
86236 + return 0;
86237 +}
86238 +
86239 +static void start_unit_callback(void *gcc_data, void *user_data)
86240 +{
86241 +#if BUILDING_GCC_VERSION >= 4007
86242 + seed = get_random_seed(false);
86243 +#else
86244 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
86245 + seed *= seed;
86246 +#endif
86247 +
86248 + if (in_lto_p)
86249 + return;
86250 +
86251 + // extern u64 latent_entropy
86252 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
86253 +
86254 + TREE_STATIC(latent_entropy_decl) = 1;
86255 + TREE_PUBLIC(latent_entropy_decl) = 1;
86256 + TREE_USED(latent_entropy_decl) = 1;
86257 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
86258 + DECL_EXTERNAL(latent_entropy_decl) = 1;
86259 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
86260 + DECL_INITIAL(latent_entropy_decl) = NULL;
86261 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
86262 +// varpool_finalize_decl(latent_entropy_decl);
86263 +// varpool_mark_needed_node(latent_entropy_decl);
86264 +}
86265 +
86266 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86267 +{
86268 + const char * const plugin_name = plugin_info->base_name;
86269 + struct register_pass_info latent_entropy_pass_info = {
86270 + .pass = &latent_entropy_pass.pass,
86271 + .reference_pass_name = "optimized",
86272 + .ref_pass_instance_number = 1,
86273 + .pos_op = PASS_POS_INSERT_BEFORE
86274 + };
86275 +
86276 + if (!plugin_default_version_check(version, &gcc_version)) {
86277 + error(G_("incompatible gcc/plugin versions"));
86278 + return 1;
86279 + }
86280 +
86281 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
86282 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86283 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
86284 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86285 +
86286 + return 0;
86287 +}
86288 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
86289 new file mode 100644
86290 index 0000000..5921fd7
86291 --- /dev/null
86292 +++ b/tools/gcc/size_overflow_hash.data
86293 @@ -0,0 +1,3713 @@
86294 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
86295 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
86296 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
86297 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
86298 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
86299 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
86300 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
86301 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
86302 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
86303 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
86304 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
86305 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
86306 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
86307 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
86308 +create_log_8225 create_log 2 8225 NULL
86309 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
86310 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
86311 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
86312 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
86313 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
86314 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
86315 +padzero_55 padzero 1 55 &sel_read_policyvers_55
86316 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
86317 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
86318 +read_file_blob_57406 read_file_blob 3 57406 NULL
86319 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
86320 +enclosure_register_57412 enclosure_register 3 57412 NULL
86321 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
86322 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
86323 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
86324 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
86325 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
86326 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
86327 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
86328 +init_cdev_8274 init_cdev 1 8274 NULL
86329 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
86330 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
86331 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
86332 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
86333 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
86334 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
86335 +load_msg_95 load_msg 2 95 NULL
86336 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
86337 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
86338 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86339 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
86340 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
86341 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
86342 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
86343 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
86344 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
86345 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
86346 +send_midi_async_57463 send_midi_async 3 57463 NULL
86347 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
86348 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
86349 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
86350 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
86351 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
86352 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
86353 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
86354 +init_q_132 init_q 4 132 NULL
86355 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
86356 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
86357 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
86358 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
86359 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
86360 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
86361 +uio_read_49300 uio_read 3 49300 NULL
86362 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
86363 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
86364 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
86365 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
86366 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
86367 +play_iframe_8219 play_iframe 3 8219 NULL
86368 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
86369 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
86370 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
86371 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
86372 +init_tag_map_57515 init_tag_map 3 57515 NULL
86373 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
86374 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
86375 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
86376 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
86377 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
86378 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
86379 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
86380 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
86381 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
86382 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
86383 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
86384 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
86385 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86386 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
86387 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
86388 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
86389 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
86390 +cache_read_24790 cache_read 3 24790 NULL
86391 +px_raw_event_49371 px_raw_event 4 49371 NULL
86392 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
86393 +compat_filldir_32999 compat_filldir 3 32999 NULL
86394 +hci_si_event_1404 hci_si_event 3 1404 NULL
86395 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
86396 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
86397 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
86398 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
86399 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
86400 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
86401 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
86402 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
86403 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
86404 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
86405 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
86406 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
86407 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
86408 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
86409 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
86410 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
86411 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
86412 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
86413 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
86414 +mem_read_57631 mem_read 3 57631 NULL
86415 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
86416 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
86417 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
86418 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
86419 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
86420 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
86421 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
86422 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
86423 +queues_read_24877 queues_read 3 24877 NULL
86424 +__fprog_create_41263 __fprog_create 2 41263 NULL
86425 +syslog_print_307 syslog_print 2 307 NULL
86426 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
86427 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
86428 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
86429 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
86430 +r3964_write_57662 r3964_write 4 57662 NULL
86431 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
86432 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
86433 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
86434 +alloc_context_41283 alloc_context 1 41283 NULL
86435 +__lgwrite_57669 __lgwrite 4 57669 NULL
86436 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
86437 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
86438 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
86439 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
86440 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86441 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
86442 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
86443 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
86444 +write_node_33121 write_node 4 33121 NULL
86445 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86446 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
86447 +profile_remove_8556 profile_remove 3 8556 NULL
86448 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86449 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
86450 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
86451 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
86452 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
86453 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
86454 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
86455 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
86456 +tower_write_8580 tower_write 3 8580 NULL
86457 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
86458 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
86459 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
86460 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
86461 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
86462 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
86463 +smk_write_access_49561 smk_write_access 3 49561 NULL
86464 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
86465 +kmp_init_41373 kmp_init 2 41373 NULL
86466 +context_alloc_24645 context_alloc 3 24645 NULL
86467 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
86468 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
86469 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
86470 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
86471 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
86472 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
86473 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
86474 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
86475 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
86476 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
86477 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
86478 +pp_read_33210 pp_read 3 33210 NULL
86479 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
86480 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
86481 +ivtv_read_57796 ivtv_read 3 57796 NULL
86482 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
86483 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
86484 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
86485 +heap_init_49617 heap_init 2 49617 NULL
86486 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
86487 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86488 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
86489 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
86490 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
86491 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
86492 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
86493 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
86494 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
86495 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
86496 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
86497 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
86498 +st_write_16874 st_write 3 16874 NULL
86499 +copy_to_user_57835 copy_to_user 3 57835 NULL
86500 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
86501 +pidlist_resize_496 pidlist_resize 2 496 NULL
86502 +flash_read_57843 flash_read 3 57843 NULL
86503 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
86504 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
86505 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
86506 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
86507 +arcfb_write_8702 arcfb_write 3 8702 NULL
86508 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86509 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
86510 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
86511 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86512 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86513 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
86514 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
86515 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
86516 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
86517 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
86518 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
86519 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
86520 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
86521 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
86522 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
86523 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
86524 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
86525 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
86526 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
86527 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
86528 +devres_alloc_551 devres_alloc 2 551 NULL
86529 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
86530 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
86531 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
86532 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
86533 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
86534 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
86535 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
86536 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
86537 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
86538 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
86539 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86540 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
86541 +sys_prctl_8766 sys_prctl 4 8766 NULL
86542 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
86543 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
86544 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
86545 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
86546 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
86547 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
86548 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
86549 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
86550 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
86551 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
86552 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
86553 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
86554 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
86555 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
86556 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
86557 +gserial_setup_41558 gserial_setup 2 41558 NULL
86558 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
86559 +rx_57944 rx 4 57944 NULL
86560 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
86561 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
86562 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
86563 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
86564 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
86565 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
86566 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86567 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
86568 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
86569 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
86570 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
86571 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
86572 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
86573 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
86574 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86575 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
86576 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
86577 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
86578 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
86579 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86580 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86581 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
86582 +a2mp_send_41615 a2mp_send 4 41615 NULL
86583 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
86584 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
86585 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
86586 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
86587 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
86588 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
86589 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
86590 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
86591 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
86592 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
86593 +add_uuid_49831 add_uuid 4 49831 NULL
86594 +send_pages_8872 send_pages 3 8872 NULL
86595 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
86596 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
86597 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
86598 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
86599 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
86600 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
86601 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
86602 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
86603 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
86604 +vfs_writev_25278 vfs_writev 3 25278 NULL
86605 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
86606 +alloc_async_14208 alloc_async 1 14208 NULL
86607 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
86608 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
86609 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
86610 +create_entry_33479 create_entry 2 33479 NULL
86611 +mce_async_out_58056 mce_async_out 3 58056 NULL
86612 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
86613 +sys_preadv_17100 sys_preadv 3 17100 NULL
86614 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
86615 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
86616 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
86617 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
86618 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
86619 +res_counter_read_33499 res_counter_read 4 33499 NULL
86620 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
86621 +cm4040_write_58079 cm4040_write 3 58079 NULL
86622 +fb_read_33506 fb_read 3 33506 NULL
86623 +help_25316 help 5 25316 NULL nohasharray
86624 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
86625 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
86626 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
86627 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
86628 +ddp_set_map_751 ddp_set_map 4 751 NULL
86629 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
86630 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
86631 +dvb_video_write_754 dvb_video_write 3 754 NULL
86632 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
86633 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
86634 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
86635 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
86636 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
86637 +udi_log_event_58105 udi_log_event 3 58105 NULL
86638 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
86639 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
86640 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
86641 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
86642 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
86643 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
86644 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
86645 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
86646 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
86647 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
86648 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
86649 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
86650 +sep_read_17161 sep_read 3 17161 NULL
86651 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
86652 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
86653 +dup_array_33551 dup_array 3 33551 NULL
86654 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
86655 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
86656 +fillonedir_41746 fillonedir 3 41746 NULL
86657 +init_bch_64130 init_bch 1-2 64130 NULL
86658 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
86659 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
86660 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
86661 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
86662 +savemem_58129 savemem 3 58129 NULL
86663 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
86664 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86665 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
86666 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
86667 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
86668 +if_writecmd_815 if_writecmd 2 815 NULL
86669 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
86670 +read_fifo_826 read_fifo 3 826 NULL
86671 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
86672 +scsi_execute_33596 scsi_execute 5 33596 NULL
86673 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
86674 +ms_rw_17220 ms_rw 3-4 17220 NULL
86675 +read_tree_block_841 read_tree_block 3 841 NULL
86676 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
86677 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
86678 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
86679 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
86680 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
86681 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
86682 +um_idi_read_850 um_idi_read 3 850 NULL
86683 +__module_alloc_50004 __module_alloc 1 50004 NULL
86684 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
86685 +ts_read_44687 ts_read 3 44687 NULL
86686 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
86687 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
86688 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
86689 +provide_user_output_41105 provide_user_output 3 41105 NULL
86690 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
86691 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
86692 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
86693 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
86694 +alloc_ep_17269 alloc_ep 1 17269 NULL
86695 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
86696 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
86697 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
86698 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
86699 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
86700 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
86701 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
86702 +create_queues_9088 create_queues 2-3 9088 NULL
86703 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
86704 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
86705 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
86706 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
86707 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
86708 +read_file_debug_58256 read_file_debug 3 58256 NULL
86709 +skb_pad_17302 skb_pad 2 17302 NULL
86710 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
86711 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
86712 +profile_load_58267 profile_load 3 58267 NULL
86713 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
86714 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
86715 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
86716 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
86717 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
86718 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
86719 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
86720 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
86721 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
86722 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
86723 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
86724 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
86725 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
86726 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
86727 +get_packet_41914 get_packet 3 41914 NULL
86728 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
86729 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
86730 +read_file_slot_50111 read_file_slot 3 50111 NULL
86731 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
86732 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
86733 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
86734 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86735 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
86736 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
86737 +copy_items_50140 copy_items 6 50140 NULL
86738 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
86739 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
86740 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
86741 +map_addr_56144 map_addr 7 56144 NULL
86742 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
86743 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
86744 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
86745 +portnames_read_41958 portnames_read 3 41958 NULL
86746 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
86747 +hashtab_create_33769 hashtab_create 3 33769 NULL
86748 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
86749 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
86750 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
86751 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
86752 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
86753 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
86754 +odev_update_50169 odev_update 2 50169 NULL
86755 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
86756 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
86757 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
86758 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86759 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
86760 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
86761 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
86762 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
86763 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86764 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
86765 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
86766 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
86767 +lguest_map_42008 lguest_map 1-2 42008 NULL
86768 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
86769 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
86770 +pool_allocate_42012 pool_allocate 3 42012 NULL
86771 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
86772 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
86773 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
86774 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
86775 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
86776 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
86777 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
86778 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
86779 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
86780 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
86781 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
86782 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
86783 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
86784 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
86785 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
86786 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
86787 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
86788 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
86789 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
86790 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
86791 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
86792 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
86793 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
86794 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
86795 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
86796 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
86797 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
86798 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
86799 +config_proc_write_33878 config_proc_write 3 33878 NULL
86800 +capabilities_read_58457 capabilities_read 3 58457 NULL
86801 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
86802 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
86803 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
86804 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
86805 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
86806 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
86807 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
86808 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
86809 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
86810 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
86811 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
86812 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
86813 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
86814 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
86815 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
86816 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
86817 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
86818 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
86819 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
86820 +vme_user_write_15587 vme_user_write 3 15587 NULL
86821 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
86822 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
86823 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
86824 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
86825 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
86826 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
86827 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
86828 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
86829 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
86830 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
86831 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
86832 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
86833 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
86834 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
86835 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
86836 +read_9397 read 3 9397 NULL
86837 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
86838 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
86839 +printer_write_60276 printer_write 3 60276 NULL
86840 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
86841 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
86842 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
86843 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
86844 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
86845 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
86846 +osst_execute_17607 osst_execute 7-6 17607 NULL
86847 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
86848 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
86849 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
86850 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
86851 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
86852 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
86853 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
86854 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
86855 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
86856 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
86857 +xip_file_read_58592 xip_file_read 3 58592 NULL
86858 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
86859 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
86860 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
86861 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
86862 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
86863 +ppp_write_34034 ppp_write 3 34034 NULL
86864 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
86865 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
86866 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
86867 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
86868 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
86869 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
86870 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
86871 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
86872 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
86873 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
86874 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
86875 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
86876 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
86877 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
86878 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
86879 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
86880 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
86881 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
86882 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
86883 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
86884 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
86885 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
86886 +lp_write_9511 lp_write 3 9511 NULL
86887 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
86888 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
86889 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
86890 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
86891 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
86892 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
86893 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
86894 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
86895 +read_file_dma_9530 read_file_dma 3 9530 NULL
86896 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
86897 +rcname_read_25919 rcname_read 3 25919 NULL
86898 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
86899 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
86900 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
86901 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
86902 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
86903 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
86904 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
86905 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
86906 +key_flags_read_25931 key_flags_read 3 25931 NULL
86907 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
86908 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
86909 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
86910 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
86911 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
86912 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
86913 +fw_node_create_9559 fw_node_create 2 9559 NULL
86914 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
86915 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
86916 +kobj_map_9566 kobj_map 2-3 9566 NULL
86917 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
86918 +acpi_map_58725 acpi_map 1-2 58725 NULL
86919 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
86920 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
86921 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
86922 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
86923 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
86924 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
86925 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
86926 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
86927 +file_read_actor_1401 file_read_actor 4 1401 NULL
86928 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86929 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
86930 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
86931 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
86932 +do_sync_9604 do_sync 1 9604 NULL
86933 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
86934 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86935 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
86936 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
86937 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
86938 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
86939 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
86940 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
86941 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
86942 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
86943 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
86944 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
86945 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
86946 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
86947 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
86948 +sge_rx_50594 sge_rx 3 50594 NULL
86949 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
86950 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
86951 +skb_padto_50759 skb_padto 2 50759 NULL
86952 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
86953 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
86954 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
86955 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
86956 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
86957 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
86958 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
86959 +ep_read_58813 ep_read 3 58813 NULL
86960 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
86961 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
86962 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
86963 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
86964 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
86965 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
86966 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
86967 +dns_query_9676 dns_query 3 9676 NULL
86968 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
86969 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
86970 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
86971 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
86972 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
86973 +command_write_58841 command_write 3 58841 NULL
86974 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86975 +dev_config_8506 dev_config 3 8506 NULL
86976 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
86977 +sys_readv_50664 sys_readv 3 50664 NULL
86978 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
86979 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
86980 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
86981 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
86982 +recover_head_17904 recover_head 3 17904 NULL
86983 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
86984 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
86985 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
86986 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
86987 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
86988 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
86989 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
86990 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
86991 +skb_cow_26138 skb_cow 2 26138 NULL
86992 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
86993 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
86994 +do_sigpending_9766 do_sigpending 2 9766 NULL
86995 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
86996 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
86997 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
86998 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
86999 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
87000 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
87001 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
87002 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
87003 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
87004 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
87005 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
87006 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
87007 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
87008 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
87009 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
87010 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
87011 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
87012 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
87013 +get_registers_26187 get_registers 3 26187 NULL
87014 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
87015 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
87016 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
87017 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
87018 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
87019 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
87020 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
87021 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
87022 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
87023 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
87024 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
87025 +mce_write_26201 mce_write 3 26201 NULL
87026 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87027 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
87028 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
87029 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
87030 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
87031 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
87032 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
87033 +tpm_write_50798 tpm_write 3 50798 NULL
87034 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
87035 +tun_do_read_50800 tun_do_read 4 50800 NULL
87036 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
87037 +write_flush_50803 write_flush 3 50803 NULL
87038 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
87039 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
87040 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
87041 +dvb_play_50814 dvb_play 3 50814 NULL
87042 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
87043 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
87044 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
87045 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
87046 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
87047 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
87048 +dma_attach_50831 dma_attach 6-7 50831 NULL
87049 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
87050 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
87051 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
87052 +packet_came_18072 packet_came 3 18072 NULL
87053 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
87054 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
87055 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
87056 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
87057 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
87058 +get_vm_area_18080 get_vm_area 1 18080 NULL
87059 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
87060 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
87061 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
87062 +self_check_write_50856 self_check_write 5 50856 NULL
87063 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
87064 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
87065 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
87066 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
87067 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
87068 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
87069 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
87070 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
87071 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87072 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
87073 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
87074 +vb2_read_42703 vb2_read 3 42703 NULL
87075 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
87076 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
87077 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
87078 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
87079 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
87080 +read_file_misc_9948 read_file_misc 3 9948 NULL
87081 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
87082 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
87083 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
87084 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
87085 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
87086 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
87087 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
87088 +cosa_write_1774 cosa_write 3 1774 NULL
87089 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
87090 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
87091 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
87092 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
87093 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
87094 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
87095 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
87096 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
87097 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
87098 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
87099 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
87100 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
87101 +mld_newpack_50950 mld_newpack 2 50950 NULL
87102 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
87103 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
87104 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
87105 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
87106 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
87107 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
87108 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
87109 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
87110 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
87111 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
87112 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
87113 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
87114 +handle_request_10024 handle_request 9 10024 NULL
87115 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
87116 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
87117 +timeout_write_50991 timeout_write 3 50991 NULL
87118 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
87119 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
87120 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87121 +proc_write_51003 proc_write 3 51003 NULL
87122 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
87123 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
87124 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
87125 +set_arg_42824 set_arg 3 42824 NULL
87126 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
87127 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
87128 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
87129 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
87130 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87131 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
87132 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
87133 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
87134 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
87135 +dt3155_read_59226 dt3155_read 3 59226 NULL
87136 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
87137 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
87138 +dump_midi_51040 dump_midi 3 51040 NULL
87139 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
87140 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
87141 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
87142 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
87143 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
87144 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
87145 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
87146 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
87147 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
87148 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
87149 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
87150 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
87151 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
87152 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
87153 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
87154 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
87155 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
87156 +read_vmcore_26501 read_vmcore 3 26501 NULL
87157 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
87158 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
87159 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
87160 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
87161 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
87162 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
87163 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
87164 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
87165 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
87166 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87167 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87168 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87169 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
87170 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87171 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87172 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
87173 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
87174 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
87175 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
87176 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
87177 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
87178 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
87179 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
87180 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
87181 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
87182 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
87183 +fd_copyout_59323 fd_copyout 3 59323 NULL
87184 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
87185 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
87186 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
87187 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
87188 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87189 +solos_param_store_34755 solos_param_store 4 34755 NULL
87190 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
87191 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
87192 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
87193 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
87194 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
87195 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
87196 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
87197 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
87198 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
87199 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
87200 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
87201 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
87202 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
87203 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
87204 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
87205 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
87206 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
87207 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
87208 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
87209 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
87210 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
87211 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
87212 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
87213 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
87214 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
87215 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
87216 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
87217 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
87218 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
87219 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
87220 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
87221 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
87222 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
87223 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
87224 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
87225 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
87226 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
87227 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
87228 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
87229 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
87230 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
87231 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
87232 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
87233 +tipc_send_51238 tipc_send 4 51238 NULL
87234 +drm_property_create_51239 drm_property_create 4 51239 NULL
87235 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
87236 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
87237 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
87238 +audit_expand_2098 audit_expand 2 2098 NULL
87239 +st_read_51251 st_read 3 51251 NULL
87240 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
87241 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
87242 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
87243 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
87244 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
87245 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
87246 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
87247 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
87248 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
87249 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
87250 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
87251 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
87252 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
87253 +c4_add_card_54968 c4_add_card 3 54968 NULL
87254 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
87255 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
87256 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
87257 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
87258 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
87259 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
87260 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
87261 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
87262 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
87263 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
87264 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
87265 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
87266 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
87267 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
87268 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
87269 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
87270 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
87271 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
87272 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
87273 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
87274 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
87275 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
87276 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
87277 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
87278 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
87279 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
87280 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87281 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
87282 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
87283 +debug_output_18575 debug_output 3 18575 NULL
87284 +Realloc_34961 Realloc 2 34961 NULL
87285 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
87286 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
87287 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
87288 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
87289 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
87290 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
87291 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
87292 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
87293 +vhci_write_2224 vhci_write 3 2224 NULL
87294 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
87295 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
87296 +rb_alloc_3102 rb_alloc 1 3102 NULL
87297 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
87298 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
87299 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
87300 +write_pbl_59583 write_pbl 4 59583 NULL
87301 +from_buffer_18625 from_buffer 3 18625 NULL
87302 +uio_write_43202 uio_write 3 43202 NULL
87303 +memdup_user_59590 memdup_user 2 59590 NULL
87304 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
87305 +iso_callback_43208 iso_callback 3 43208 NULL
87306 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
87307 +smk_write_load_26829 smk_write_load 3 26829 NULL
87308 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
87309 +do_update_counters_2259 do_update_counters 4 2259 NULL
87310 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
87311 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
87312 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
87313 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
87314 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
87315 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
87316 +mtrr_write_59622 mtrr_write 3 59622 NULL
87317 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
87318 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
87319 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
87320 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
87321 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
87322 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
87323 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
87324 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
87325 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
87326 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
87327 +fixup_leb_43256 fixup_leb 3 43256 NULL
87328 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
87329 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
87330 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
87331 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
87332 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
87333 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
87334 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
87335 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
87336 +evtchn_write_43278 evtchn_write 3 43278 NULL
87337 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
87338 +store_ifalias_35088 store_ifalias 4 35088 NULL
87339 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
87340 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
87341 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
87342 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
87343 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
87344 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
87345 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
87346 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
87347 +capi_write_35104 capi_write 3 35104 NULL nohasharray
87348 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
87349 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
87350 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
87351 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
87352 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
87353 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
87354 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
87355 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
87356 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
87357 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87358 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
87359 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
87360 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
87361 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
87362 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
87363 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
87364 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
87365 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
87366 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
87367 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
87368 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
87369 +do_trimming_26952 do_trimming 3 26952 NULL
87370 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
87371 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
87372 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
87373 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
87374 +alloc_buf_34532 alloc_buf 1 34532 NULL
87375 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
87376 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
87377 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
87378 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
87379 +otp_read_10594 otp_read 2-4-5 10594 NULL
87380 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
87381 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
87382 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
87383 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87384 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
87385 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
87386 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
87387 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
87388 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
87389 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
87390 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
87391 +venus_remove_59781 venus_remove 4 59781 NULL
87392 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
87393 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
87394 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
87395 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
87396 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
87397 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
87398 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
87399 +xenfb_write_43412 xenfb_write 3 43412 NULL
87400 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
87401 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
87402 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
87403 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
87404 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
87405 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
87406 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
87407 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
87408 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
87409 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
87410 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
87411 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
87412 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
87413 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
87414 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
87415 +cmd_complete_51629 cmd_complete 6 51629 NULL
87416 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
87417 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
87418 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
87419 +set_fd_set_35249 set_fd_set 1 35249 NULL
87420 +wiphy_new_2482 wiphy_new 2 2482 NULL
87421 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
87422 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
87423 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
87424 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
87425 +tcp_push_10680 tcp_push 3 10680 NULL
87426 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
87427 +c101_run_37279 c101_run 2 37279 NULL
87428 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
87429 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
87430 +tun_put_user_59849 tun_put_user 4 59849 NULL
87431 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
87432 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
87433 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
87434 +dm_write_2513 dm_write 3 2513 NULL
87435 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
87436 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
87437 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
87438 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
87439 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
87440 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
87441 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
87442 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
87443 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
87444 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
87445 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
87446 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
87447 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
87448 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
87449 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
87450 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
87451 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
87452 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
87453 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
87454 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
87455 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
87456 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
87457 +sel_write_access_51704 sel_write_access 3 51704 NULL
87458 +sys_syslog_10746 sys_syslog 3 10746 NULL
87459 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
87460 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
87461 +do_readlink_43518 do_readlink 2 43518 NULL
87462 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
87463 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
87464 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
87465 +read_file_reset_52310 read_file_reset 3 52310 NULL
87466 +pms_capture_27142 pms_capture 4 27142 NULL
87467 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
87468 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
87469 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
87470 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
87471 +msg_set_51725 msg_set 3 51725 NULL
87472 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
87473 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
87474 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
87475 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
87476 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
87477 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
87478 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
87479 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87480 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
87481 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
87482 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
87483 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
87484 +sys_bind_10799 sys_bind 3 10799 NULL
87485 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
87486 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
87487 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
87488 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
87489 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
87490 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
87491 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
87492 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
87493 +send_command_10832 send_command 4 10832 NULL
87494 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
87495 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
87496 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
87497 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87498 +proc_read_43614 proc_read 3 43614 NULL
87499 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
87500 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
87501 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
87502 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
87503 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
87504 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
87505 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
87506 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
87507 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
87508 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87509 +vmalloc_15464 vmalloc 1 15464 NULL
87510 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
87511 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
87512 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
87513 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
87514 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
87515 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
87516 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
87517 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
87518 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
87519 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
87520 +adu_write_30487 adu_write 3 30487 NULL
87521 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
87522 +get_scq_10897 get_scq 2 10897 NULL
87523 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
87524 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
87525 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
87526 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
87527 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
87528 +load_module_60056 load_module 2 60056 NULL nohasharray
87529 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
87530 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
87531 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
87532 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
87533 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
87534 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
87535 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
87536 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
87537 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
87538 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
87539 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
87540 +user_read_51881 user_read 3 51881 NULL
87541 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
87542 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
87543 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
87544 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
87545 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
87546 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
87547 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
87548 +async_setkey_35521 async_setkey 3 35521 NULL
87549 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
87550 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
87551 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
87552 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
87553 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
87554 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
87555 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87556 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87557 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
87558 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
87559 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
87560 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
87561 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
87562 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
87563 +alloc_context_3194 alloc_context 1 3194 NULL
87564 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
87565 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
87566 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
87567 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
87568 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
87569 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
87570 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
87571 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
87572 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
87573 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
87574 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87575 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
87576 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
87577 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
87578 +init_state_60165 init_state 2 60165 NULL
87579 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
87580 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
87581 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
87582 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
87583 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
87584 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
87585 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
87586 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
87587 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
87588 +calc_hmac_32010 calc_hmac 3 32010 NULL
87589 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
87590 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
87591 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
87592 +kernel_readv_35617 kernel_readv 3 35617 NULL
87593 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
87594 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
87595 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
87596 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
87597 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
87598 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
87599 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
87600 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
87601 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
87602 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
87603 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
87604 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
87605 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
87606 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
87607 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87608 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
87609 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
87610 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
87611 +store_debug_level_35652 store_debug_level 3 35652 NULL
87612 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87613 +read_flush_43851 read_flush 3 43851 NULL
87614 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
87615 +cmm_write_2896 cmm_write 3 2896 NULL
87616 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
87617 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
87618 +tunables_write_59563 tunables_write 3 59563 NULL
87619 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
87620 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
87621 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
87622 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
87623 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
87624 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
87625 +dm_table_create_35687 dm_table_create 3 35687 NULL
87626 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
87627 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
87628 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
87629 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
87630 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
87631 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
87632 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
87633 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
87634 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
87635 +debug_read_19322 debug_read 3 19322 NULL
87636 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
87637 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
87638 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
87639 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
87640 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
87641 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
87642 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
87643 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
87644 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
87645 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
87646 +doc_probe_23285 doc_probe 1 23285 NULL
87647 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
87648 +SendString_43928 SendString 3 43928 NULL
87649 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
87650 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
87651 +retry_count_read_52129 retry_count_read 3 52129 NULL
87652 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87653 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
87654 +read_zero_19366 read_zero 3 19366 NULL
87655 +bch_alloc_4593 bch_alloc 1 4593 NULL
87656 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
87657 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
87658 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
87659 +raid5_resize_63306 raid5_resize 2 63306 NULL
87660 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
87661 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
87662 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
87663 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
87664 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
87665 +depth_write_3021 depth_write 3 3021 NULL
87666 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
87667 +read_file_stations_35795 read_file_stations 3 35795 NULL
87668 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
87669 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
87670 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
87671 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
87672 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
87673 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
87674 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
87675 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
87676 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
87677 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
87678 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
87679 +driver_names_read_60399 driver_names_read 3 60399 NULL
87680 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
87681 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
87682 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
87683 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
87684 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
87685 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
87686 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
87687 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
87688 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
87689 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
87690 +rx_data_60442 rx_data 4 60442 NULL
87691 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
87692 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
87693 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
87694 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
87695 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87696 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
87697 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
87698 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
87699 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
87700 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
87701 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
87702 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
87703 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
87704 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
87705 +construct_key_11329 construct_key 3 11329 NULL
87706 +evm_write_key_27715 evm_write_key 3 27715 NULL
87707 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
87708 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
87709 +filldir_55137 filldir 3 55137 NULL
87710 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
87711 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
87712 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
87713 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
87714 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
87715 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
87716 +sel_write_create_11353 sel_write_create 3 11353 NULL
87717 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
87718 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
87719 +hwflags_read_52318 hwflags_read 3 52318 NULL
87720 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
87721 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
87722 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
87723 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
87724 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
87725 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
87726 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
87727 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
87728 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
87729 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
87730 +nfsd_read_19568 nfsd_read 5 19568 NULL
87731 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
87732 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
87733 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
87734 +kcalloc_27770 kcalloc 1-2 27770 NULL
87735 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
87736 +bm_status_read_19583 bm_status_read 3 19583 NULL
87737 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
87738 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
87739 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
87740 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
87741 +acl_alloc_35979 acl_alloc 1 35979 NULL
87742 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
87743 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
87744 +str_to_user_11411 str_to_user 2 11411 NULL
87745 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
87746 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
87747 +trace_options_read_11419 trace_options_read 3 11419 NULL
87748 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
87749 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
87750 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
87751 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
87752 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
87753 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
87754 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
87755 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
87756 +console_store_36007 console_store 4 36007 NULL
87757 +bttv_read_11432 bttv_read 3 11432 NULL
87758 +key_key_read_3241 key_key_read 3 3241 NULL
87759 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
87760 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
87761 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
87762 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
87763 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
87764 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87765 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
87766 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
87767 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
87768 +um_idi_write_18293 um_idi_write 3 18293 NULL
87769 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
87770 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
87771 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
87772 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
87773 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
87774 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
87775 +sys_init_module_36047 sys_init_module 2 36047 NULL
87776 +read_profile_27859 read_profile 3 27859 NULL
87777 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
87778 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
87779 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
87780 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
87781 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
87782 +refill_pool_19477 refill_pool 2 19477 NULL
87783 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
87784 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
87785 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
87786 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
87787 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
87788 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
87789 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
87790 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
87791 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
87792 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
87793 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
87794 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
87795 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
87796 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
87797 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
87798 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
87799 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87800 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
87801 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
87802 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
87803 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
87804 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
87805 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
87806 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
87807 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
87808 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
87809 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
87810 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
87811 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
87812 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
87813 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
87814 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
87815 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
87816 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87817 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
87818 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
87819 +init_data_container_60709 init_data_container 1 60709 NULL
87820 +p9_client_read_19750 p9_client_read 5 19750 NULL
87821 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
87822 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
87823 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
87824 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
87825 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
87826 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
87827 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
87828 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
87829 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
87830 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
87831 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
87832 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
87833 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
87834 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
87835 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
87836 +send_stream_3397 send_stream 4 3397 NULL
87837 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
87838 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
87839 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
87840 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
87841 +msix_map_region_3411 msix_map_region 3 3411 NULL
87842 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
87843 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
87844 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
87845 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
87846 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
87847 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
87848 +opticon_write_60775 opticon_write 4 60775 NULL
87849 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
87850 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
87851 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
87852 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
87853 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
87854 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
87855 +vip_read_19832 vip_read 3 19832 NULL
87856 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
87857 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
87858 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
87859 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
87860 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
87861 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
87862 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
87863 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
87864 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
87865 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
87866 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
87867 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
87868 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
87869 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
87870 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
87871 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
87872 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
87873 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
87874 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
87875 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
87876 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
87877 +split_11691 split 2 11691 NULL
87878 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
87879 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
87880 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
87881 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
87882 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
87883 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
87884 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
87885 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
87886 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
87887 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
87888 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
87889 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
87890 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
87891 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
87892 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
87893 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
87894 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
87895 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
87896 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
87897 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
87898 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
87899 +spidev_write_44510 spidev_write 3 44510 NULL
87900 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
87901 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
87902 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
87903 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
87904 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
87905 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
87906 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
87907 +kone_receive_4690 kone_receive 4 4690 NULL
87908 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
87909 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
87910 +evtchn_read_3569 evtchn_read 3 3569 NULL
87911 +video_read_28148 video_read 3 28148 NULL
87912 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
87913 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
87914 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
87915 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
87916 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
87917 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
87918 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
87919 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
87920 +vc_resize_3585 vc_resize 2-3 3585 NULL
87921 +gluebi_write_27905 gluebi_write 3 27905 NULL
87922 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
87923 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
87924 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
87925 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
87926 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
87927 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
87928 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
87929 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
87930 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
87931 +pti_char_write_60960 pti_char_write 3 60960 NULL
87932 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
87933 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
87934 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
87935 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
87936 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
87937 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
87938 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
87939 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
87940 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
87941 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
87942 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
87943 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
87944 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
87945 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
87946 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
87947 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
87948 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
87949 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
87950 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
87951 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
87952 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
87953 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
87954 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
87955 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
87956 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
87957 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
87958 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
87959 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
87960 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
87961 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
87962 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
87963 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
87964 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
87965 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
87966 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
87967 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
87968 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
87969 +symtab_init_61050 symtab_init 2 61050 NULL
87970 +team_options_register_20091 team_options_register 3 20091 NULL
87971 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
87972 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
87973 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
87974 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
87975 +mpi_resize_44674 mpi_resize 2 44674 NULL
87976 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
87977 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
87978 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
87979 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
87980 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
87981 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
87982 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
87983 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
87984 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
87985 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
87986 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
87987 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
87988 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87989 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
87990 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
87991 +pms_read_53873 pms_read 3 53873 NULL
87992 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
87993 +get_derived_key_61100 get_derived_key 4 61100 NULL
87994 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
87995 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
87996 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
87997 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
87998 +dm_read_15674 dm_read 3 15674 NULL
87999 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
88000 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
88001 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
88002 +kone_send_63435 kone_send 4 63435 NULL
88003 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
88004 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
88005 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
88006 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
88007 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
88008 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
88009 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
88010 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
88011 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
88012 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
88013 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
88014 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
88015 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
88016 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
88017 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
88018 +send_packet_52960 send_packet 4 52960 NULL
88019 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
88020 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
88021 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
88022 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
88023 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
88024 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
88025 +put_cmsg_36589 put_cmsg 4 36589 NULL
88026 +__vmalloc_61168 __vmalloc 1 61168 NULL
88027 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
88028 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
88029 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
88030 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
88031 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
88032 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
88033 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
88034 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
88035 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
88036 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
88037 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
88038 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
88039 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
88040 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
88041 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
88042 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
88043 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
88044 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
88045 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
88046 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
88047 +get_fd_set_3866 get_fd_set 1 3866 NULL
88048 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
88049 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
88050 +unlink_queued_645 unlink_queued 3-4 645 NULL
88051 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
88052 +sisusb_write_44834 sisusb_write 3 44834 NULL
88053 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
88054 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
88055 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
88056 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
88057 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
88058 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
88059 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
88060 +nvram_write_3894 nvram_write 3 3894 NULL
88061 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
88062 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
88063 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
88064 +vcs_write_3910 vcs_write 3 3910 NULL
88065 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
88066 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
88067 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
88068 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
88069 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
88070 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
88071 +do_tty_write_44896 do_tty_write 5 44896 NULL
88072 +set_powered_12129 set_powered 4 12129 NULL
88073 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
88074 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
88075 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
88076 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
88077 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
88078 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
88079 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
88080 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
88081 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
88082 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
88083 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
88084 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
88085 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
88086 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
88087 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
88088 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
88089 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
88090 +gather_array_56641 gather_array 3 56641 NULL
88091 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
88092 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
88093 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
88094 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
88095 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
88096 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
88097 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
88098 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
88099 +do_add_counters_3992 do_add_counters 3 3992 NULL
88100 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
88101 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
88102 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
88103 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
88104 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
88105 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
88106 +mei_write_4005 mei_write 3 4005 NULL
88107 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
88108 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
88109 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
88110 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
88111 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
88112 +receive_copy_12216 receive_copy 3 12216 NULL
88113 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
88114 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
88115 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
88116 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
88117 +change_xattr_61390 change_xattr 5 61390 NULL
88118 +find_skb_20431 find_skb 2 20431 NULL
88119 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
88120 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
88121 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
88122 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
88123 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
88124 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
88125 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
88126 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
88127 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
88128 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
88129 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
88130 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
88131 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
88132 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
88133 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
88134 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
88135 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
88136 +read_buf_20469 read_buf 2 20469 NULL
88137 +cm_write_36858 cm_write 3 36858 NULL
88138 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
88139 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
88140 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
88141 +sel_write_user_45060 sel_write_user 3 45060 NULL
88142 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
88143 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
88144 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
88145 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
88146 +fast_user_write_20494 fast_user_write 5 20494 NULL
88147 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
88148 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
88149 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
88150 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
88151 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
88152 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
88153 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
88154 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
88155 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
88156 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
88157 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
88158 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
88159 +osst_read_40237 osst_read 3 40237 NULL
88160 +tm6000_read_4151 tm6000_read 3 4151 NULL
88161 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
88162 +usbdev_read_45114 usbdev_read 3 45114 NULL
88163 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
88164 +spi_execute_28736 spi_execute 5 28736 NULL
88165 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
88166 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
88167 +get_alua_req_4166 get_alua_req 3 4166 NULL
88168 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
88169 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
88170 +venus_create_20555 venus_create 4 20555 NULL
88171 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
88172 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
88173 +receive_packet_12367 receive_packet 2 12367 NULL
88174 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
88175 +mem_write_22232 mem_write 3 22232 NULL
88176 +read_file_bool_4180 read_file_bool 3 4180 NULL
88177 +send_to_tty_45141 send_to_tty 3 45141 NULL
88178 +fops_read_40672 fops_read 3 40672 NULL
88179 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
88180 +write_leb_36957 write_leb 5 36957 NULL
88181 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
88182 +device_write_45156 device_write 3 45156 NULL
88183 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
88184 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
88185 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
88186 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
88187 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
88188 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
88189 +isp1760_register_628 isp1760_register 1-2 628 NULL
88190 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
88191 +lirc_write_20604 lirc_write 3 20604 NULL
88192 +sel_write_member_28800 sel_write_member 3 28800 NULL
88193 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
88194 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
88195 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
88196 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
88197 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
88198 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
88199 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
88200 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
88201 +setxattr_37006 setxattr 4 37006 NULL
88202 +add_child_45201 add_child 4 45201 NULL
88203 +seq_open_private_61589 seq_open_private 3 61589 NULL
88204 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
88205 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
88206 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
88207 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
88208 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
88209 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
88210 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
88211 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
88212 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
88213 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
88214 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
88215 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
88216 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
88217 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
88218 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
88219 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
88220 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
88221 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
88222 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
88223 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
88224 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
88225 +resize_stripes_61650 resize_stripes 2 61650 NULL
88226 +n2_run_53459 n2_run 3 53459 NULL
88227 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
88228 +parse_command_37079 parse_command 2 37079 NULL
88229 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
88230 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
88231 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
88232 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
88233 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
88234 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
88235 +insert_one_name_61668 insert_one_name 7 61668 NULL
88236 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
88237 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
88238 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
88239 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
88240 +lock_loop_61681 lock_loop 1 61681 NULL
88241 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
88242 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
88243 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
88244 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
88245 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
88246 +push_rx_28939 push_rx 3 28939 NULL
88247 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
88248 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
88249 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
88250 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
88251 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
88252 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
88253 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
88254 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
88255 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
88256 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
88257 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
88258 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
88259 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
88260 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
88261 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
88262 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
88263 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
88264 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
88265 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
88266 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
88267 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
88268 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
88269 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
88270 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
88271 +bin_uuid_28999 bin_uuid 3 28999 NULL
88272 +sys_sendto_20809 sys_sendto 6 20809 NULL
88273 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
88274 +set_registers_53582 set_registers 3 53582 NULL
88275 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
88276 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
88277 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
88278 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
88279 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
88280 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
88281 +keymap_store_45406 keymap_store 4 45406 NULL
88282 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
88283 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
88284 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
88285 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
88286 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
88287 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
88288 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
88289 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
88290 +__do_replace_37227 __do_replace 5 37227 NULL
88291 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
88292 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
88293 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
88294 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
88295 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
88296 +tso_fragment_29050 tso_fragment 3 29050 NULL
88297 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
88298 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
88299 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
88300 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
88301 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
88302 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
88303 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
88304 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
88305 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
88306 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
88307 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
88308 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
88309 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
88310 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
88311 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
88312 +set_link_security_4502 set_link_security 4 4502 NULL
88313 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
88314 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
88315 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
88316 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
88317 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
88318 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
88319 +mmio_read_40348 mmio_read 4 40348 NULL
88320 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
88321 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
88322 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
88323 +ivtv_write_12721 ivtv_write 3 12721 NULL
88324 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
88325 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
88326 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
88327 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
88328 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
88329 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
88330 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
88331 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
88332 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
88333 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
88334 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
88335 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
88336 +send_msg_37323 send_msg 4 37323 NULL
88337 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
88338 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
88339 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
88340 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
88341 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
88342 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
88343 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
88344 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
88345 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
88346 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
88347 +reshape_ring_29147 reshape_ring 2 29147 NULL
88348 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
88349 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
88350 +copy_macs_45534 copy_macs 4 45534 NULL
88351 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
88352 +listxattr_12769 listxattr 3 12769 NULL
88353 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
88354 +wdm_write_53735 wdm_write 3 53735 NULL
88355 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
88356 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
88357 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
88358 +mempool_create_29437 mempool_create 1 29437 NULL
88359 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
88360 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
88361 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
88362 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
88363 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
88364 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
88365 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
88366 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
88367 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
88368 +mgmt_event_12810 mgmt_event 4 12810 NULL
88369 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
88370 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
88371 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
88372 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
88373 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
88374 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
88375 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
88376 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
88377 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
88378 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
88379 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
88380 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
88381 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
88382 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
88383 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
88384 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
88385 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
88386 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
88387 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
88388 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
88389 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
88390 +recover_peb_29238 recover_peb 6-7 29238 NULL
88391 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
88392 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
88393 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
88394 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
88395 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
88396 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
88397 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
88398 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
88399 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
88400 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
88401 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
88402 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
88403 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
88404 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
88405 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
88406 +do_pselect_62061 do_pselect 1 62061 NULL
88407 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
88408 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
88409 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
88410 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
88411 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
88412 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
88413 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
88414 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
88415 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
88416 +sg_read_25799 sg_read 3 25799 NULL
88417 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
88418 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
88419 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
88420 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
88421 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
88422 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
88423 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
88424 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
88425 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
88426 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
88427 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
88428 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
88429 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
88430 +new_skb_21148 new_skb 1 21148 NULL
88431 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
88432 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
88433 +bm_status_write_12964 bm_status_write 3 12964 NULL
88434 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
88435 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
88436 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
88437 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
88438 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
88439 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
88440 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
88441 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
88442 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
88443 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
88444 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
88445 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
88446 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
88447 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
88448 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
88449 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
88450 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
88451 +video_usercopy_62151 video_usercopy 2 62151 NULL
88452 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
88453 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
88454 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
88455 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
88456 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
88457 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
88458 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
88459 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
88460 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
88461 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
88462 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
88463 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
88464 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
88465 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
88466 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
88467 +input_ff_create_21240 input_ff_create 2 21240 NULL
88468 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
88469 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
88470 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
88471 +amthi_read_45831 amthi_read 4 45831 NULL
88472 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
88473 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
88474 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
88475 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
88476 +sys_ipc_4889 sys_ipc 3 4889 NULL
88477 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
88478 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
88479 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
88480 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
88481 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
88482 +do_register_entry_29478 do_register_entry 4 29478 NULL
88483 +isdn_write_45863 isdn_write 3 45863 NULL
88484 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
88485 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
88486 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
88487 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
88488 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
88489 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
88490 +_malloc_54077 _malloc 1 54077 NULL
88491 +add_res_range_21310 add_res_range 4 21310 NULL
88492 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
88493 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
88494 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
88495 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
88496 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
88497 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
88498 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
88499 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
88500 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
88501 +create_xattr_54106 create_xattr 5 54106 NULL
88502 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
88503 +ep_write_59008 ep_write 3 59008 NULL
88504 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
88505 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
88506 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
88507 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
88508 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
88509 +alloc_mr_45935 alloc_mr 1 45935 NULL
88510 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
88511 +isku_receive_54130 isku_receive 4 54130 NULL
88512 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
88513 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
88514 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
88515 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
88516 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
88517 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
88518 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
88519 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
88520 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
88521 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
88522 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
88523 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
88524 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
88525 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
88526 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
88527 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
88528 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
88529 +comedi_read_13199 comedi_read 3 13199 NULL
88530 +flash_write_62354 flash_write 3 62354 NULL
88531 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
88532 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
88533 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
88534 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
88535 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
88536 +proc_file_read_53905 proc_file_read 3 53905 NULL
88537 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
88538 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
88539 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
88540 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
88541 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
88542 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
88543 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
88544 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
88545 +cru_detect_11272 cru_detect 1 11272 NULL
88546 +altera_irscan_62396 altera_irscan 2 62396 NULL
88547 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
88548 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
88549 +fw_download_code_13249 fw_download_code 3 13249 NULL
88550 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
88551 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
88552 +set_ssp_62411 set_ssp 4 62411 NULL
88553 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
88554 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
88555 +get_free_entries_46030 get_free_entries 1 46030 NULL
88556 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
88557 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
88558 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
88559 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
88560 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
88561 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
88562 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
88563 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
88564 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
88565 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
88566 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
88567 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
88568 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
88569 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
88570 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
88571 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
88572 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
88573 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
88574 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
88575 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
88576 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
88577 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
88578 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
88579 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
88580 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
88581 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
88582 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
88583 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
88584 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
88585 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
88586 +probes_write_29711 probes_write 3 29711 NULL
88587 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
88588 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
88589 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
88590 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
88591 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
88592 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
88593 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
88594 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
88595 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
88596 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
88597 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
88598 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
88599 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
88600 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
88601 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
88602 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
88603 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
88604 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
88605 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
88606 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
88607 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
88608 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
88609 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
88610 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
88611 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
88612 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
88613 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
88614 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
88615 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
88616 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
88617 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
88618 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
88619 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
88620 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
88621 +isdn_read_50021 isdn_read 3 50021 NULL
88622 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
88623 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
88624 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
88625 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
88626 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
88627 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
88628 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
88629 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
88630 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
88631 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
88632 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
88633 +get_subdir_62581 get_subdir 3 62581 NULL
88634 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
88635 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
88636 +vfs_readv_38011 vfs_readv 3 38011 NULL
88637 +keyring_read_13438 keyring_read 3 13438 NULL
88638 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
88639 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
88640 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
88641 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
88642 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
88643 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
88644 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
88645 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
88646 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
88647 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
88648 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
88649 +ftrace_write_29551 ftrace_write 3 29551 NULL
88650 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
88651 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
88652 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
88653 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
88654 +dev_write_7708 dev_write 3 7708 NULL
88655 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
88656 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
88657 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
88658 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
88659 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
88660 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
88661 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
88662 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
88663 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
88664 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
88665 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
88666 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
88667 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
88668 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
88669 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
88670 +bm_init_13529 bm_init 2 13529 NULL
88671 +check586_29914 check586 2 29914 NULL
88672 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
88673 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
88674 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
88675 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
88676 +pg_read_17276 pg_read 3 17276 NULL
88677 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
88678 +ep0_read_38095 ep0_read 3 38095 NULL
88679 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
88680 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
88681 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
88682 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
88683 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
88684 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
88685 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
88686 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
88687 +l2down_create_21755 l2down_create 4 21755 NULL
88688 +alloc_tio_13564 alloc_tio 3 13564 NULL
88689 +viacam_read_54526 viacam_read 3 54526 NULL
88690 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
88691 +tunables_read_36385 tunables_read 3 36385 NULL
88692 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
88693 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
88694 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
88695 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
88696 +setsockopt_54539 setsockopt 5 54539 NULL
88697 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
88698 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
88699 +tty_register_device_4544 tty_register_device 2 4544 NULL
88700 +cache_write_13589 cache_write 3 13589 NULL
88701 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
88702 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
88703 +key_replays_read_62746 key_replays_read 3 62746 NULL
88704 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
88705 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
88706 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
88707 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
88708 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
88709 +cdev_add_38176 cdev_add 2-3 38176 NULL
88710 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
88711 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
88712 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
88713 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
88714 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
88715 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
88716 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
88717 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
88718 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
88719 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
88720 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
88721 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
88722 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
88723 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
88724 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
88725 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
88726 +packet_snd_13634 packet_snd 3 13634 NULL
88727 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
88728 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
88729 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
88730 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
88731 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
88732 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
88733 +drp_wmove_30043 drp_wmove 4 30043 NULL
88734 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
88735 +cache_downcall_13666 cache_downcall 3 13666 NULL
88736 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
88737 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
88738 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
88739 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
88740 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
88741 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
88742 +tty_write_5494 tty_write 3 5494 NULL
88743 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
88744 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
88745 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
88746 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
88747 +teiup_create_43201 teiup_create 3 43201 NULL
88748 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
88749 +filldir64_46469 filldir64 3 46469 NULL
88750 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
88751 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
88752 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
88753 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
88754 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
88755 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
88756 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
88757 +spidev_message_5518 spidev_message 3 5518 NULL
88758 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
88759 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
88760 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
88761 +evm_read_key_54674 evm_read_key 3 54674 NULL
88762 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
88763 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
88764 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
88765 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
88766 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
88767 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
88768 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
88769 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
88770 +u32_array_read_2219 u32_array_read 3 2219 NULL
88771 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
88772 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
88773 +sys_add_key_61288 sys_add_key 4 61288 NULL
88774 +kmsg_read_46514 kmsg_read 3 46514 NULL
88775 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
88776 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
88777 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
88778 +recv_stream_30138 recv_stream 4 30138 NULL
88779 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
88780 +getdqbuf_62908 getdqbuf 1 62908 NULL
88781 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
88782 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
88783 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
88784 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
88785 +fir16_create_5574 fir16_create 3 5574 NULL
88786 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
88787 +pt_write_40159 pt_write 3 40159 NULL
88788 +bioset_create_5580 bioset_create 1 5580 NULL
88789 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
88790 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
88791 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
88792 +kzalloc_54740 kzalloc 1 54740 NULL
88793 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
88794 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
88795 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
88796 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
88797 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
88798 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
88799 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
88800 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
88801 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
88802 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
88803 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
88804 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
88805 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
88806 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
88807 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
88808 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
88809 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
88810 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
88811 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
88812 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
88813 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
88814 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
88815 +ti_recv_22027 ti_recv 4 22027 NULL
88816 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
88817 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
88818 +nfsd_write_54809 nfsd_write 6 54809 NULL
88819 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
88820 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
88821 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
88822 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
88823 +get_skb_63008 get_skb 2 63008 NULL
88824 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
88825 +netlink_send_38434 netlink_send 5 38434 NULL
88826 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
88827 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
88828 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
88829 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
88830 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
88831 +write_rio_54837 write_rio 3 54837 NULL
88832 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
88833 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
88834 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
88835 +get_arg_5694 get_arg 3 5694 NULL
88836 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
88837 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
88838 +compat_readv_30273 compat_readv 3 30273 NULL
88839 +printer_read_54851 printer_read 3 54851 NULL
88840 +mem_rw_22085 mem_rw 3 22085 NULL
88841 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
88842 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
88843 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
88844 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
88845 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
88846 +unlink1_63059 unlink1 3 63059 NULL
88847 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
88848 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
88849 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
88850 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
88851 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
88852 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
88853 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
88854 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
88855 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
88856 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
88857 +dev_names_read_38509 dev_names_read 3 38509 NULL
88858 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
88859 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
88860 +get_packet_5747 get_packet 3 5747 NULL
88861 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
88862 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
88863 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
88864 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
88865 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
88866 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
88867 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
88868 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
88869 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
88870 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
88871 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
88872 +resource_from_user_30341 resource_from_user 3 30341 NULL
88873 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
88874 +sound_write_5102 sound_write 3 5102 NULL
88875 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
88876 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
88877 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
88878 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
88879 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
88880 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
88881 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
88882 +com90xx_found_13974 com90xx_found 3 13974 NULL
88883 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
88884 +qcam_read_13977 qcam_read 3 13977 NULL
88885 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
88886 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
88887 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
88888 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
88889 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
88890 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
88891 +generic_readlink_32654 generic_readlink 3 32654 NULL
88892 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
88893 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
88894 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
88895 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
88896 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
88897 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
88898 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
88899 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
88900 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
88901 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
88902 +concat_writev_21451 concat_writev 3 21451 NULL
88903 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
88904 +_queue_data_54983 _queue_data 4 54983 NULL
88905 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
88906 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
88907 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
88908 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
88909 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
88910 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
88911 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
88912 +setup_req_5848 setup_req 3 5848 NULL
88913 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
88914 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
88915 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
88916 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
88917 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
88918 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
88919 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
88920 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
88921 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
88922 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
88923 +cma_create_area_38642 cma_create_area 2 38642 NULL
88924 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
88925 +sriov_enable_59689 sriov_enable 2 59689 NULL
88926 +enable_write_30456 enable_write 3 30456 NULL
88927 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
88928 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
88929 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
88930 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
88931 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
88932 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
88933 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
88934 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
88935 +port_show_regs_5904 port_show_regs 3 5904 NULL
88936 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
88937 +ptp_read_63251 ptp_read 4 63251 NULL
88938 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
88939 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
88940 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
88941 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
88942 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
88943 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
88944 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
88945 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
88946 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
88947 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
88948 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
88949 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
88950 +read_dma_55086 read_dma 3 55086 NULL
88951 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
88952 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
88953 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
88954 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
88955 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
88956 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
88957 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
88958 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
88959 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
88960 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
88961 +em_canid_change_14150 em_canid_change 3 14150 NULL
88962 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
88963 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
88964 +fb_write_46924 fb_write 3 46924 NULL
88965 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
88966 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
88967 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
88968 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
88969 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
88970 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
88971 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
88972 +udf_readpages_38761 udf_readpages 4 38761 NULL
88973 +reada_add_block_54247 reada_add_block 2 54247 NULL
88974 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
88975 +proc_info_read_63344 proc_info_read 3 63344 NULL
88976 +pep_indicate_38611 pep_indicate 5 38611 NULL
88977 +set_le_30581 set_le 4 30581 NULL
88978 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
88979 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
88980 +alloc_private_22399 alloc_private 2 22399 NULL
88981 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
88982 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
88983 +zoran_write_22404 zoran_write 3 22404 NULL
88984 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
88985 +idmouse_read_63374 idmouse_read 3 63374 NULL
88986 +queue_reply_22416 queue_reply 3 22416 NULL
88987 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
88988 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
88989 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
88990 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
88991 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
88992 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
88993 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
88994 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
88995 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
88996 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
88997 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
88998 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
88999 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
89000 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
89001 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
89002 +sys_select_38827 sys_select 1 38827 NULL
89003 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
89004 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
89005 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
89006 +direct_entry_38836 direct_entry 3 38836 NULL
89007 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
89008 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
89009 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
89010 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
89011 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
89012 +write_head_30481 write_head 4 30481 NULL
89013 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
89014 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
89015 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
89016 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
89017 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
89018 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
89019 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
89020 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
89021 +agp_remap_30665 agp_remap 2 30665 NULL
89022 +interfaces_38859 interfaces 2 38859 NULL
89023 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
89024 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
89025 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
89026 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
89027 +qc_capture_19298 qc_capture 3 19298 NULL
89028 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
89029 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
89030 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
89031 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
89032 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
89033 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
89034 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
89035 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
89036 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
89037 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
89038 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
89039 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
89040 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
89041 +read_kcore_63488 read_kcore 3 63488 NULL
89042 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
89043 +__skb_cow_39254 __skb_cow 2 39254 NULL
89044 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
89045 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
89046 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
89047 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
89048 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
89049 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
89050 +mousedev_read_47123 mousedev_read 3 47123 NULL
89051 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
89052 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
89053 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
89054 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
89055 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
89056 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
89057 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
89058 +vme_user_read_55338 vme_user_read 3 55338 NULL
89059 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
89060 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
89061 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
89062 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
89063 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
89064 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
89065 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
89066 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
89067 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
89068 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
89069 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
89070 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
89071 +snapshot_read_22601 snapshot_read 3 22601 NULL
89072 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
89073 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
89074 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
89075 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
89076 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
89077 +__send_to_port_55383 __send_to_port 3 55383 NULL
89078 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
89079 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
89080 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
89081 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
89082 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
89083 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
89084 +get_nodes_39012 get_nodes 3 39012 NULL
89085 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
89086 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
89087 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
89088 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
89089 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
89090 +create_subvol_30836 create_subvol 4 30836 NULL
89091 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
89092 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
89093 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
89094 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
89095 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
89096 +read_oldmem_55658 read_oldmem 3 55658 NULL
89097 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
89098 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
89099 +options_write_47243 options_write 3 47243 NULL
89100 +module_alloc_63630 module_alloc 1 63630 NULL
89101 +alloc_skb_55439 alloc_skb 1 55439 NULL
89102 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
89103 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
89104 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
89105 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
89106 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
89107 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
89108 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
89109 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
89110 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
89111 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
89112 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
89113 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
89114 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
89115 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
89116 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
89117 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
89118 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
89119 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
89120 +vbi_read_63673 vbi_read 3 63673 NULL
89121 +tun_get_user_39099 tun_get_user 4 39099 NULL
89122 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
89123 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
89124 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
89125 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
89126 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
89127 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
89128 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
89129 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
89130 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
89131 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
89132 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
89133 +ax25_output_22736 ax25_output 2 22736 NULL
89134 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
89135 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
89136 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
89137 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
89138 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
89139 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
89140 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
89141 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
89142 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
89143 +hid_input_report_32458 hid_input_report 4 32458 NULL
89144 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
89145 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
89146 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
89147 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
89148 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
89149 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
89150 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
89151 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
89152 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
89153 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
89154 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
89155 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
89156 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
89157 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
89158 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
89159 +get_info_55681 get_info 3 55681 NULL
89160 +setkey_14987 setkey 3 14987 NULL
89161 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
89162 +init_list_set_39188 init_list_set 2-3 39188 NULL
89163 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
89164 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
89165 +l2up_create_6430 l2up_create 3 6430 NULL
89166 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
89167 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
89168 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
89169 +add_partition_55588 add_partition 2 55588 NULL
89170 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
89171 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
89172 +depth_read_31112 depth_read 3 31112 NULL
89173 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
89174 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
89175 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
89176 +profile_replace_14652 profile_replace 3 14652 NULL
89177 +vzalloc_47421 vzalloc 1 47421 NULL
89178 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
89179 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
89180 +sys_writev_28384 sys_writev 3 28384 NULL
89181 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
89182 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
89183 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
89184 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
89185 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
89186 +create_attr_set_22861 create_attr_set 1 22861 NULL
89187 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
89188 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
89189 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
89190 +sel_write_load_63830 sel_write_load 3 63830 NULL
89191 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
89192 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
89193 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
89194 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
89195 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
89196 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
89197 +probe_bios_17467 probe_bios 1 17467 NULL
89198 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
89199 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
89200 +mei_read_6507 mei_read 3 6507 NULL
89201 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
89202 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
89203 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
89204 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
89205 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
89206 +SetArea_50835 SetArea 4 50835 NULL
89207 +tpm_read_50344 tpm_read 3 50344 NULL
89208 +newpart_47485 newpart 6 47485 NULL
89209 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
89210 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
89211 +core_sys_select_47494 core_sys_select 1 47494 NULL
89212 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
89213 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
89214 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
89215 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
89216 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
89217 +unlink_simple_47506 unlink_simple 3 47506 NULL
89218 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
89219 +wdm_read_6549 wdm_read 3 6549 NULL
89220 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
89221 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
89222 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
89223 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
89224 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
89225 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
89226 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
89227 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
89228 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
89229 +filter_read_61692 filter_read 3 61692 NULL
89230 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
89231 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
89232 +debugfs_read_62535 debugfs_read 3 62535 NULL
89233 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
89234 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
89235 +divas_write_63901 divas_write 3 63901 NULL
89236 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
89237 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
89238 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
89239 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
89240 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
89241 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
89242 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
89243 +ipw_write_59807 ipw_write 3 59807 NULL
89244 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
89245 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
89246 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
89247 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
89248 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
89249 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
89250 +cycx_setup_47562 cycx_setup 4 47562 NULL
89251 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
89252 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
89253 +set_local_name_55757 set_local_name 4 55757 NULL
89254 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
89255 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
89256 +read_ldt_47570 read_ldt 2 47570 NULL
89257 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
89258 +pci_iomap_47575 pci_iomap 3 47575 NULL
89259 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
89260 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
89261 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
89262 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
89263 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
89264 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
89265 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
89266 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
89267 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
89268 +conf_read_55786 conf_read 3 55786 NULL
89269 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
89270 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
89271 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
89272 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
89273 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
89274 +user_power_read_39414 user_power_read 3 39414 NULL
89275 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
89276 +uea_request_47613 uea_request 4 47613 NULL
89277 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
89278 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
89279 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
89280 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
89281 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
89282 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
89283 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
89284 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
89285 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
89286 +kmemdup_64015 kmemdup 2 64015 NULL
89287 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
89288 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
89289 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
89290 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
89291 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
89292 +oz_events_read_47535 oz_events_read 3 47535 NULL
89293 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
89294 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
89295 +sys_semop_39457 sys_semop 3 39457 NULL
89296 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
89297 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
89298 +update_pmkid_2481 update_pmkid 4 2481 NULL
89299 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
89300 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
89301 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
89302 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
89303 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
89304 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
89305 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
89306 +mpeg_read_6708 mpeg_read 3 6708 NULL
89307 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
89308 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
89309 +sky2_receive_13407 sky2_receive 2 13407 NULL
89310 +krealloc_14908 krealloc 2 14908 NULL
89311 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
89312 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
89313 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
89314 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
89315 +video_proc_write_6724 video_proc_write 3 6724 NULL
89316 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
89317 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
89318 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
89319 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
89320 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
89321 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
89322 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
89323 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
89324 +command_file_write_31318 command_file_write 3 31318 NULL
89325 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
89326 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
89327 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
89328 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
89329 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
89330 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
89331 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
89332 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
89333 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
89334 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
89335 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
89336 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
89337 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
89338 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
89339 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
89340 +int_proc_write_39542 int_proc_write 3 39542 NULL
89341 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
89342 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
89343 +read_file_ani_23161 read_file_ani 3 23161 NULL
89344 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
89345 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
89346 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
89347 +pp_write_39554 pp_write 3 39554 NULL
89348 +ioremap_23172 ioremap 1-2 23172 NULL
89349 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
89350 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
89351 +usblp_write_23178 usblp_write 3 23178 NULL
89352 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
89353 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
89354 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
89355 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
89356 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
89357 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
89358 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
89359 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
89360 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
89361 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
89362 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
89363 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
89364 +__team_options_register_63941 __team_options_register 3 63941 NULL
89365 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
89366 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
89367 +rvmalloc_46873 rvmalloc 1 46873 NULL
89368 +vmap_15025 vmap 2 15025 NULL
89369 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
89370 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
89371 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
89372 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
89373 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
89374 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
89375 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
89376 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
89377 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
89378 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
89379 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
89380 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
89381 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
89382 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
89383 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
89384 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
89385 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
89386 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
89387 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
89388 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
89389 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
89390 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
89391 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
89392 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
89393 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
89394 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
89395 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
89396 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
89397 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
89398 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
89399 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
89400 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
89401 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
89402 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
89403 +alg_setkey_31485 alg_setkey 3 31485 NULL
89404 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
89405 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
89406 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
89407 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
89408 +vhci_read_47878 vhci_read 3 47878 NULL
89409 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
89410 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
89411 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
89412 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
89413 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
89414 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
89415 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
89416 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
89417 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
89418 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
89419 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
89420 +timeout_read_47915 timeout_read 3 47915 NULL
89421 +hidraw_write_31536 hidraw_write 3 31536 NULL
89422 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
89423 +page_readlink_23346 page_readlink 3 23346 NULL
89424 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
89425 +comedi_write_47926 comedi_write 3 47926 NULL
89426 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
89427 +dsp_write_46218 dsp_write 2 46218 NULL
89428 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
89429 +usbvision_read_31555 usbvision_read 3 31555 NULL
89430 +pd_video_read_24510 pd_video_read 3 24510 NULL
89431 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
89432 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
89433 +request_key_async_6990 request_key_async 4 6990 NULL
89434 +ts_write_64336 ts_write 3 64336 NULL
89435 +handle_response_55951 handle_response 5 55951 NULL
89436 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
89437 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
89438 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
89439 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
89440 +osst_write_31581 osst_write 3 31581 NULL
89441 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
89442 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
89443 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
89444 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
89445 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
89446 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
89447 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
89448 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
89449 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
89450 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
89451 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
89452 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
89453 +ilo_write_64378 ilo_write 3 64378 NULL
89454 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
89455 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
89456 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
89457 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
89458 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
89459 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
89460 +copy_from_user_17559 copy_from_user 3 17559 NULL
89461 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
89462 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
89463 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
89464 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
89465 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
89466 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
89467 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
89468 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
89469 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
89470 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
89471 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
89472 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
89473 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
89474 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
89475 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
89476 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
89477 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
89478 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
89479 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
89480 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
89481 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
89482 +__lgread_31668 __lgread 4 31668 NULL
89483 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
89484 +fd_copyin_56247 fd_copyin 3 56247 NULL
89485 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
89486 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
89487 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
89488 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
89489 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
89490 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
89491 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
89492 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
89493 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
89494 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
89495 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
89496 +event_filter_read_23494 event_filter_read 3 23494 NULL
89497 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
89498 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
89499 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
89500 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
89501 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
89502 +pkt_add_39897 pkt_add 3 39897 NULL
89503 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
89504 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
89505 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
89506 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
89507 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
89508 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
89509 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
89510 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
89511 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
89512 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
89513 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
89514 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
89515 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
89516 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
89517 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
89518 +remove_uuid_64505 remove_uuid 4 64505 NULL
89519 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
89520 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
89521 +create_table_16213 create_table 2 16213 NULL
89522 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
89523 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
89524 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
89525 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
89526 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
89527 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
89528 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
89529 +set_discoverable_48141 set_discoverable 4 48141 NULL
89530 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
89531 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
89532 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
89533 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
89534 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
89535 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
89536 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
89537 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
89538 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
89539 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
89540 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
89541 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
89542 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
89543 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
89544 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
89545 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
89546 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
89547 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
89548 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
89549 +dev_read_56369 dev_read 3 56369 NULL
89550 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
89551 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
89552 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
89553 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
89554 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
89555 +init_ipath_48187 init_ipath 1 48187 NULL
89556 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
89557 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
89558 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
89559 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
89560 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
89561 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
89562 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
89563 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
89564 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
89565 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
89566 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
89567 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
89568 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
89569 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
89570 +use_pool_64607 use_pool 2 64607 NULL
89571 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
89572 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
89573 +store_msg_56417 store_msg 3 56417 NULL
89574 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
89575 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
89576 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
89577 +read_file_recv_48232 read_file_recv 3 48232 NULL
89578 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
89579 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
89580 +fanotify_write_64623 fanotify_write 3 64623 NULL
89581 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
89582 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
89583 +fl_create_56435 fl_create 5 56435 NULL
89584 +gnttab_map_56439 gnttab_map 2 56439 NULL
89585 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
89586 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
89587 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
89588 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
89589 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
89590 +set_connectable_56458 set_connectable 4 56458 NULL
89591 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
89592 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
89593 +add_port_54941 add_port 2 54941 NULL
89594 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
89595 +cx18_read_23699 cx18_read 3 23699 NULL
89596 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
89597 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
89598 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
89599 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
89600 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
89601 +send_set_info_48288 send_set_info 7 48288 NULL
89602 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
89603 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
89604 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
89605 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
89606 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
89607 +new_dir_31919 new_dir 3 31919 NULL
89608 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
89609 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
89610 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
89611 +mgmt_control_7349 mgmt_control 3 7349 NULL
89612 +hash_setkey_48310 hash_setkey 3 48310 NULL
89613 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
89614 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
89615 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
89616 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
89617 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
89618 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
89619 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
89620 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
89621 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
89622 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
89623 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
89624 +vb2_write_31948 vb2_write 3 31948 NULL
89625 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
89626 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
89627 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
89628 +ip_options_get_56538 ip_options_get 4 56538 NULL
89629 +write_62671 write 3 62671 NULL
89630 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
89631 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
89632 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
89633 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
89634 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
89635 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
89636 +skb_add_data_48363 skb_add_data 3 48363 NULL
89637 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
89638 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
89639 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
89640 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
89641 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
89642 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
89643 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
89644 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
89645 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
89646 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
89647 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
89648 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
89649 +system_enable_read_25815 system_enable_read 3 25815 NULL
89650 +allocate_probes_40204 allocate_probes 1 40204 NULL
89651 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
89652 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
89653 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
89654 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
89655 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
89656 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
89657 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
89658 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
89659 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
89660 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
89661 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
89662 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
89663 +fs_path_add_15648 fs_path_add 3 15648 NULL
89664 +event_filter_write_56609 event_filter_write 3 56609 NULL
89665 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
89666 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
89667 +xsd_read_15653 xsd_read 3 15653 NULL
89668 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
89669 +p54_init_common_23850 p54_init_common 1 23850 NULL
89670 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
89671 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
89672 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
89673 +garp_request_join_7471 garp_request_join 4 7471 NULL
89674 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
89675 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
89676 +unifi_read_14899 unifi_read 3 14899 NULL
89677 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
89678 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
89679 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
89680 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
89681 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
89682 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
89683 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
89684 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
89685 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
89686 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
89687 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
89688 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
89689 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
89690 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
89691 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
89692 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
89693 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
89694 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
89695 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
89696 +bio_alloc_32095 bio_alloc 2 32095 NULL
89697 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
89698 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
89699 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
89700 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
89701 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
89702 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
89703 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
89704 +send_control_msg_48498 send_control_msg 6 48498 NULL
89705 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
89706 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
89707 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
89708 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
89709 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
89710 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
89711 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
89712 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
89713 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
89714 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
89715 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
89716 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
89717 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
89718 +alloc_tx_32143 alloc_tx 2 32143 NULL
89719 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
89720 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
89721 +hsc_write_55875 hsc_write 3 55875 NULL
89722 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
89723 +do_test_15766 do_test 1 15766 NULL
89724 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
89725 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
89726 +named_distribute_48544 named_distribute 4 48544 NULL
89727 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
89728 +venus_link_32165 venus_link 5 32165 NULL
89729 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
89730 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
89731 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
89732 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
89733 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
89734 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
89735 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
89736 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
89737 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
89738 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
89739 +groups_alloc_7614 groups_alloc 1 7614 NULL
89740 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
89741 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
89742 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
89743 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
89744 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
89745 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
89746 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
89747 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
89748 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
89749 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
89750 +snapshot_write_28351 snapshot_write 3 28351 NULL
89751 +event_enable_read_7074 event_enable_read 3 7074 NULL
89752 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
89753 +do_syslog_56807 do_syslog 3 56807 NULL
89754 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
89755 +pskb_pull_65005 pskb_pull 2 65005 NULL
89756 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
89757 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
89758 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
89759 +unifi_write_65012 unifi_write 3 65012 NULL
89760 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
89761 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
89762 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
89763 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
89764 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
89765 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
89766 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
89767 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
89768 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
89769 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
89770 +if_write_51756 if_write 3 51756 NULL
89771 +insert_dent_65034 insert_dent 7 65034 NULL
89772 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
89773 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
89774 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
89775 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
89776 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
89777 +lc_create_48662 lc_create 3 48662 NULL
89778 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
89779 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
89780 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
89781 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
89782 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
89783 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
89784 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
89785 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
89786 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
89787 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
89788 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
89789 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
89790 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
89791 +altera_drscan_48698 altera_drscan 2 48698 NULL
89792 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
89793 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
89794 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
89795 +power_read_15939 power_read 3 15939 NULL
89796 +recv_msg_48709 recv_msg 4 48709 NULL
89797 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
89798 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
89799 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
89800 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
89801 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
89802 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
89803 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
89804 +revalidate_19043 revalidate 2 19043 NULL
89805 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
89806 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
89807 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
89808 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
89809 +check_header_56930 check_header 2 56930 NULL
89810 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
89811 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
89812 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
89813 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
89814 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
89815 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
89816 +frame_alloc_15981 frame_alloc 4 15981 NULL
89817 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
89818 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
89819 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
89820 +adu_read_24177 adu_read 3 24177 NULL
89821 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
89822 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
89823 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
89824 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
89825 +vfd_write_14717 vfd_write 3 14717 NULL
89826 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
89827 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
89828 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
89829 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
89830 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
89831 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
89832 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
89833 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
89834 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
89835 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
89836 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
89837 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
89838 +register_device_60015 register_device 2-3 60015 NULL
89839 +got_frame_16028 got_frame 2 16028 NULL
89840 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
89841 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
89842 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
89843 +scsi_register_49094 scsi_register 2 49094 NULL
89844 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
89845 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
89846 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
89847 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
89848 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
89849 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
89850 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
89851 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
89852 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
89853 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
89854 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
89855 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
89856 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
89857 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
89858 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
89859 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
89860 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
89861 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
89862 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
89863 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
89864 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
89865 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
89866 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
89867 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
89868 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
89869 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
89870 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
89871 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
89872 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
89873 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
89874 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
89875 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
89876 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
89877 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
89878 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
89879 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
89880 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
89881 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
89882 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
89883 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
89884 +fsm_init_16134 fsm_init 2 16134 NULL
89885 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
89886 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
89887 +disconnect_32521 disconnect 4 32521 NULL
89888 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
89889 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
89890 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
89891 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
89892 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
89893 +ilo_read_32531 ilo_read 3 32531 NULL
89894 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
89895 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
89896 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
89897 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
89898 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
89899 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
89900 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
89901 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
89902 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
89903 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
89904 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
89905 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
89906 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
89907 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
89908 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
89909 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
89910 +card_send_command_40757 card_send_command 3 40757 NULL
89911 +sys_mbind_7990 sys_mbind 5 7990 NULL
89912 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
89913 +pg_write_40766 pg_write 3 40766 NULL
89914 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
89915 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
89916 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
89917 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
89918 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
89919 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
89920 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
89921 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
89922 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
89923 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
89924 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
89925 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
89926 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
89927 +vcs_read_8017 vcs_read 3 8017 NULL
89928 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
89929 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
89930 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
89931 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
89932 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
89933 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
89934 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
89935 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
89936 +copy_and_check_19089 copy_and_check 3 19089 NULL
89937 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
89938 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
89939 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
89940 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
89941 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
89942 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
89943 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
89944 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
89945 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
89946 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
89947 +smk_user_access_24440 smk_user_access 3 24440 NULL
89948 +xd_rw_49020 xd_rw 3-4 49020 NULL
89949 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
89950 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
89951 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
89952 +kvmalloc_32646 kvmalloc 1 32646 NULL
89953 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
89954 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
89955 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
89956 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
89957 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
89958 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
89959 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
89960 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
89961 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
89962 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
89963 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
89964 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
89965 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
89966 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
89967 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
89968 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
89969 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
89970 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
89971 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
89972 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
89973 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
89974 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
89975 +venus_lookup_8121 venus_lookup 4 8121 NULL
89976 +compat_writev_60063 compat_writev 3 60063 NULL
89977 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
89978 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
89979 +read_file_queue_40895 read_file_queue 3 40895 NULL
89980 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
89981 +waiters_read_40902 waiters_read 3 40902 NULL
89982 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
89983 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
89984 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
89985 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
89986 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
89987 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
89988 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
89989 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
89990 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
89991 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
89992 +alloc_dr_65495 alloc_dr 2 65495 NULL
89993 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
89994 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
89995 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
89996 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
89997 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
89998 +rbd_add_16366 rbd_add 3 16366 NULL
89999 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
90000 +pt_read_49136 pt_read 3 49136 NULL
90001 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
90002 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
90003 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
90004 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
90005 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
90006 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
90007 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
90008 new file mode 100644
90009 index 0000000..d52f2ee
90010 --- /dev/null
90011 +++ b/tools/gcc/size_overflow_plugin.c
90012 @@ -0,0 +1,1941 @@
90013 +/*
90014 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
90015 + * Licensed under the GPL v2, or (at your option) v3
90016 + *
90017 + * Homepage:
90018 + * http://www.grsecurity.net/~ephox/overflow_plugin/
90019 + *
90020 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
90021 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
90022 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
90023 + *
90024 + * Usage:
90025 + * $ 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
90026 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
90027 + */
90028 +
90029 +#include "gcc-plugin.h"
90030 +#include "config.h"
90031 +#include "system.h"
90032 +#include "coretypes.h"
90033 +#include "tree.h"
90034 +#include "tree-pass.h"
90035 +#include "intl.h"
90036 +#include "plugin-version.h"
90037 +#include "tm.h"
90038 +#include "toplev.h"
90039 +#include "function.h"
90040 +#include "tree-flow.h"
90041 +#include "plugin.h"
90042 +#include "gimple.h"
90043 +#include "c-common.h"
90044 +#include "diagnostic.h"
90045 +#include "cfgloop.h"
90046 +
90047 +#if BUILDING_GCC_VERSION >= 4007
90048 +#include "c-tree.h"
90049 +#else
90050 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
90051 +#endif
90052 +
90053 +#if BUILDING_GCC_VERSION >= 4008
90054 +#define TODO_dump_func 0
90055 +#endif
90056 +
90057 +struct size_overflow_hash {
90058 + const struct size_overflow_hash * const next;
90059 + const char * const name;
90060 + const unsigned int param;
90061 +};
90062 +
90063 +#include "size_overflow_hash.h"
90064 +
90065 +enum marked {
90066 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
90067 +};
90068 +
90069 +static unsigned int call_count = 0;
90070 +
90071 +#define __unused __attribute__((__unused__))
90072 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
90073 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
90074 +#define BEFORE_STMT true
90075 +#define AFTER_STMT false
90076 +#define CREATE_NEW_VAR NULL_TREE
90077 +#define CODES_LIMIT 32
90078 +#define MAX_PARAM 32
90079 +#define MY_STMT GF_PLF_1
90080 +#define NO_CAST_CHECK GF_PLF_2
90081 +
90082 +#if BUILDING_GCC_VERSION == 4005
90083 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
90084 +#endif
90085 +
90086 +int plugin_is_GPL_compatible;
90087 +void debug_gimple_stmt(gimple gs);
90088 +
90089 +static tree expand(struct pointer_set_t *visited, tree lhs);
90090 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
90091 +static tree report_size_overflow_decl;
90092 +static const_tree const_char_ptr_type_node;
90093 +static unsigned int handle_function(void);
90094 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
90095 +static tree get_size_overflow_type(gimple stmt, const_tree node);
90096 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
90097 +
90098 +static struct plugin_info size_overflow_plugin_info = {
90099 + .version = "20130109beta",
90100 + .help = "no-size-overflow\tturn off size overflow checking\n",
90101 +};
90102 +
90103 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90104 +{
90105 + unsigned int arg_count;
90106 + enum tree_code code = TREE_CODE(*node);
90107 +
90108 + switch (code) {
90109 + case FUNCTION_DECL:
90110 + arg_count = type_num_arguments(TREE_TYPE(*node));
90111 + break;
90112 + case FUNCTION_TYPE:
90113 + case METHOD_TYPE:
90114 + arg_count = type_num_arguments(*node);
90115 + break;
90116 + default:
90117 + *no_add_attrs = true;
90118 + error("%s: %qE attribute only applies to functions", __func__, name);
90119 + return NULL_TREE;
90120 + }
90121 +
90122 + for (; args; args = TREE_CHAIN(args)) {
90123 + tree position = TREE_VALUE(args);
90124 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
90125 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90126 + *no_add_attrs = true;
90127 + }
90128 + }
90129 + return NULL_TREE;
90130 +}
90131 +
90132 +static const char* get_asm_name(tree node)
90133 +{
90134 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
90135 +}
90136 +
90137 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90138 +{
90139 + unsigned int arg_count, arg_num;
90140 + enum tree_code code = TREE_CODE(*node);
90141 +
90142 + switch (code) {
90143 + case FUNCTION_DECL:
90144 + arg_count = type_num_arguments(TREE_TYPE(*node));
90145 + break;
90146 + case FUNCTION_TYPE:
90147 + case METHOD_TYPE:
90148 + arg_count = type_num_arguments(*node);
90149 + break;
90150 + case FIELD_DECL:
90151 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
90152 + if (arg_num != 0) {
90153 + *no_add_attrs = true;
90154 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
90155 + }
90156 + return NULL_TREE;
90157 + default:
90158 + *no_add_attrs = true;
90159 + error("%qE attribute only applies to functions", name);
90160 + return NULL_TREE;
90161 + }
90162 +
90163 + for (; args; args = TREE_CHAIN(args)) {
90164 + tree position = TREE_VALUE(args);
90165 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
90166 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90167 + *no_add_attrs = true;
90168 + }
90169 + }
90170 + return NULL_TREE;
90171 +}
90172 +
90173 +static struct attribute_spec size_overflow_attr = {
90174 + .name = "size_overflow",
90175 + .min_length = 1,
90176 + .max_length = -1,
90177 + .decl_required = true,
90178 + .type_required = false,
90179 + .function_type_required = false,
90180 + .handler = handle_size_overflow_attribute,
90181 +#if BUILDING_GCC_VERSION >= 4007
90182 + .affects_type_identity = false
90183 +#endif
90184 +};
90185 +
90186 +static struct attribute_spec intentional_overflow_attr = {
90187 + .name = "intentional_overflow",
90188 + .min_length = 1,
90189 + .max_length = -1,
90190 + .decl_required = true,
90191 + .type_required = false,
90192 + .function_type_required = false,
90193 + .handler = handle_intentional_overflow_attribute,
90194 +#if BUILDING_GCC_VERSION >= 4007
90195 + .affects_type_identity = false
90196 +#endif
90197 +};
90198 +
90199 +static void register_attributes(void __unused *event_data, void __unused *data)
90200 +{
90201 + register_attribute(&size_overflow_attr);
90202 + register_attribute(&intentional_overflow_attr);
90203 +}
90204 +
90205 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
90206 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
90207 +{
90208 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
90209 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
90210 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
90211 +
90212 + unsigned int m = 0x57559429;
90213 + unsigned int n = 0x5052acdb;
90214 + const unsigned int *key4 = (const unsigned int *)key;
90215 + unsigned int h = len;
90216 + unsigned int k = len + seed + n;
90217 + unsigned long long p;
90218 +
90219 + while (len >= 8) {
90220 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
90221 + len -= 8;
90222 + }
90223 + if (len >= 4) {
90224 + cwmixb(key4[0]) key4 += 1;
90225 + len -= 4;
90226 + }
90227 + if (len)
90228 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
90229 + cwmixb(h ^ (k + n));
90230 + return k ^ h;
90231 +
90232 +#undef cwfold
90233 +#undef cwmixa
90234 +#undef cwmixb
90235 +}
90236 +
90237 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
90238 +{
90239 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
90240 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
90241 + return fn ^ codes;
90242 +}
90243 +
90244 +static inline tree get_original_function_decl(tree fndecl)
90245 +{
90246 + if (DECL_ABSTRACT_ORIGIN(fndecl))
90247 + return DECL_ABSTRACT_ORIGIN(fndecl);
90248 + return fndecl;
90249 +}
90250 +
90251 +static inline gimple get_def_stmt(const_tree node)
90252 +{
90253 + gcc_assert(node != NULL_TREE);
90254 + gcc_assert(TREE_CODE(node) == SSA_NAME);
90255 + return SSA_NAME_DEF_STMT(node);
90256 +}
90257 +
90258 +static unsigned char get_tree_code(const_tree type)
90259 +{
90260 + switch (TREE_CODE(type)) {
90261 + case ARRAY_TYPE:
90262 + return 0;
90263 + case BOOLEAN_TYPE:
90264 + return 1;
90265 + case ENUMERAL_TYPE:
90266 + return 2;
90267 + case FUNCTION_TYPE:
90268 + return 3;
90269 + case INTEGER_TYPE:
90270 + return 4;
90271 + case POINTER_TYPE:
90272 + return 5;
90273 + case RECORD_TYPE:
90274 + return 6;
90275 + case UNION_TYPE:
90276 + return 7;
90277 + case VOID_TYPE:
90278 + return 8;
90279 + case REAL_TYPE:
90280 + return 9;
90281 + case VECTOR_TYPE:
90282 + return 10;
90283 + case REFERENCE_TYPE:
90284 + return 11;
90285 + case OFFSET_TYPE:
90286 + return 12;
90287 + case COMPLEX_TYPE:
90288 + return 13;
90289 + default:
90290 + debug_tree((tree)type);
90291 + gcc_unreachable();
90292 + }
90293 +}
90294 +
90295 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
90296 +{
90297 + gcc_assert(type != NULL_TREE);
90298 +
90299 + while (type && len < CODES_LIMIT) {
90300 + tree_codes[len] = get_tree_code(type);
90301 + len++;
90302 + type = TREE_TYPE(type);
90303 + }
90304 + return len;
90305 +}
90306 +
90307 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
90308 +{
90309 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
90310 + enum tree_code code = TREE_CODE(type);
90311 + size_t len = 0;
90312 +
90313 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
90314 +
90315 + arg = TYPE_ARG_TYPES(type);
90316 + // skip builtins __builtin_constant_p
90317 + if (!arg && DECL_BUILT_IN(fndecl))
90318 + return 0;
90319 +
90320 + if (TREE_CODE_CLASS(code) == tcc_type)
90321 + result = type;
90322 + else
90323 + result = DECL_RESULT(fndecl);
90324 +
90325 + gcc_assert(result != NULL_TREE);
90326 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
90327 +
90328 + if (arg == NULL_TREE) {
90329 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
90330 + arg_field = DECL_ARGUMENT_FLD(fndecl);
90331 + if (arg_field == NULL_TREE)
90332 + return 0;
90333 + arg = TREE_TYPE(arg_field);
90334 + len = add_type_codes(arg, tree_codes, len);
90335 + gcc_assert(len != 0);
90336 + return len;
90337 + }
90338 +
90339 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
90340 + while (arg && len < CODES_LIMIT) {
90341 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
90342 + arg = TREE_CHAIN(arg);
90343 + }
90344 +
90345 + gcc_assert(len != 0);
90346 + return len;
90347 +}
90348 +
90349 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
90350 +{
90351 + unsigned int hash;
90352 + const struct size_overflow_hash *entry;
90353 + unsigned char tree_codes[CODES_LIMIT];
90354 + size_t len;
90355 + const char *func_name = get_asm_name(fndecl);
90356 +
90357 + len = get_function_decl(fndecl, tree_codes);
90358 + if (len == 0)
90359 + return NULL;
90360 +
90361 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
90362 +
90363 + entry = size_overflow_hash[hash];
90364 + while (entry) {
90365 + if (!strcmp(entry->name, func_name))
90366 + return entry;
90367 + entry = entry->next;
90368 + }
90369 +
90370 + return NULL;
90371 +}
90372 +
90373 +static void check_arg_type(const_tree arg)
90374 +{
90375 + const_tree type = TREE_TYPE(arg);
90376 + enum tree_code code = TREE_CODE(type);
90377 +
90378 + if (code == BOOLEAN_TYPE)
90379 + return;
90380 +
90381 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
90382 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
90383 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
90384 +}
90385 +
90386 +static unsigned int find_arg_number(const_tree arg, tree func)
90387 +{
90388 + tree var;
90389 + unsigned int argnum = 1;
90390 +
90391 + if (TREE_CODE(arg) == SSA_NAME)
90392 + arg = SSA_NAME_VAR(arg);
90393 +
90394 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
90395 + if (strcmp(NAME(arg), NAME(var))) {
90396 + argnum++;
90397 + continue;
90398 + }
90399 + check_arg_type(var);
90400 + return argnum;
90401 + }
90402 + gcc_unreachable();
90403 +}
90404 +
90405 +static tree create_new_var(tree type)
90406 +{
90407 + tree new_var = create_tmp_var(type, "cicus");
90408 +
90409 +#if BUILDING_GCC_VERSION <= 4007
90410 + add_referenced_var(new_var);
90411 + mark_sym_for_renaming(new_var);
90412 +#endif
90413 + return new_var;
90414 +}
90415 +
90416 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
90417 +{
90418 + gimple assign;
90419 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90420 + tree type = TREE_TYPE(rhs1);
90421 + tree lhs = create_new_var(type);
90422 +
90423 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
90424 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
90425 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90426 +
90427 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
90428 + update_stmt(assign);
90429 + gimple_set_plf(assign, MY_STMT, true);
90430 + return assign;
90431 +}
90432 +
90433 +static bool is_bool(const_tree node)
90434 +{
90435 + const_tree type;
90436 +
90437 + if (node == NULL_TREE)
90438 + return false;
90439 +
90440 + type = TREE_TYPE(node);
90441 + if (!INTEGRAL_TYPE_P(type))
90442 + return false;
90443 + if (TREE_CODE(type) == BOOLEAN_TYPE)
90444 + return true;
90445 + if (TYPE_PRECISION(type) == 1)
90446 + return true;
90447 + return false;
90448 +}
90449 +
90450 +static tree cast_a_tree(tree type, tree var)
90451 +{
90452 + gcc_assert(type != NULL_TREE);
90453 + gcc_assert(var != NULL_TREE);
90454 + gcc_assert(fold_convertible_p(type, var));
90455 +
90456 + return fold_convert(type, var);
90457 +}
90458 +
90459 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
90460 +{
90461 + gimple assign;
90462 +
90463 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
90464 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
90465 + gcc_unreachable();
90466 +
90467 + if (lhs == CREATE_NEW_VAR)
90468 + lhs = create_new_var(dst_type);
90469 +
90470 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
90471 +
90472 + if (!gsi_end_p(*gsi)) {
90473 + location_t loc = gimple_location(gsi_stmt(*gsi));
90474 + gimple_set_location(assign, loc);
90475 + }
90476 +
90477 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90478 +
90479 + if (before)
90480 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
90481 + else
90482 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
90483 + update_stmt(assign);
90484 + gimple_set_plf(assign, MY_STMT, true);
90485 +
90486 + return assign;
90487 +}
90488 +
90489 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
90490 +{
90491 + gimple assign;
90492 + gimple_stmt_iterator gsi;
90493 +
90494 + if (rhs == NULL_TREE)
90495 + return NULL_TREE;
90496 +
90497 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
90498 + return rhs;
90499 +
90500 + gsi = gsi_for_stmt(stmt);
90501 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
90502 + gimple_set_plf(assign, MY_STMT, true);
90503 + return gimple_get_lhs(assign);
90504 +}
90505 +
90506 +static tree cast_to_TI_type(gimple stmt, tree node)
90507 +{
90508 + gimple_stmt_iterator gsi;
90509 + gimple cast_stmt;
90510 + tree type = TREE_TYPE(node);
90511 +
90512 + if (types_compatible_p(type, intTI_type_node))
90513 + return node;
90514 +
90515 + gsi = gsi_for_stmt(stmt);
90516 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90517 + gimple_set_plf(cast_stmt, MY_STMT, true);
90518 + return gimple_get_lhs(cast_stmt);
90519 +}
90520 +
90521 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
90522 +{
90523 + tree lhs;
90524 + gimple_stmt_iterator gsi;
90525 +
90526 + if (rhs1 == NULL_TREE) {
90527 + debug_gimple_stmt(oldstmt);
90528 + error("%s: rhs1 is NULL_TREE", __func__);
90529 + gcc_unreachable();
90530 + }
90531 +
90532 + switch (gimple_code(oldstmt)) {
90533 + case GIMPLE_ASM:
90534 + lhs = rhs1;
90535 + break;
90536 + case GIMPLE_CALL:
90537 + lhs = gimple_call_lhs(oldstmt);
90538 + break;
90539 + case GIMPLE_ASSIGN:
90540 + lhs = gimple_get_lhs(oldstmt);
90541 + break;
90542 + default:
90543 + debug_gimple_stmt(oldstmt);
90544 + gcc_unreachable();
90545 + }
90546 +
90547 + gsi = gsi_for_stmt(oldstmt);
90548 + pointer_set_insert(visited, oldstmt);
90549 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
90550 + basic_block next_bb, cur_bb;
90551 + const_edge e;
90552 +
90553 + gcc_assert(before == false);
90554 + gcc_assert(stmt_can_throw_internal(oldstmt));
90555 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
90556 + gcc_assert(!gsi_end_p(gsi));
90557 +
90558 + cur_bb = gimple_bb(oldstmt);
90559 + next_bb = cur_bb->next_bb;
90560 + e = find_edge(cur_bb, next_bb);
90561 + gcc_assert(e != NULL);
90562 + gcc_assert(e->flags & EDGE_FALLTHRU);
90563 +
90564 + gsi = gsi_after_labels(next_bb);
90565 + gcc_assert(!gsi_end_p(gsi));
90566 +
90567 + before = true;
90568 + oldstmt = gsi_stmt(gsi);
90569 + }
90570 +
90571 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
90572 +}
90573 +
90574 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
90575 +{
90576 + gimple stmt;
90577 + gimple_stmt_iterator gsi;
90578 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
90579 +
90580 + if (gimple_plf(oldstmt, MY_STMT))
90581 + return lhs;
90582 +
90583 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
90584 + rhs1 = gimple_assign_rhs1(oldstmt);
90585 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
90586 + }
90587 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
90588 + rhs2 = gimple_assign_rhs2(oldstmt);
90589 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
90590 + }
90591 +
90592 + stmt = gimple_copy(oldstmt);
90593 + gimple_set_location(stmt, gimple_location(oldstmt));
90594 + gimple_set_plf(stmt, MY_STMT, true);
90595 +
90596 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
90597 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
90598 +
90599 + size_overflow_type = get_size_overflow_type(oldstmt, node);
90600 +
90601 + if (is_bool(lhs))
90602 + new_var = SSA_NAME_VAR(lhs);
90603 + else
90604 + new_var = create_new_var(size_overflow_type);
90605 + new_var = make_ssa_name(new_var, stmt);
90606 + gimple_set_lhs(stmt, new_var);
90607 +
90608 + if (rhs1 != NULL_TREE)
90609 + gimple_assign_set_rhs1(stmt, rhs1);
90610 +
90611 + if (rhs2 != NULL_TREE)
90612 + gimple_assign_set_rhs2(stmt, rhs2);
90613 +#if BUILDING_GCC_VERSION >= 4007
90614 + if (rhs3 != NULL_TREE)
90615 + gimple_assign_set_rhs3(stmt, rhs3);
90616 +#endif
90617 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
90618 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
90619 +
90620 + gsi = gsi_for_stmt(oldstmt);
90621 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
90622 + update_stmt(stmt);
90623 + pointer_set_insert(visited, oldstmt);
90624 + return gimple_get_lhs(stmt);
90625 +}
90626 +
90627 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
90628 +{
90629 + basic_block bb;
90630 + gimple phi;
90631 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
90632 + gimple_seq seq;
90633 +
90634 + bb = gsi_bb(gsi);
90635 +
90636 + phi = create_phi_node(result, bb);
90637 + seq = phi_nodes(bb);
90638 + gsi = gsi_last(seq);
90639 + gsi_remove(&gsi, false);
90640 +
90641 + gsi = gsi_for_stmt(oldstmt);
90642 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
90643 + gimple_set_bb(phi, bb);
90644 + gimple_set_plf(phi, MY_STMT, true);
90645 + return phi;
90646 +}
90647 +
90648 +static basic_block create_a_first_bb(void)
90649 +{
90650 + basic_block first_bb;
90651 +
90652 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90653 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90654 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
90655 + return first_bb;
90656 +}
90657 +
90658 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
90659 +{
90660 + basic_block bb;
90661 + const_gimple newstmt;
90662 + gimple_stmt_iterator gsi;
90663 + bool before = BEFORE_STMT;
90664 +
90665 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
90666 + gsi = gsi_for_stmt(get_def_stmt(arg));
90667 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
90668 + return gimple_get_lhs(newstmt);
90669 + }
90670 +
90671 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
90672 + gsi = gsi_after_labels(bb);
90673 + if (bb->index == 0) {
90674 + bb = create_a_first_bb();
90675 + gsi = gsi_start_bb(bb);
90676 + }
90677 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
90678 + return gimple_get_lhs(newstmt);
90679 +}
90680 +
90681 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
90682 +{
90683 + gimple newstmt;
90684 + gimple_stmt_iterator gsi;
90685 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
90686 + gimple def_newstmt = get_def_stmt(new_rhs);
90687 +
90688 + gsi_insert = gsi_insert_after;
90689 + gsi = gsi_for_stmt(def_newstmt);
90690 +
90691 + switch (gimple_code(get_def_stmt(arg))) {
90692 + case GIMPLE_PHI:
90693 + newstmt = gimple_build_assign(new_var, new_rhs);
90694 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
90695 + gsi_insert = gsi_insert_before;
90696 + break;
90697 + case GIMPLE_ASM:
90698 + case GIMPLE_CALL:
90699 + newstmt = gimple_build_assign(new_var, new_rhs);
90700 + break;
90701 + case GIMPLE_ASSIGN:
90702 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
90703 + break;
90704 + default:
90705 + /* unknown gimple_code (handle_build_new_phi_arg) */
90706 + gcc_unreachable();
90707 + }
90708 +
90709 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
90710 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
90711 + gimple_set_plf(newstmt, MY_STMT, true);
90712 + update_stmt(newstmt);
90713 + return newstmt;
90714 +}
90715 +
90716 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
90717 +{
90718 + const_gimple newstmt;
90719 + gimple def_stmt;
90720 + tree new_rhs;
90721 +
90722 + new_rhs = expand(visited, arg);
90723 + if (new_rhs == NULL_TREE)
90724 + return NULL_TREE;
90725 +
90726 + def_stmt = get_def_stmt(new_rhs);
90727 + if (gimple_code(def_stmt) == GIMPLE_NOP)
90728 + return NULL_TREE;
90729 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
90730 +
90731 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
90732 + return gimple_get_lhs(newstmt);
90733 +}
90734 +
90735 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
90736 +{
90737 + gimple phi, oldstmt = get_def_stmt(orig_result);
90738 + tree new_result, size_overflow_type;
90739 + unsigned int i;
90740 + unsigned int n = gimple_phi_num_args(oldstmt);
90741 +
90742 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
90743 +
90744 + new_result = create_new_var(size_overflow_type);
90745 +
90746 + pointer_set_insert(visited, oldstmt);
90747 + phi = overflow_create_phi_node(oldstmt, new_result);
90748 + for (i = 0; i < n; i++) {
90749 + tree arg, lhs;
90750 +
90751 + arg = gimple_phi_arg_def(oldstmt, i);
90752 + if (is_gimple_constant(arg))
90753 + arg = cast_a_tree(size_overflow_type, arg);
90754 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
90755 + if (lhs == NULL_TREE)
90756 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
90757 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
90758 + }
90759 +
90760 + update_stmt(phi);
90761 + return gimple_phi_result(phi);
90762 +}
90763 +
90764 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
90765 +{
90766 + const_gimple assign;
90767 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90768 + tree origtype = TREE_TYPE(orig_rhs);
90769 +
90770 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
90771 +
90772 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90773 + return gimple_get_lhs(assign);
90774 +}
90775 +
90776 +static void change_rhs1(gimple stmt, tree new_rhs1)
90777 +{
90778 + tree assign_rhs;
90779 + const_tree rhs = gimple_assign_rhs1(stmt);
90780 +
90781 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
90782 + gimple_assign_set_rhs1(stmt, assign_rhs);
90783 + update_stmt(stmt);
90784 +}
90785 +
90786 +static bool check_mode_type(const_gimple stmt)
90787 +{
90788 + const_tree lhs = gimple_get_lhs(stmt);
90789 + const_tree lhs_type = TREE_TYPE(lhs);
90790 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
90791 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
90792 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
90793 +
90794 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
90795 + return false;
90796 +
90797 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
90798 + return false;
90799 +
90800 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
90801 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
90802 + return false;
90803 +
90804 + return true;
90805 +}
90806 +
90807 +static bool check_undefined_integer_operation(const_gimple stmt)
90808 +{
90809 + const_gimple def_stmt;
90810 + const_tree lhs = gimple_get_lhs(stmt);
90811 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90812 + const_tree rhs1_type = TREE_TYPE(rhs1);
90813 + const_tree lhs_type = TREE_TYPE(lhs);
90814 +
90815 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90816 + return false;
90817 +
90818 + def_stmt = get_def_stmt(rhs1);
90819 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
90820 + return false;
90821 +
90822 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
90823 + return false;
90824 + return true;
90825 +}
90826 +
90827 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
90828 +{
90829 + const_tree rhs1, lhs, rhs1_type, lhs_type;
90830 + enum machine_mode lhs_mode, rhs_mode;
90831 + gimple def_stmt = get_def_stmt(no_const_rhs);
90832 +
90833 + if (!gimple_assign_cast_p(def_stmt))
90834 + return false;
90835 +
90836 + rhs1 = gimple_assign_rhs1(def_stmt);
90837 + lhs = gimple_get_lhs(def_stmt);
90838 + rhs1_type = TREE_TYPE(rhs1);
90839 + lhs_type = TREE_TYPE(lhs);
90840 + rhs_mode = TYPE_MODE(rhs1_type);
90841 + lhs_mode = TYPE_MODE(lhs_type);
90842 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
90843 + return false;
90844 +
90845 + return true;
90846 +}
90847 +
90848 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
90849 +{
90850 + tree rhs1 = gimple_assign_rhs1(stmt);
90851 + tree lhs = gimple_get_lhs(stmt);
90852 + const_tree rhs1_type = TREE_TYPE(rhs1);
90853 + const_tree lhs_type = TREE_TYPE(lhs);
90854 +
90855 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90856 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90857 +
90858 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
90859 +}
90860 +
90861 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
90862 +{
90863 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
90864 + tree new_rhs1 = NULL_TREE;
90865 + tree rhs1 = gimple_assign_rhs1(stmt);
90866 + const_tree rhs1_type = TREE_TYPE(rhs1);
90867 + const_tree lhs_type = TREE_TYPE(lhs);
90868 +
90869 + if (gimple_plf(stmt, MY_STMT))
90870 + return lhs;
90871 +
90872 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
90873 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90874 +
90875 + new_rhs1 = expand(visited, rhs1);
90876 +
90877 + if (new_rhs1 == NULL_TREE)
90878 + return create_cast_assign(visited, stmt);
90879 +
90880 + if (gimple_plf(stmt, NO_CAST_CHECK))
90881 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90882 +
90883 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
90884 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90885 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90886 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90887 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90888 + }
90889 +
90890 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
90891 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90892 +
90893 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
90894 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90895 +
90896 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90897 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90898 +
90899 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90900 +
90901 + change_rhs1(stmt, new_rhs1);
90902 +
90903 + if (!check_mode_type(stmt))
90904 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90905 +
90906 + size_overflow_type = get_size_overflow_type(stmt, lhs);
90907 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90908 +
90909 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
90910 +
90911 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90912 +}
90913 +
90914 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
90915 +{
90916 + tree rhs1, lhs = gimple_get_lhs(stmt);
90917 + gimple def_stmt = get_def_stmt(lhs);
90918 +
90919 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
90920 + rhs1 = gimple_assign_rhs1(def_stmt);
90921 +
90922 + if (is_gimple_constant(rhs1))
90923 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90924 +
90925 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
90926 + switch (TREE_CODE(rhs1)) {
90927 + case SSA_NAME:
90928 + return handle_unary_rhs(visited, def_stmt);
90929 + case ARRAY_REF:
90930 + case BIT_FIELD_REF:
90931 + case ADDR_EXPR:
90932 + case COMPONENT_REF:
90933 + case INDIRECT_REF:
90934 +#if BUILDING_GCC_VERSION >= 4006
90935 + case MEM_REF:
90936 +#endif
90937 + case TARGET_MEM_REF:
90938 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90939 + case PARM_DECL:
90940 + case VAR_DECL:
90941 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90942 +
90943 + default:
90944 + debug_gimple_stmt(def_stmt);
90945 + debug_tree(rhs1);
90946 + gcc_unreachable();
90947 + }
90948 +}
90949 +
90950 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
90951 +{
90952 + gimple cond_stmt;
90953 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
90954 +
90955 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
90956 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
90957 + update_stmt(cond_stmt);
90958 +}
90959 +
90960 +static tree create_string_param(tree string)
90961 +{
90962 + tree i_type, a_type;
90963 + const int length = TREE_STRING_LENGTH(string);
90964 +
90965 + gcc_assert(length > 0);
90966 +
90967 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
90968 + a_type = build_array_type(char_type_node, i_type);
90969 +
90970 + TREE_TYPE(string) = a_type;
90971 + TREE_CONSTANT(string) = 1;
90972 + TREE_READONLY(string) = 1;
90973 +
90974 + return build1(ADDR_EXPR, ptr_type_node, string);
90975 +}
90976 +
90977 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
90978 +{
90979 + gimple func_stmt;
90980 + const_gimple def_stmt;
90981 + const_tree loc_line;
90982 + tree loc_file, ssa_name, current_func;
90983 + expanded_location xloc;
90984 + char *ssa_name_buf;
90985 + int len;
90986 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
90987 +
90988 + def_stmt = get_def_stmt(arg);
90989 + xloc = expand_location(gimple_location(def_stmt));
90990 +
90991 + if (!gimple_has_location(def_stmt)) {
90992 + xloc = expand_location(gimple_location(stmt));
90993 + if (!gimple_has_location(stmt))
90994 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
90995 + }
90996 +
90997 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
90998 +
90999 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
91000 + loc_file = create_string_param(loc_file);
91001 +
91002 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
91003 + current_func = create_string_param(current_func);
91004 +
91005 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
91006 + call_count++;
91007 + 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);
91008 + gcc_assert(len > 0);
91009 + ssa_name = build_string(len + 1, ssa_name_buf);
91010 + free(ssa_name_buf);
91011 + ssa_name = create_string_param(ssa_name);
91012 +
91013 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
91014 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
91015 +
91016 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
91017 +}
91018 +
91019 +static void __unused print_the_code_insertions(const_gimple stmt)
91020 +{
91021 + location_t loc = gimple_location(stmt);
91022 +
91023 + inform(loc, "Integer size_overflow check applied here.");
91024 +}
91025 +
91026 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
91027 +{
91028 + basic_block cond_bb, join_bb, bb_true;
91029 + edge e;
91030 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91031 +
91032 + cond_bb = gimple_bb(stmt);
91033 + if (before)
91034 + gsi_prev(&gsi);
91035 + if (gsi_end_p(gsi))
91036 + e = split_block_after_labels(cond_bb);
91037 + else
91038 + e = split_block(cond_bb, gsi_stmt(gsi));
91039 + cond_bb = e->src;
91040 + join_bb = e->dest;
91041 + e->flags = EDGE_FALSE_VALUE;
91042 + e->probability = REG_BR_PROB_BASE;
91043 +
91044 + bb_true = create_empty_bb(cond_bb);
91045 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
91046 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
91047 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
91048 +
91049 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91050 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
91051 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
91052 +
91053 + if (current_loops != NULL) {
91054 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
91055 + add_bb_to_loop(bb_true, cond_bb->loop_father);
91056 + }
91057 +
91058 + insert_cond(cond_bb, arg, cond_code, type_value);
91059 + insert_cond_result(bb_true, stmt, arg, min);
91060 +
91061 +// print_the_code_insertions(stmt);
91062 +}
91063 +
91064 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
91065 +{
91066 + const_tree rhs_type = TREE_TYPE(rhs);
91067 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
91068 +
91069 + gcc_assert(rhs_type != NULL_TREE);
91070 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
91071 + return;
91072 +
91073 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
91074 +
91075 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
91076 + // typemax (-1) < typemin (0)
91077 + if (TREE_OVERFLOW(type_max))
91078 + return;
91079 +
91080 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
91081 +
91082 + cast_rhs_type = TREE_TYPE(cast_rhs);
91083 + type_max_type = TREE_TYPE(type_max);
91084 + type_min_type = TREE_TYPE(type_min);
91085 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
91086 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
91087 +
91088 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
91089 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
91090 +}
91091 +
91092 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
91093 +{
91094 + gimple change_rhs_def_stmt;
91095 + tree lhs = gimple_get_lhs(def_stmt);
91096 + tree lhs_type = TREE_TYPE(lhs);
91097 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
91098 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
91099 +
91100 + if (change_rhs == NULL_TREE)
91101 + return get_size_overflow_type(def_stmt, lhs);
91102 +
91103 + change_rhs_def_stmt = get_def_stmt(change_rhs);
91104 +
91105 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
91106 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91107 +
91108 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
91109 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91110 +
91111 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
91112 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91113 +
91114 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
91115 + debug_gimple_stmt(def_stmt);
91116 + gcc_unreachable();
91117 + }
91118 +
91119 + return get_size_overflow_type(def_stmt, lhs);
91120 +}
91121 +
91122 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
91123 +{
91124 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
91125 + return false;
91126 + if (!is_gimple_constant(rhs))
91127 + return false;
91128 + return true;
91129 +}
91130 +
91131 +static bool is_subtraction_special(const_gimple stmt)
91132 +{
91133 + gimple rhs1_def_stmt, rhs2_def_stmt;
91134 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
91135 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
91136 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91137 + const_tree rhs2 = gimple_assign_rhs2(stmt);
91138 +
91139 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
91140 + return false;
91141 +
91142 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
91143 +
91144 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
91145 + return false;
91146 +
91147 + rhs1_def_stmt = get_def_stmt(rhs1);
91148 + rhs2_def_stmt = get_def_stmt(rhs2);
91149 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
91150 + return false;
91151 +
91152 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91153 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
91154 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
91155 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
91156 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
91157 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
91158 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
91159 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
91160 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
91161 + return false;
91162 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
91163 + return false;
91164 +
91165 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
91166 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
91167 + return true;
91168 +}
91169 +
91170 +static tree get_def_stmt_rhs(const_tree var)
91171 +{
91172 + tree rhs1, def_stmt_rhs1;
91173 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
91174 +
91175 + def_stmt = get_def_stmt(var);
91176 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
91177 +
91178 + rhs1 = gimple_assign_rhs1(def_stmt);
91179 + rhs1_def_stmt = get_def_stmt(rhs1);
91180 + if (!gimple_assign_cast_p(rhs1_def_stmt))
91181 + return rhs1;
91182 +
91183 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91184 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
91185 +
91186 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
91187 + case GIMPLE_CALL:
91188 + case GIMPLE_NOP:
91189 + case GIMPLE_ASM:
91190 + return def_stmt_rhs1;
91191 + case GIMPLE_ASSIGN:
91192 + return rhs1;
91193 + default:
91194 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
91195 + gcc_unreachable();
91196 + }
91197 +}
91198 +
91199 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
91200 +{
91201 + tree new_rhs1, new_rhs2;
91202 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
91203 + gimple assign, stmt = get_def_stmt(lhs);
91204 + tree rhs1 = gimple_assign_rhs1(stmt);
91205 + tree rhs2 = gimple_assign_rhs2(stmt);
91206 +
91207 + if (!is_subtraction_special(stmt))
91208 + return NULL_TREE;
91209 +
91210 + new_rhs1 = expand(visited, rhs1);
91211 + new_rhs2 = expand(visited, rhs2);
91212 +
91213 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
91214 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
91215 +
91216 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
91217 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
91218 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
91219 + }
91220 +
91221 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
91222 + new_lhs = gimple_get_lhs(assign);
91223 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
91224 +
91225 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91226 +}
91227 +
91228 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
91229 +{
91230 + const_gimple def_stmt;
91231 +
91232 + if (TREE_CODE(rhs) != SSA_NAME)
91233 + return false;
91234 +
91235 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
91236 + return false;
91237 +
91238 + def_stmt = get_def_stmt(rhs);
91239 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
91240 + return false;
91241 +
91242 + return true;
91243 +}
91244 +
91245 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
91246 +{
91247 + tree new_rhs, size_overflow_type, orig_rhs;
91248 + void (*gimple_assign_set_rhs)(gimple, tree);
91249 + tree rhs1 = gimple_assign_rhs1(stmt);
91250 + tree rhs2 = gimple_assign_rhs2(stmt);
91251 + tree lhs = gimple_get_lhs(stmt);
91252 +
91253 + if (change_rhs == NULL_TREE)
91254 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91255 +
91256 + if (new_rhs2 == NULL_TREE) {
91257 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
91258 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
91259 + orig_rhs = rhs1;
91260 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
91261 + } else {
91262 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
91263 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
91264 + orig_rhs = rhs2;
91265 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
91266 + }
91267 +
91268 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
91269 +
91270 + if (check_overflow)
91271 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
91272 +
91273 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
91274 + gimple_assign_set_rhs(stmt, new_rhs);
91275 + update_stmt(stmt);
91276 +
91277 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91278 +}
91279 +
91280 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
91281 +{
91282 + tree rhs1, rhs2, new_lhs;
91283 + gimple def_stmt = get_def_stmt(lhs);
91284 + tree new_rhs1 = NULL_TREE;
91285 + tree new_rhs2 = NULL_TREE;
91286 +
91287 + rhs1 = gimple_assign_rhs1(def_stmt);
91288 + rhs2 = gimple_assign_rhs2(def_stmt);
91289 +
91290 + /* no DImode/TImode division in the 32/64 bit kernel */
91291 + switch (gimple_assign_rhs_code(def_stmt)) {
91292 + case RDIV_EXPR:
91293 + case TRUNC_DIV_EXPR:
91294 + case CEIL_DIV_EXPR:
91295 + case FLOOR_DIV_EXPR:
91296 + case ROUND_DIV_EXPR:
91297 + case TRUNC_MOD_EXPR:
91298 + case CEIL_MOD_EXPR:
91299 + case FLOOR_MOD_EXPR:
91300 + case ROUND_MOD_EXPR:
91301 + case EXACT_DIV_EXPR:
91302 + case POINTER_PLUS_EXPR:
91303 + case BIT_AND_EXPR:
91304 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91305 + default:
91306 + break;
91307 + }
91308 +
91309 + new_lhs = handle_integer_truncation(visited, lhs);
91310 + if (new_lhs != NULL_TREE)
91311 + return new_lhs;
91312 +
91313 + if (TREE_CODE(rhs1) == SSA_NAME)
91314 + new_rhs1 = expand(visited, rhs1);
91315 + if (TREE_CODE(rhs2) == SSA_NAME)
91316 + new_rhs2 = expand(visited, rhs2);
91317 +
91318 + if (is_a_neg_overflow(def_stmt, rhs2))
91319 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91320 + if (is_a_neg_overflow(def_stmt, rhs1))
91321 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91322 +
91323 + if (is_a_constant_overflow(def_stmt, rhs2))
91324 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91325 + if (is_a_constant_overflow(def_stmt, rhs1))
91326 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91327 +
91328 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91329 +}
91330 +
91331 +#if BUILDING_GCC_VERSION >= 4007
91332 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
91333 +{
91334 + if (is_gimple_constant(rhs))
91335 + return cast_a_tree(size_overflow_type, rhs);
91336 + if (TREE_CODE(rhs) != SSA_NAME)
91337 + return NULL_TREE;
91338 + return expand(visited, rhs);
91339 +}
91340 +
91341 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
91342 +{
91343 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
91344 + gimple def_stmt = get_def_stmt(lhs);
91345 +
91346 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
91347 +
91348 + rhs1 = gimple_assign_rhs1(def_stmt);
91349 + rhs2 = gimple_assign_rhs2(def_stmt);
91350 + rhs3 = gimple_assign_rhs3(def_stmt);
91351 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
91352 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
91353 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
91354 +
91355 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
91356 +}
91357 +#endif
91358 +
91359 +static tree get_size_overflow_type(gimple stmt, const_tree node)
91360 +{
91361 + const_tree type;
91362 + tree new_type;
91363 +
91364 + gcc_assert(node != NULL_TREE);
91365 +
91366 + type = TREE_TYPE(node);
91367 +
91368 + if (gimple_plf(stmt, MY_STMT))
91369 + return TREE_TYPE(node);
91370 +
91371 + switch (TYPE_MODE(type)) {
91372 + case QImode:
91373 + new_type = intHI_type_node;
91374 + break;
91375 + case HImode:
91376 + new_type = intSI_type_node;
91377 + break;
91378 + case SImode:
91379 + new_type = intDI_type_node;
91380 + break;
91381 + case DImode:
91382 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
91383 + new_type = intDI_type_node;
91384 + else
91385 + new_type = intTI_type_node;
91386 + break;
91387 + default:
91388 + debug_tree((tree)node);
91389 + error("%s: unsupported gcc configuration.", __func__);
91390 + gcc_unreachable();
91391 + }
91392 +
91393 + if (TYPE_QUALS(type) != 0)
91394 + return build_qualified_type(new_type, TYPE_QUALS(type));
91395 + return new_type;
91396 +}
91397 +
91398 +static tree expand_visited(gimple def_stmt)
91399 +{
91400 + const_gimple next_stmt;
91401 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
91402 +
91403 + gsi_next(&gsi);
91404 + next_stmt = gsi_stmt(gsi);
91405 +
91406 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
91407 +
91408 + switch (gimple_code(next_stmt)) {
91409 + case GIMPLE_ASSIGN:
91410 + return gimple_get_lhs(next_stmt);
91411 + case GIMPLE_PHI:
91412 + return gimple_phi_result(next_stmt);
91413 + case GIMPLE_CALL:
91414 + return gimple_call_lhs(next_stmt);
91415 + default:
91416 + return NULL_TREE;
91417 + }
91418 +}
91419 +
91420 +static tree expand(struct pointer_set_t *visited, tree lhs)
91421 +{
91422 + gimple def_stmt;
91423 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
91424 +
91425 + if (is_gimple_constant(lhs))
91426 + return NULL_TREE;
91427 +
91428 + if (TREE_CODE(lhs) == ADDR_EXPR)
91429 + return NULL_TREE;
91430 +
91431 + if (code == REAL_TYPE)
91432 + return NULL_TREE;
91433 +
91434 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
91435 +
91436 + def_stmt = get_def_stmt(lhs);
91437 +
91438 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
91439 + return NULL_TREE;
91440 +
91441 + if (gimple_plf(def_stmt, MY_STMT))
91442 + return lhs;
91443 +
91444 + if (pointer_set_contains(visited, def_stmt))
91445 + return expand_visited(def_stmt);
91446 +
91447 + switch (gimple_code(def_stmt)) {
91448 + case GIMPLE_PHI:
91449 + return build_new_phi(visited, lhs);
91450 + case GIMPLE_CALL:
91451 + case GIMPLE_ASM:
91452 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91453 + case GIMPLE_ASSIGN:
91454 + switch (gimple_num_ops(def_stmt)) {
91455 + case 2:
91456 + return handle_unary_ops(visited, def_stmt);
91457 + case 3:
91458 + return handle_binary_ops(visited, lhs);
91459 +#if BUILDING_GCC_VERSION >= 4007
91460 + case 4:
91461 + return handle_ternary_ops(visited, lhs);
91462 +#endif
91463 + }
91464 + default:
91465 + debug_gimple_stmt(def_stmt);
91466 + error("%s: unknown gimple code", __func__);
91467 + gcc_unreachable();
91468 + }
91469 +}
91470 +
91471 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
91472 +{
91473 + const_gimple assign;
91474 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91475 + tree origtype = TREE_TYPE(origarg);
91476 +
91477 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
91478 +
91479 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91480 +
91481 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
91482 + update_stmt(stmt);
91483 +}
91484 +
91485 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
91486 +{
91487 + const char *origid;
91488 + tree arg;
91489 + const_tree origarg;
91490 +
91491 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
91492 + return true;
91493 +
91494 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
91495 + while (origarg && *argnum) {
91496 + (*argnum)--;
91497 + origarg = TREE_CHAIN(origarg);
91498 + }
91499 +
91500 + gcc_assert(*argnum == 0);
91501 +
91502 + gcc_assert(origarg != NULL_TREE);
91503 + origid = NAME(origarg);
91504 + *argnum = 0;
91505 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
91506 + if (!strcmp(origid, NAME(arg)))
91507 + return true;
91508 + (*argnum)++;
91509 + }
91510 + return false;
91511 +}
91512 +
91513 +static bool skip_types(const_tree var)
91514 +{
91515 + const_tree type;
91516 +
91517 + switch (TREE_CODE(var)) {
91518 + case ADDR_EXPR:
91519 +#if BUILDING_GCC_VERSION >= 4006
91520 + case MEM_REF:
91521 +#endif
91522 + case ARRAY_REF:
91523 + case BIT_FIELD_REF:
91524 + case INDIRECT_REF:
91525 + case TARGET_MEM_REF:
91526 + case VAR_DECL:
91527 + return true;
91528 + default:
91529 + break;
91530 + }
91531 +
91532 + type = TREE_TYPE(TREE_TYPE(var));
91533 + if (!type)
91534 + return false;
91535 + switch (TREE_CODE(type)) {
91536 + case RECORD_TYPE:
91537 + return true;
91538 + default:
91539 + break;
91540 + }
91541 +
91542 + return false;
91543 +}
91544 +
91545 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
91546 +{
91547 + gimple phi = get_def_stmt(result);
91548 + unsigned int i, n = gimple_phi_num_args(phi);
91549 +
91550 + if (!phi)
91551 + return false;
91552 +
91553 + pointer_set_insert(visited, phi);
91554 + for (i = 0; i < n; i++) {
91555 + const_tree arg = gimple_phi_arg_def(phi, i);
91556 + if (pre_expand(visited, arg))
91557 + return true;
91558 + }
91559 + return false;
91560 +}
91561 +
91562 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
91563 +{
91564 + gimple def_stmt = get_def_stmt(lhs);
91565 + const_tree rhs;
91566 +
91567 + if (!def_stmt)
91568 + return false;
91569 +
91570 + rhs = gimple_assign_rhs1(def_stmt);
91571 + if (pre_expand(visited, rhs))
91572 + return true;
91573 + return false;
91574 +}
91575 +
91576 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
91577 +{
91578 + bool rhs1_found, rhs2_found;
91579 + gimple def_stmt = get_def_stmt(lhs);
91580 + const_tree rhs1, rhs2;
91581 +
91582 + if (!def_stmt)
91583 + return false;
91584 +
91585 + rhs1 = gimple_assign_rhs1(def_stmt);
91586 + rhs2 = gimple_assign_rhs2(def_stmt);
91587 + rhs1_found = pre_expand(visited, rhs1);
91588 + rhs2_found = pre_expand(visited, rhs2);
91589 +
91590 + return rhs1_found || rhs2_found;
91591 +}
91592 +
91593 +static const_tree search_field_decl(const_tree comp_ref)
91594 +{
91595 + const_tree field = NULL_TREE;
91596 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
91597 +
91598 + for (i = 0; i < len; i++) {
91599 + field = TREE_OPERAND(comp_ref, i);
91600 + if (TREE_CODE(field) == FIELD_DECL)
91601 + break;
91602 + }
91603 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
91604 + return field;
91605 +}
91606 +
91607 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
91608 +{
91609 + const_tree attr, p;
91610 +
91611 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
91612 + if (!attr || !TREE_VALUE(attr))
91613 + return MARKED_NO;
91614 +
91615 + p = TREE_VALUE(attr);
91616 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
91617 + return MARKED_NOT_INTENTIONAL;
91618 +
91619 + do {
91620 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
91621 + return MARKED_YES;
91622 + p = TREE_CHAIN(p);
91623 + } while (p);
91624 +
91625 + return MARKED_NO;
91626 +}
91627 +
91628 +static void print_missing_msg(tree func, unsigned int argnum)
91629 +{
91630 + unsigned int new_hash;
91631 + size_t len;
91632 + unsigned char tree_codes[CODES_LIMIT];
91633 + location_t loc = DECL_SOURCE_LOCATION(func);
91634 + const char *curfunc = get_asm_name(func);
91635 +
91636 + len = get_function_decl(func, tree_codes);
91637 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
91638 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
91639 +}
91640 +
91641 +static unsigned int search_missing_attribute(const_tree arg)
91642 +{
91643 + const_tree type = TREE_TYPE(arg);
91644 + tree func = get_original_function_decl(current_function_decl);
91645 + unsigned int argnum;
91646 + const struct size_overflow_hash *hash;
91647 +
91648 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
91649 +
91650 + if (TREE_CODE(type) == POINTER_TYPE)
91651 + return 0;
91652 +
91653 + argnum = find_arg_number(arg, func);
91654 + if (argnum == 0)
91655 + return 0;
91656 +
91657 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
91658 + return argnum;
91659 +
91660 + hash = get_function_hash(func);
91661 + if (!hash || !(hash->param & (1U << argnum))) {
91662 + print_missing_msg(func, argnum);
91663 + return 0;
91664 + }
91665 + return argnum;
91666 +}
91667 +
91668 +static bool is_already_marked(const_tree lhs)
91669 +{
91670 + unsigned int argnum;
91671 + const_tree fndecl;
91672 +
91673 + argnum = search_missing_attribute(lhs);
91674 + fndecl = get_original_function_decl(current_function_decl);
91675 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
91676 + return true;
91677 + return false;
91678 +}
91679 +
91680 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
91681 +{
91682 + const_gimple def_stmt;
91683 +
91684 + if (is_gimple_constant(lhs))
91685 + return false;
91686 +
91687 + if (skip_types(lhs))
91688 + return false;
91689 +
91690 + // skip char type (FIXME: only kernel)
91691 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
91692 + return false;
91693 +
91694 + if (TREE_CODE(lhs) == PARM_DECL)
91695 + return is_already_marked(lhs);
91696 +
91697 + if (TREE_CODE(lhs) == COMPONENT_REF) {
91698 + const_tree field, attr;
91699 +
91700 + field = search_field_decl(lhs);
91701 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
91702 + if (!attr || !TREE_VALUE(attr))
91703 + return false;
91704 + return true;
91705 + }
91706 +
91707 + def_stmt = get_def_stmt(lhs);
91708 +
91709 + if (!def_stmt)
91710 + return false;
91711 +
91712 + if (pointer_set_contains(visited, def_stmt))
91713 + return false;
91714 +
91715 + switch (gimple_code(def_stmt)) {
91716 + case GIMPLE_NOP:
91717 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
91718 + return is_already_marked(lhs);
91719 + return false;
91720 + case GIMPLE_PHI:
91721 + return walk_phi(visited, lhs);
91722 + case GIMPLE_CALL:
91723 + case GIMPLE_ASM:
91724 + return false;
91725 + case GIMPLE_ASSIGN:
91726 + switch (gimple_num_ops(def_stmt)) {
91727 + case 2:
91728 + return walk_unary_ops(visited, lhs);
91729 + case 3:
91730 + return walk_binary_ops(visited, lhs);
91731 + }
91732 + default:
91733 + debug_gimple_stmt((gimple)def_stmt);
91734 + error("%s: unknown gimple code", __func__);
91735 + gcc_unreachable();
91736 + }
91737 +}
91738 +
91739 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
91740 +{
91741 + struct pointer_set_t *visited;
91742 + bool is_found;
91743 + enum marked is_marked;
91744 + location_t loc;
91745 +
91746 + visited = pointer_set_create();
91747 + is_found = pre_expand(visited, arg);
91748 + pointer_set_destroy(visited);
91749 +
91750 + is_marked = mark_status(fndecl, argnum + 1);
91751 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
91752 + return true;
91753 +
91754 + if (is_found) {
91755 + loc = DECL_SOURCE_LOCATION(fndecl);
91756 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
91757 + return true;
91758 + }
91759 + return false;
91760 +}
91761 +
91762 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
91763 +{
91764 + struct pointer_set_t *visited;
91765 + tree arg, newarg;
91766 + bool match;
91767 +
91768 + match = get_function_arg(&argnum, fndecl);
91769 + if (!match)
91770 + return;
91771 + gcc_assert(gimple_call_num_args(stmt) > argnum);
91772 + arg = gimple_call_arg(stmt, argnum);
91773 + if (arg == NULL_TREE)
91774 + return;
91775 +
91776 + if (is_gimple_constant(arg))
91777 + return;
91778 +
91779 + if (search_attributes(fndecl, arg, argnum))
91780 + return;
91781 +
91782 + if (TREE_CODE(arg) != SSA_NAME)
91783 + return;
91784 +
91785 + check_arg_type(arg);
91786 +
91787 + visited = pointer_set_create();
91788 + newarg = expand(visited, arg);
91789 + pointer_set_destroy(visited);
91790 +
91791 + if (newarg == NULL_TREE)
91792 + return;
91793 +
91794 + change_function_arg(stmt, arg, argnum, newarg);
91795 +
91796 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
91797 +}
91798 +
91799 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
91800 +{
91801 + tree p = TREE_VALUE(attr);
91802 + do {
91803 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
91804 + p = TREE_CHAIN(p);
91805 + } while (p);
91806 +}
91807 +
91808 +static void handle_function_by_hash(gimple stmt, tree fndecl)
91809 +{
91810 + tree orig_fndecl;
91811 + unsigned int num;
91812 + const struct size_overflow_hash *hash;
91813 +
91814 + orig_fndecl = get_original_function_decl(fndecl);
91815 + if (C_DECL_IMPLICIT(orig_fndecl))
91816 + return;
91817 + hash = get_function_hash(orig_fndecl);
91818 + if (!hash)
91819 + return;
91820 +
91821 + for (num = 1; num <= MAX_PARAM; num++)
91822 + if (hash->param & (1U << num))
91823 + handle_function_arg(stmt, fndecl, num - 1);
91824 +}
91825 +
91826 +static void set_plf_false(void)
91827 +{
91828 + basic_block bb;
91829 +
91830 + FOR_ALL_BB(bb) {
91831 + gimple_stmt_iterator si;
91832 +
91833 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
91834 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91835 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
91836 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91837 + }
91838 +}
91839 +
91840 +static unsigned int handle_function(void)
91841 +{
91842 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
91843 +
91844 + set_plf_false();
91845 +
91846 + do {
91847 + gimple_stmt_iterator gsi;
91848 + next = bb->next_bb;
91849 +
91850 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91851 + tree fndecl, attr;
91852 + gimple stmt = gsi_stmt(gsi);
91853 +
91854 + if (!(is_gimple_call(stmt)))
91855 + continue;
91856 + fndecl = gimple_call_fndecl(stmt);
91857 + if (fndecl == NULL_TREE)
91858 + continue;
91859 + if (gimple_call_num_args(stmt) == 0)
91860 + continue;
91861 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
91862 + if (!attr || !TREE_VALUE(attr))
91863 + handle_function_by_hash(stmt, fndecl);
91864 + else
91865 + handle_function_by_attribute(stmt, attr, fndecl);
91866 + gsi = gsi_for_stmt(stmt);
91867 + next = gimple_bb(stmt)->next_bb;
91868 + }
91869 + bb = next;
91870 + } while (bb);
91871 + return 0;
91872 +}
91873 +
91874 +static struct gimple_opt_pass size_overflow_pass = {
91875 + .pass = {
91876 + .type = GIMPLE_PASS,
91877 + .name = "size_overflow",
91878 +#if BUILDING_GCC_VERSION >= 4008
91879 + .optinfo_flags = OPTGROUP_NONE,
91880 +#endif
91881 + .gate = NULL,
91882 + .execute = handle_function,
91883 + .sub = NULL,
91884 + .next = NULL,
91885 + .static_pass_number = 0,
91886 + .tv_id = TV_NONE,
91887 + .properties_required = PROP_cfg,
91888 + .properties_provided = 0,
91889 + .properties_destroyed = 0,
91890 + .todo_flags_start = 0,
91891 + .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
91892 + }
91893 +};
91894 +
91895 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
91896 +{
91897 + tree fntype;
91898 +
91899 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
91900 +
91901 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
91902 + fntype = build_function_type_list(void_type_node,
91903 + const_char_ptr_type_node,
91904 + unsigned_type_node,
91905 + const_char_ptr_type_node,
91906 + const_char_ptr_type_node,
91907 + NULL_TREE);
91908 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
91909 +
91910 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
91911 + TREE_PUBLIC(report_size_overflow_decl) = 1;
91912 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
91913 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
91914 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
91915 +}
91916 +
91917 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91918 +{
91919 + int i;
91920 + const char * const plugin_name = plugin_info->base_name;
91921 + const int argc = plugin_info->argc;
91922 + const struct plugin_argument * const argv = plugin_info->argv;
91923 + bool enable = true;
91924 +
91925 + struct register_pass_info size_overflow_pass_info = {
91926 + .pass = &size_overflow_pass.pass,
91927 + .reference_pass_name = "ssa",
91928 + .ref_pass_instance_number = 1,
91929 + .pos_op = PASS_POS_INSERT_AFTER
91930 + };
91931 +
91932 + if (!plugin_default_version_check(version, &gcc_version)) {
91933 + error(G_("incompatible gcc/plugin versions"));
91934 + return 1;
91935 + }
91936 +
91937 + for (i = 0; i < argc; ++i) {
91938 + if (!strcmp(argv[i].key, "no-size-overflow")) {
91939 + enable = false;
91940 + continue;
91941 + }
91942 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91943 + }
91944 +
91945 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
91946 + if (enable) {
91947 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
91948 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
91949 + }
91950 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
91951 +
91952 + return 0;
91953 +}
91954 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
91955 new file mode 100644
91956 index 0000000..ac2901e
91957 --- /dev/null
91958 +++ b/tools/gcc/stackleak_plugin.c
91959 @@ -0,0 +1,327 @@
91960 +/*
91961 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
91962 + * Licensed under the GPL v2
91963 + *
91964 + * Note: the choice of the license means that the compilation process is
91965 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91966 + * but for the kernel it doesn't matter since it doesn't link against
91967 + * any of the gcc libraries
91968 + *
91969 + * gcc plugin to help implement various PaX features
91970 + *
91971 + * - track lowest stack pointer
91972 + *
91973 + * TODO:
91974 + * - initialize all local variables
91975 + *
91976 + * BUGS:
91977 + * - none known
91978 + */
91979 +#include "gcc-plugin.h"
91980 +#include "config.h"
91981 +#include "system.h"
91982 +#include "coretypes.h"
91983 +#include "tree.h"
91984 +#include "tree-pass.h"
91985 +#include "flags.h"
91986 +#include "intl.h"
91987 +#include "toplev.h"
91988 +#include "plugin.h"
91989 +//#include "expr.h" where are you...
91990 +#include "diagnostic.h"
91991 +#include "plugin-version.h"
91992 +#include "tm.h"
91993 +#include "function.h"
91994 +#include "basic-block.h"
91995 +#include "gimple.h"
91996 +#include "rtl.h"
91997 +#include "emit-rtl.h"
91998 +
91999 +#if BUILDING_GCC_VERSION >= 4008
92000 +#define TODO_dump_func 0
92001 +#endif
92002 +
92003 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92004 +
92005 +int plugin_is_GPL_compatible;
92006 +
92007 +static int track_frame_size = -1;
92008 +static const char track_function[] = "pax_track_stack";
92009 +static const char check_function[] = "pax_check_alloca";
92010 +static bool init_locals;
92011 +
92012 +static struct plugin_info stackleak_plugin_info = {
92013 + .version = "201302112000",
92014 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
92015 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
92016 +};
92017 +
92018 +static bool gate_stackleak_track_stack(void);
92019 +static unsigned int execute_stackleak_tree_instrument(void);
92020 +static unsigned int execute_stackleak_final(void);
92021 +
92022 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
92023 + .pass = {
92024 + .type = GIMPLE_PASS,
92025 + .name = "stackleak_tree_instrument",
92026 +#if BUILDING_GCC_VERSION >= 4008
92027 + .optinfo_flags = OPTGROUP_NONE,
92028 +#endif
92029 + .gate = gate_stackleak_track_stack,
92030 + .execute = execute_stackleak_tree_instrument,
92031 + .sub = NULL,
92032 + .next = NULL,
92033 + .static_pass_number = 0,
92034 + .tv_id = TV_NONE,
92035 + .properties_required = PROP_gimple_leh | PROP_cfg,
92036 + .properties_provided = 0,
92037 + .properties_destroyed = 0,
92038 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92039 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92040 + }
92041 +};
92042 +
92043 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
92044 + .pass = {
92045 + .type = RTL_PASS,
92046 + .name = "stackleak_final",
92047 +#if BUILDING_GCC_VERSION >= 4008
92048 + .optinfo_flags = OPTGROUP_NONE,
92049 +#endif
92050 + .gate = gate_stackleak_track_stack,
92051 + .execute = execute_stackleak_final,
92052 + .sub = NULL,
92053 + .next = NULL,
92054 + .static_pass_number = 0,
92055 + .tv_id = TV_NONE,
92056 + .properties_required = 0,
92057 + .properties_provided = 0,
92058 + .properties_destroyed = 0,
92059 + .todo_flags_start = 0,
92060 + .todo_flags_finish = TODO_dump_func
92061 + }
92062 +};
92063 +
92064 +static bool gate_stackleak_track_stack(void)
92065 +{
92066 + return track_frame_size >= 0;
92067 +}
92068 +
92069 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
92070 +{
92071 + gimple check_alloca;
92072 + tree fntype, fndecl, alloca_size;
92073 +
92074 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
92075 + fndecl = build_fn_decl(check_function, fntype);
92076 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92077 +
92078 + // insert call to void pax_check_alloca(unsigned long size)
92079 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
92080 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
92081 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
92082 +}
92083 +
92084 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
92085 +{
92086 + gimple track_stack;
92087 + tree fntype, fndecl;
92088 +
92089 + fntype = build_function_type_list(void_type_node, NULL_TREE);
92090 + fndecl = build_fn_decl(track_function, fntype);
92091 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92092 +
92093 + // insert call to void pax_track_stack(void)
92094 + track_stack = gimple_build_call(fndecl, 0);
92095 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
92096 +}
92097 +
92098 +#if BUILDING_GCC_VERSION == 4005
92099 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
92100 +{
92101 + tree fndecl;
92102 +
92103 + if (!is_gimple_call(stmt))
92104 + return false;
92105 + fndecl = gimple_call_fndecl(stmt);
92106 + if (!fndecl)
92107 + return false;
92108 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
92109 + return false;
92110 +// print_node(stderr, "pax", fndecl, 4);
92111 + return DECL_FUNCTION_CODE(fndecl) == code;
92112 +}
92113 +#endif
92114 +
92115 +static bool is_alloca(gimple stmt)
92116 +{
92117 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
92118 + return true;
92119 +
92120 +#if BUILDING_GCC_VERSION >= 4007
92121 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
92122 + return true;
92123 +#endif
92124 +
92125 + return false;
92126 +}
92127 +
92128 +static unsigned int execute_stackleak_tree_instrument(void)
92129 +{
92130 + basic_block bb, entry_bb;
92131 + bool prologue_instrumented = false, is_leaf = true;
92132 +
92133 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
92134 +
92135 + // 1. loop through BBs and GIMPLE statements
92136 + FOR_EACH_BB(bb) {
92137 + gimple_stmt_iterator gsi;
92138 +
92139 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92140 + gimple stmt;
92141 +
92142 + stmt = gsi_stmt(gsi);
92143 +
92144 + if (is_gimple_call(stmt))
92145 + is_leaf = false;
92146 +
92147 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
92148 + if (!is_alloca(stmt))
92149 + continue;
92150 +
92151 + // 2. insert stack overflow check before each __builtin_alloca call
92152 + stackleak_check_alloca(&gsi);
92153 +
92154 + // 3. insert track call after each __builtin_alloca call
92155 + stackleak_add_instrumentation(&gsi);
92156 + if (bb == entry_bb)
92157 + prologue_instrumented = true;
92158 + }
92159 + }
92160 +
92161 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
92162 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
92163 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
92164 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
92165 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
92166 + return 0;
92167 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
92168 + return 0;
92169 +
92170 + // 4. insert track call at the beginning
92171 + if (!prologue_instrumented) {
92172 + gimple_stmt_iterator gsi;
92173 +
92174 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92175 + if (dom_info_available_p(CDI_DOMINATORS))
92176 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
92177 + gsi = gsi_start_bb(bb);
92178 + stackleak_add_instrumentation(&gsi);
92179 + }
92180 +
92181 + return 0;
92182 +}
92183 +
92184 +static unsigned int execute_stackleak_final(void)
92185 +{
92186 + rtx insn, next;
92187 +
92188 + if (cfun->calls_alloca)
92189 + return 0;
92190 +
92191 + // keep calls only if function frame is big enough
92192 + if (get_frame_size() >= track_frame_size)
92193 + return 0;
92194 +
92195 + // 1. find pax_track_stack calls
92196 + for (insn = get_insns(); insn; insn = next) {
92197 + // 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))
92198 + rtx body;
92199 +
92200 + next = NEXT_INSN(insn);
92201 + if (!CALL_P(insn))
92202 + continue;
92203 + body = PATTERN(insn);
92204 + if (GET_CODE(body) != CALL)
92205 + continue;
92206 + body = XEXP(body, 0);
92207 + if (GET_CODE(body) != MEM)
92208 + continue;
92209 + body = XEXP(body, 0);
92210 + if (GET_CODE(body) != SYMBOL_REF)
92211 + continue;
92212 + if (strcmp(XSTR(body, 0), track_function))
92213 + continue;
92214 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92215 + // 2. delete call
92216 + delete_insn_and_edges(insn);
92217 +#if BUILDING_GCC_VERSION >= 4007
92218 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
92219 + insn = next;
92220 + next = NEXT_INSN(insn);
92221 + delete_insn_and_edges(insn);
92222 + }
92223 +#endif
92224 + }
92225 +
92226 +// print_simple_rtl(stderr, get_insns());
92227 +// print_rtl(stderr, get_insns());
92228 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92229 +
92230 + return 0;
92231 +}
92232 +
92233 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92234 +{
92235 + const char * const plugin_name = plugin_info->base_name;
92236 + const int argc = plugin_info->argc;
92237 + const struct plugin_argument * const argv = plugin_info->argv;
92238 + int i;
92239 + struct register_pass_info stackleak_tree_instrument_pass_info = {
92240 + .pass = &stackleak_tree_instrument_pass.pass,
92241 +// .reference_pass_name = "tree_profile",
92242 + .reference_pass_name = "optimized",
92243 + .ref_pass_instance_number = 1,
92244 + .pos_op = PASS_POS_INSERT_BEFORE
92245 + };
92246 + struct register_pass_info stackleak_final_pass_info = {
92247 + .pass = &stackleak_final_rtl_opt_pass.pass,
92248 + .reference_pass_name = "final",
92249 + .ref_pass_instance_number = 1,
92250 + .pos_op = PASS_POS_INSERT_BEFORE
92251 + };
92252 +
92253 + if (!plugin_default_version_check(version, &gcc_version)) {
92254 + error(G_("incompatible gcc/plugin versions"));
92255 + return 1;
92256 + }
92257 +
92258 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
92259 +
92260 + for (i = 0; i < argc; ++i) {
92261 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
92262 + if (!argv[i].value) {
92263 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92264 + continue;
92265 + }
92266 + track_frame_size = atoi(argv[i].value);
92267 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
92268 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92269 + continue;
92270 + }
92271 + if (!strcmp(argv[i].key, "initialize-locals")) {
92272 + if (argv[i].value) {
92273 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92274 + continue;
92275 + }
92276 + init_locals = true;
92277 + continue;
92278 + }
92279 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92280 + }
92281 +
92282 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
92283 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
92284 +
92285 + return 0;
92286 +}
92287 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
92288 index 6789d78..4afd019e 100644
92289 --- a/tools/perf/util/include/asm/alternative-asm.h
92290 +++ b/tools/perf/util/include/asm/alternative-asm.h
92291 @@ -5,4 +5,7 @@
92292
92293 #define altinstruction_entry #
92294
92295 + .macro pax_force_retaddr rip=0, reload=0
92296 + .endm
92297 +
92298 #endif
92299 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
92300 index 6e8fa7e..f0ec393 100644
92301 --- a/virt/kvm/kvm_main.c
92302 +++ b/virt/kvm/kvm_main.c
92303 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
92304
92305 static cpumask_var_t cpus_hardware_enabled;
92306 static int kvm_usage_count = 0;
92307 -static atomic_t hardware_enable_failed;
92308 +static atomic_unchecked_t hardware_enable_failed;
92309
92310 struct kmem_cache *kvm_vcpu_cache;
92311 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
92312
92313 -static __read_mostly struct preempt_ops kvm_preempt_ops;
92314 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
92315 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
92316 +static struct preempt_ops kvm_preempt_ops = {
92317 + .sched_in = kvm_sched_in,
92318 + .sched_out = kvm_sched_out,
92319 +};
92320
92321 struct dentry *kvm_debugfs_dir;
92322
92323 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
92324 /* We can read the guest memory with __xxx_user() later on. */
92325 if (user_alloc &&
92326 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
92327 - !access_ok(VERIFY_WRITE,
92328 + !__access_ok(VERIFY_WRITE,
92329 (void __user *)(unsigned long)mem->userspace_addr,
92330 mem->memory_size)))
92331 goto out;
92332 @@ -1778,7 +1783,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
92333 return 0;
92334 }
92335
92336 -static struct file_operations kvm_vcpu_fops = {
92337 +static file_operations_no_const kvm_vcpu_fops __read_only = {
92338 .release = kvm_vcpu_release,
92339 .unlocked_ioctl = kvm_vcpu_ioctl,
92340 #ifdef CONFIG_COMPAT
92341 @@ -2326,7 +2331,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
92342 return 0;
92343 }
92344
92345 -static struct file_operations kvm_vm_fops = {
92346 +static file_operations_no_const kvm_vm_fops __read_only = {
92347 .release = kvm_vm_release,
92348 .unlocked_ioctl = kvm_vm_ioctl,
92349 #ifdef CONFIG_COMPAT
92350 @@ -2424,7 +2429,7 @@ out:
92351 return r;
92352 }
92353
92354 -static struct file_operations kvm_chardev_ops = {
92355 +static file_operations_no_const kvm_chardev_ops __read_only = {
92356 .unlocked_ioctl = kvm_dev_ioctl,
92357 .compat_ioctl = kvm_dev_ioctl,
92358 .llseek = noop_llseek,
92359 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
92360
92361 if (r) {
92362 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
92363 - atomic_inc(&hardware_enable_failed);
92364 + atomic_inc_unchecked(&hardware_enable_failed);
92365 printk(KERN_INFO "kvm: enabling virtualization on "
92366 "CPU%d failed\n", cpu);
92367 }
92368 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
92369
92370 kvm_usage_count++;
92371 if (kvm_usage_count == 1) {
92372 - atomic_set(&hardware_enable_failed, 0);
92373 + atomic_set_unchecked(&hardware_enable_failed, 0);
92374 on_each_cpu(hardware_enable_nolock, NULL, 1);
92375
92376 - if (atomic_read(&hardware_enable_failed)) {
92377 + if (atomic_read_unchecked(&hardware_enable_failed)) {
92378 hardware_disable_all_nolock();
92379 r = -EBUSY;
92380 }
92381 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
92382 kvm_arch_vcpu_put(vcpu);
92383 }
92384
92385 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92386 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92387 struct module *module)
92388 {
92389 int r;
92390 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92391 if (!vcpu_align)
92392 vcpu_align = __alignof__(struct kvm_vcpu);
92393 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
92394 - 0, NULL);
92395 + SLAB_USERCOPY, NULL);
92396 if (!kvm_vcpu_cache) {
92397 r = -ENOMEM;
92398 goto out_free_3;
92399 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92400 if (r)
92401 goto out_free;
92402
92403 + pax_open_kernel();
92404 kvm_chardev_ops.owner = module;
92405 kvm_vm_fops.owner = module;
92406 kvm_vcpu_fops.owner = module;
92407 + pax_close_kernel();
92408
92409 r = misc_register(&kvm_dev);
92410 if (r) {
92411 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92412
92413 register_syscore_ops(&kvm_syscore_ops);
92414
92415 - kvm_preempt_ops.sched_in = kvm_sched_in;
92416 - kvm_preempt_ops.sched_out = kvm_sched_out;
92417 -
92418 r = kvm_init_debug();
92419 if (r) {
92420 printk(KERN_ERR "kvm: create debugfs files failed\n");